Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved value setter to constructor #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Jms/YamlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,15 @@ private function visitBaseComplexType(&$class, &$data, BaseComplexType $type, $n
private function handleClassExtension(&$class, &$data, Type $type, $parentName)
{
if ($alias = $this->getTypeAlias($type)) {


$property = array();
$property["expose"] = true;
$property["xml_value"] = true;
$property["access_type"] = "public_method";
$property["accessor"]["getter"] = "value";
$property["accessor"]["setter"] = "value";
$property["accessor"]["setter"] = "__construct";
$property["type"] = $alias;

$data["properties"]["__value"] = $property;


} else {
$extension = $this->visitType($type, true);

Expand All @@ -331,7 +327,7 @@ private function handleClassExtension(&$class, &$data, Type $type, $parentName)
$property["xml_value"] = true;
$property["access_type"] = "public_method";
$property["accessor"]["getter"] = "value";
$property["accessor"]["setter"] = "value";
$property["accessor"]["setter"] = "__construct";

if ($valueProp = $this->typeHasValue($type, $class, $parentName)) {
$property["type"] = $valueProp;
Expand Down
14 changes: 2 additions & 12 deletions src/Php/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,12 @@ private function handleValueMethod(Generator\ClassGenerator $generator, PHPPrope
$param
]);
$method->setDocBlock($docblock);
$method->setBody("\$this->value(\$value);");
$method->setBody("\$this->" . $prop->getName() . " = \$value;");

$generator->addMethodFromGenerator($method);

$docblock = new DocBlockGenerator('Gets or sets the inner value');
$docblock->setWordWrap(false);
$paramTag = new ParamTag("value");
if ($type && $type instanceof PHPClassOf) {
$paramTag->setTypes($type->getArg()->getType()->getPhpType() . "[]");
} elseif ($type) {
$paramTag->setTypes($prop->getType()->getPhpType());
}
$docblock->setTag($paramTag);

$returnTag = new ReturnTag("mixed");

Expand All @@ -88,10 +81,7 @@ private function handleValueMethod(Generator\ClassGenerator $generator, PHPPrope
$method = new MethodGenerator("value", []);
$method->setDocBlock($docblock);

$methodBody = "if (\$args = func_get_args()) {" . PHP_EOL;
$methodBody .= " \$this->" . $prop->getName() . " = \$args[0];" . PHP_EOL;
$methodBody .= "}" . PHP_EOL;
$methodBody .= "return \$this->" . $prop->getName() . ";" . PHP_EOL;
$methodBody = "return \$this->" . $prop->getName() . ";" . PHP_EOL;
$method->setBody($methodBody);

$generator->addMethodFromGenerator($method);
Expand Down
8 changes: 4 additions & 4 deletions tests/Converter/JMS/Xsd2JmsElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testElementOfPrimitiveType($xsType, $phpName)
'access_type' => 'public_method',
'accessor' => array(
'getter' => 'value',
'setter' => 'value'
'setter' => '__construct'
),
'type' => $phpName
)
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testElementOfPrimitiveTypeAnon($xsType, $phpName)
'access_type' => 'public_method',
'accessor' => array(
'getter' => 'value',
'setter' => 'value'
'setter' => '__construct'
),
'type' => $phpName
)
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testElementOfBaseType($xsType, $phpName, $jmsType)
'access_type' => 'public_method',
'accessor' => array(
'getter' => 'value',
'setter' => 'value',
'setter' => '__construct',
),
'type' => $jmsType,
),
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testElementOfBaseTypeAnon($xsType, $phpName, $jmsType)
'access_type' => 'public_method',
'accessor' => array(
'getter' => 'value',
'setter' => 'value',
'setter' => '__construct',
),
'type' => $jmsType,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/Converter/JMS/Xsd2JmsGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public function testGeneralParts()
'access_type' => 'public_method',
'accessor' => array(
'getter' => 'value',
'setter' => 'value'
'setter' => '__construct'
),
'type' => 'string'
)
Expand Down