From f304d8f5506682efc01abb93b1700d13b63d0b8e Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Tue, 18 Jun 2024 09:46:23 +0200 Subject: [PATCH] Fix code generation deprecations --- composer.json | 2 +- .../CodeGenerator/Model/ParameterSpec.php | 10 -- .../Assembler/ClassMapAssembler.php | 18 +-- .../Assembler/ClientConstructorAssembler.php | 36 ++--- .../Assembler/ClientMethodAssembler.php | 124 ++++++++---------- .../Assembler/ConstructorAssembler.php | 26 ++-- .../Assembler/FluentSetterAssembler.php | 49 ++++--- .../Assembler/GetterAssembler.php | 20 +-- .../Assembler/ImmutableSetterAssembler.php | 36 ++--- .../Assembler/IteratorAssembler.php | 74 ++++++----- .../Assembler/JsonSerializableAssembler.php | 12 +- .../Assembler/PropertyAssembler.php | 22 ++-- .../Assembler/ResultProviderAssembler.php | 32 ++--- .../Assembler/SetterAssembler.php | 32 +++-- .../CodeGenerator/ClientFactoryGenerator.php | 32 ++--- .../DocBlockGeneratorFactory.php | 15 --- .../CodeGenerator/Model/Parameter.php | 13 -- 17 files changed, 243 insertions(+), 310 deletions(-) delete mode 100644 src/Phpro/SoapClient/CodeGenerator/LaminasCodeFactory/DocBlockGeneratorFactory.php diff --git a/composer.json b/composer.json index 245189d6..800251be 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "azjezz/psl": "^2.1", - "laminas/laminas-code": "^4.8.0", + "laminas/laminas-code": "^4.14.0", "php-soap/cached-engine": "~0.2", "php-soap/engine": "^2.10.1", "php-soap/encoding": "~0.4", diff --git a/spec/Phpro/SoapClient/CodeGenerator/Model/ParameterSpec.php b/spec/Phpro/SoapClient/CodeGenerator/Model/ParameterSpec.php index 99b02323..ff5cf959 100644 --- a/spec/Phpro/SoapClient/CodeGenerator/Model/ParameterSpec.php +++ b/spec/Phpro/SoapClient/CodeGenerator/Model/ParameterSpec.php @@ -35,16 +35,6 @@ function is_has_a_namespace() $this->getNamespace()->shouldBe('MyParameterType'); } - function it_returns_an_array() - { - $this->toArray()->shouldBe( - [ - 'name' => 'MyParameter', - 'type' => '\\MyNamespace\\MyParameterType', - ] - ); - } - public function it_has_type_meta(): void { $this->getMeta()->shouldBeLike(new TypeMeta()); diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClassMapAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClassMapAssembler.php index 4e5d2690..abffae01 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClassMapAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClassMapAssembler.php @@ -36,11 +36,7 @@ public function canAssemble(ContextInterface $context): bool */ public function assemble(ContextInterface $context) { - $class = ClassGenerator::fromArray( - [ - 'name' => $context->getName(), - ] - ); + $class = new ClassGenerator($context->getName()); $file = $context->getFile(); $file->setClass($class); $file->setNamespace($context->getNamespace()); @@ -55,14 +51,10 @@ public function assemble(ContextInterface $context) $classMap = $this->assembleClassMap($typeMap, $linefeed, $file->getIndentation()); $code = $this->assembleClassMapCollection($classMap, $linefeed).$linefeed; $class->addMethodFromGenerator( - MethodGenerator::fromArray( - [ - 'name' => 'getCollection', - 'static' => true, - 'body' => 'return '.$code, - 'returntype' => ClassMapCollection::class, - ] - ) + (new MethodGenerator('getCollection')) + ->setStatic(true) + ->setBody('return '.$code) + ->setReturnType(ClassMapCollection::class) ); } catch (\Exception $e) { throw AssemblerException::fromException($e); diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientConstructorAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientConstructorAssembler.php index 3614d7c6..c66a73cb 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientConstructorAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientConstructorAssembler.php @@ -4,6 +4,7 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; use Laminas\Code\Generator\ClassGenerator; +use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Generator\MethodGenerator; use Laminas\Code\Generator\ParameterGenerator; use Laminas\Code\Generator\PropertyGenerator; @@ -33,36 +34,23 @@ public function assemble(ContextInterface $context) try { $caller = $this->generateClassNameAndAddImport(Caller::class, $class); $class->addPropertyFromGenerator( - PropertyGenerator::fromArray([ - 'name' => 'caller', - 'visibility' => PropertyGenerator::VISIBILITY_PRIVATE, - 'omitdefaultvalue' => true, - 'docblock' => DocBlockGeneratorFactory::fromArray([ - 'tags' => [ + (new PropertyGenerator('caller')) + ->setVisibility(PropertyGenerator::VISIBILITY_PRIVATE) + ->omitDefaultValue(true) + ->setDocBlock((new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ [ 'name' => 'var', 'description' => $caller, ], - ] - ]) - ]) + ])), ); $class->addMethodFromGenerator( - MethodGenerator::fromArray( - [ - 'name' => '__construct', - 'parameters' => [ - ParameterGenerator::fromArray( - [ - 'name' => 'caller', - 'type' => Caller::class, - ] - ) - ], - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - 'body' => '$this->caller = $caller;', - ] - ) + (new MethodGenerator('__construct')) + ->setParameter(new ParameterGenerator('caller', Caller::class)) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC) + ->setBody('$this->caller = $caller;') ); } catch (\Exception $e) { throw AssemblerException::fromException($e); diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientMethodAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientMethodAssembler.php index 2f7ffd04..5c0213bf 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientMethodAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ClientMethodAssembler.php @@ -9,7 +9,6 @@ use Phpro\SoapClient\CodeGenerator\Context\ClientMethodContext; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\GeneratorInterface; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\CodeGenerator\Model\ClientMethod; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; use Phpro\SoapClient\Exception\AssemblerException; @@ -55,16 +54,12 @@ public function assemble(ContextInterface $context): bool $methodBody = $this->generateMethodBody($class, $param, $method, $context); $class->addMethodFromGenerator( - MethodGenerator::fromArray( - [ - 'name' => $phpMethodName, - 'parameters' => $param === null ? [] : [$param], - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - 'body' => $methodBody, - 'returntype' => $this->decideOnReturnType($context, true), - 'docblock' => $docblock, - ] - ) + (new MethodGenerator($phpMethodName)) + ->setParameters($param === null ? [] : [$param]) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC) + ->setBody($methodBody) + ->setReturnType($this->decideOnReturnType($context, true)) + ->setDocBlock($docblock) ); } catch (\Exception $e) { throw AssemblerException::fromException($e); @@ -117,15 +112,10 @@ private function createParamsFromContext(ClientMethodContext $context): ?Paramet if (!$method->shouldGenerateAsMultiArgumentsRequest()) { $param = current($context->getMethod()->getParameters()); - return ParameterGenerator::fromArray($param->toArray()); + return new ParameterGenerator($param->getName(), $param->getType()); } - return ParameterGenerator::fromArray( - [ - 'name' => 'multiArgumentRequest', - 'type' => MultiArgumentRequest::class, - ] - ); + return new ParameterGenerator('multiArgumentRequest', MultiArgumentRequest::class); } /** @@ -141,56 +131,22 @@ private function generateMultiArgumentDocblock(ClientMethodContext $context): Do $description[] = $parameter->getType().' $'.$parameter->getName(); } - return DocBlockGeneratorFactory::fromArray( - [ - 'shortdescription' => $context->getMethod()->getMeta()->docs()->unwrapOr(''), - 'longdescription' => implode(GeneratorInterface::EOL, $description), - 'tags' => [ - [ - 'name' => 'param', - 'description' => sprintf( - '%s $%s', - $this->generateClassNameAndAddImport( - MultiArgumentRequest::class, - $class - ), - 'multiArgumentRequest' - ), - ], - [ - 'name' => 'return', - 'description' => sprintf( - '%s & %s', - $this->generateClassNameAndAddImport(ResultInterface::class, $class), - $this->decideOnReturnType($context, false) - ), - ], - [ - 'name' => 'throws', - 'description' => $this->generateClassNameAndAddImport( - SoapException::class, + return (new DocBlockGenerator()) + ->setWordWrap(false) + ->setShortDescription($context->getMethod()->getMeta()->docs()->unwrapOr('')) + ->setLongDescription(implode(GeneratorInterface::EOL, $description)) + ->setTags([ + [ + 'name' => 'param', + 'description' => sprintf( + '%s $%s', + $this->generateClassNameAndAddImport( + MultiArgumentRequest::class, $class ), - ], + 'multiArgumentRequest' + ), ], - ] - ); - } - - /** - * @param ClientMethodContext $context - * - * @return DocBlockGenerator - */ - private function generateSingleArgumentDocblock(ClientMethodContext $context): DocBlockGenerator - { - $method = $context->getMethod(); - $class = $context->getClass(); - $param = current($method->getParameters()); - - $data = [ - 'shortdescription' => $context->getMethod()->getMeta()->docs()->unwrapOr(''), - 'tags' => [ [ 'name' => 'return', 'description' => sprintf( @@ -206,12 +162,42 @@ private function generateSingleArgumentDocblock(ClientMethodContext $context): D $class ), ], + ]); + } + + /** + * @param ClientMethodContext $context + * + * @return DocBlockGenerator + */ + private function generateSingleArgumentDocblock(ClientMethodContext $context): DocBlockGenerator + { + $method = $context->getMethod(); + $class = $context->getClass(); + $param = current($method->getParameters()); + + $shortDescription = $context->getMethod()->getMeta()->docs()->unwrapOr(''); + $tags = [ + [ + 'name' => 'return', + 'description' => sprintf( + '%s & %s', + $this->generateClassNameAndAddImport(ResultInterface::class, $class), + $this->decideOnReturnType($context, false) + ), + ], + [ + 'name' => 'throws', + 'description' => $this->generateClassNameAndAddImport( + SoapException::class, + $class + ), ], ]; if ($param) { array_unshift( - $data['tags'], + $tags, [ 'name' => 'param', 'description' => sprintf( @@ -224,8 +210,10 @@ private function generateSingleArgumentDocblock(ClientMethodContext $context): D ); } - return DocBlockGeneratorFactory::fromArray($data) - ->setWordWrap(false); + return (new DocBlockGenerator()) + ->setWordWrap(false) + ->setShortDescription($shortDescription) + ->setTags($tags); } /** diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ConstructorAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ConstructorAssembler.php index 39599cd8..fa36a240 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ConstructorAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ConstructorAssembler.php @@ -2,10 +2,11 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; +use Laminas\Code\Generator\ParameterGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\TypeContext; use Phpro\SoapClient\CodeGenerator\Model\Type; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\MethodGenerator; @@ -67,21 +68,22 @@ public function assemble(ContextInterface $context) private function assembleConstructor(Type $type): MethodGenerator { $body = []; - $constructor = MethodGenerator::fromArray([ - 'name' => '__construct', - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - ]); - $docblock = DocBlockGeneratorFactory::fromArray([ - 'shortdescription' => 'Constructor' - ]); + $constructor = (new MethodGenerator('__construct')) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC); + + $docblock = (new DocBlockGenerator()) + ->setWordWrap(false) + ->setShortDescription('Constructor'); foreach ($type->getProperties() as $property) { + $param = (new ParameterGenerator($property->getName())); $body[] = sprintf('$this->%1$s = $%1$s;', $property->getName()); - $withTypeHints = $this->options->useTypeHints() ? ['type' => $property->getPhpType()] : []; - $constructor->setParameter(array_merge([ - 'name' => $property->getName(), - ], $withTypeHints)); + if ($this->options->useTypeHints()) { + $param->setType($property->getPhpType()); + } + + $constructor->setParameter($param); if ($this->options->useDocBlocks()) { $docblock->setTag([ diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/FluentSetterAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/FluentSetterAssembler.php index 94afe6b0..32347c7e 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/FluentSetterAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/FluentSetterAssembler.php @@ -2,11 +2,13 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; +use Laminas\Code\Generator\ParameterGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\PropertyContext; +use Phpro\SoapClient\CodeGenerator\Model\Parameter; use Phpro\SoapClient\CodeGenerator\Model\Property; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\MethodGenerator; @@ -53,7 +55,7 @@ public function assemble(ContextInterface $context) $class->removeMethod($methodName); $methodGenerator = new MethodGenerator($methodName); - $methodGenerator->setParameters($this->getParameter($property)); + $methodGenerator->setParameter($this->getParameter($property)); $methodGenerator->setVisibility(MethodGenerator::VISIBILITY_PUBLIC); $methodGenerator->setBody(sprintf( '$this->%1$s = $%1$s;%2$sreturn $this;', @@ -64,18 +66,20 @@ public function assemble(ContextInterface $context) $methodGenerator->setReturnType('static'); } if ($this->options->useDocBlocks()) { - $methodGenerator->setDocBlock(DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'param', - 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), - ], - [ - 'name' => 'return', - 'description' => '$this', - ], - ], - ])); + $methodGenerator->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'param', + 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), + ], + [ + 'name' => 'return', + 'description' => '$this', + ] + ]) + ); } $class->addMethodFromGenerator($methodGenerator); } catch (\Exception $e) { @@ -83,22 +87,13 @@ public function assemble(ContextInterface $context) } } - /** - * @param Property $property - * - * @return array - */ - private function getParameter(Property $property): array + private function getParameter(Property $property): ParameterGenerator { + $param = (new ParameterGenerator($property->getName())); if ($this->options->useTypeHints()) { - return [ - [ - 'name' => $property->getName(), - 'type' => $property->getPhpType(), - ], - ]; + $param->setType($property->getPhpType()); } - return [$property->getName()]; + return $param; } } diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/GetterAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/GetterAssembler.php index 165fd089..b8ad663f 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/GetterAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/GetterAssembler.php @@ -2,11 +2,11 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\PropertyContext; use Phpro\SoapClient\CodeGenerator\Model\Property; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\MethodGenerator; use Soap\Engine\Metadata\Model\TypeMeta; @@ -70,14 +70,16 @@ public function assemble(ContextInterface $context) } if ($this->options->useDocBlocks()) { - $methodGenerator->setDocBlock(DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'return', - 'description' => $property->getDocBlockType(), - ], - ], - ])); + $methodGenerator->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'return', + 'description' => $property->getDocBlockType(), + ] + ]) + ); } $class->addMethodFromGenerator($methodGenerator); diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ImmutableSetterAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ImmutableSetterAssembler.php index e857f02d..76b7a2e7 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ImmutableSetterAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ImmutableSetterAssembler.php @@ -2,10 +2,11 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; +use Laminas\Code\Generator\ParameterGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\PropertyContext; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\MethodGenerator; @@ -62,30 +63,33 @@ public function assemble(ContextInterface $context) '', sprintf('return $new;'), ]; - $parameterOptions = ['name' => $property->getName()]; + + $param = (new ParameterGenerator($property->getName())); if ($this->options->useTypeHints()) { - $parameterOptions['type'] = $property->getPhpType(); + $param->setType($property->getPhpType()); } $methodGenerator = new MethodGenerator($methodName); - $methodGenerator->setParameters([$parameterOptions]); + $methodGenerator->setParameter($param); $methodGenerator->setBody(implode($class::LINE_FEED, $lines)); if ($this->options->useReturnTypes()) { $methodGenerator->setReturnType('static'); } if ($this->options->useDocBlocks()) { - $methodGenerator->setDocBlock(DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'param', - 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), - ], - [ - 'name' => 'return', - 'description' => 'static', - ], - ], - ])); + $methodGenerator->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'param', + 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), + ], + [ + 'name' => 'return', + 'description' => 'static', + ], + ]) + ); } $class->addMethodFromGenerator($methodGenerator); } catch (\Exception $e) { diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/IteratorAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/IteratorAssembler.php index 1f5eb479..2b0ac765 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/IteratorAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/IteratorAssembler.php @@ -2,10 +2,10 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\TypeContext; use Phpro\SoapClient\CodeGenerator\Model\Property; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\CodeGenerator\TypeEnhancer\Calculator\ArrayBoundsCalculator; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\ClassGenerator; @@ -67,45 +67,47 @@ private function implementGetIterator(ClassGenerator $class, Property $firstProp $methodName = 'getIterator'; $class->removeMethod($methodName); $class->addMethodFromGenerator( - MethodGenerator::fromArray([ - 'name' => $methodName, - 'parameters' => [], - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - 'body' => sprintf( + (new MethodGenerator($methodName)) + ->setParameters([]) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC) + ->setBody(sprintf( 'return new \\ArrayIterator($this->%1$s);', $firstProperty->getName() - ), - 'returntype' => 'ArrayIterator', - 'docblock' => DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'return', - 'description' => '\\ArrayIterator|'. $firstProperty->getType() .'[]' - ], - [ - 'name' => 'phpstan-return', - 'description' => '\\ArrayIterator'.$arrayInfo, - ], - [ - 'name' => 'psalm-return', - 'description' => '\\ArrayIterator'.$arrayInfo, - ] + )) + ->setReturnType('ArrayIterator') + ->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'return', + 'description' => '\\ArrayIterator|'. $firstProperty->getType() .'[]' + ], + [ + 'name' => 'phpstan-return', + 'description' => '\\ArrayIterator'.$arrayInfo, + ], + [ + 'name' => 'psalm-return', + 'description' => '\\ArrayIterator'.$arrayInfo, + ] + ]) + ) + ); + + $class->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'phpstan-implements', + 'description' => '\\IteratorAggregate'.$arrayInfo, + ], + [ + 'name' => 'psalm-implements', + 'description' => '\\IteratorAggregate'.$arrayInfo, ] ]) - ]) ); - - $class->setDocBlock(DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'phpstan-implements', - 'description' => '\\IteratorAggregate'.$arrayInfo, - ], - [ - 'name' => 'psalm-implements', - 'description' => '\\IteratorAggregate'.$arrayInfo, - ] - ] - ])); } } diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/JsonSerializableAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/JsonSerializableAssembler.php index c3ac8f0d..923da09b 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/JsonSerializableAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/JsonSerializableAssembler.php @@ -55,13 +55,11 @@ private function implementJsonSerialize(Type $type, ClassGenerator $class) $methodName = 'jsonSerialize'; $class->removeMethod($methodName); $class->addMethodFromGenerator( - MethodGenerator::fromArray([ - 'name' => $methodName, - 'parameters' => [], - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - 'body' => $this->generateJsonSerializeBody($type, $class), - 'returntype' => 'array', - ]) + (new MethodGenerator($methodName)) + ->setParameters([]) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC) + ->setBody($this->generateJsonSerializeBody($type, $class)) + ->setReturnType('array') ); } diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/PropertyAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/PropertyAssembler.php index 6ebe0538..33c841eb 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/PropertyAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/PropertyAssembler.php @@ -2,6 +2,7 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Generator\TypeGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\PropertyContext; @@ -55,24 +56,23 @@ public function assemble(ContextInterface $context) $class->removeProperty($property->getName()); } - $propertyGenerator = PropertyGenerator::fromArray([ - 'name' => $property->getName(), - 'visibility' => $this->options->visibility(), - 'omitdefaultvalue' => !$this->options->useOptionalValue() - && !(new IsConsideredNullableType())($property->getMeta()), - ]); + $propertyGenerator = (new PropertyGenerator($property->getName())) + ->setVisibility($this->options->visibility()) + ->omitDefaultValue( + !$this->options->useOptionalValue() && !(new IsConsideredNullableType())($property->getMeta()) + ); if ($this->options->useDocBlocks()) { $propertyGenerator->setDocBlock( - DocBlockGeneratorFactory::fromArray([ - 'longdescription' => $property->getMeta()->docs()->unwrapOr(''), - 'tags' => [ + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setLongDescription($property->getMeta()->docs()->unwrapOr('')) + ->setTags([ [ 'name' => 'var', 'description' => $property->getDocBlockType(), ], - ] - ]) + ]) ); } diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/ResultProviderAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/ResultProviderAssembler.php index 7397c9d4..f9defcea 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/ResultProviderAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/ResultProviderAssembler.php @@ -2,11 +2,11 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\TypeContext; use Phpro\SoapClient\CodeGenerator\Model\Property; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Phpro\SoapClient\Type\ResultInterface; use Phpro\SoapClient\Type\ResultProviderInterface; @@ -87,21 +87,21 @@ private function implementGetResult(ContextInterface $context, ClassGenerator $c $methodName = 'getResult'; $class->removeMethod($methodName); $class->addMethodFromGenerator( - MethodGenerator::fromArray([ - 'name' => $methodName, - 'parameters' => [], - 'visibility' => MethodGenerator::VISIBILITY_PUBLIC, - 'returntype' => ResultInterface::class, - 'body' => $this->generateGetResultBody($property), - 'docblock' => DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'return', - 'description' => $this->generateGetResultReturnTag($property) - ] - ] - ]) - ]) + (new MethodGenerator($methodName)) + ->setParameters([]) + ->setVisibility(MethodGenerator::VISIBILITY_PUBLIC) + ->setReturnType(ResultInterface::class) + ->setBody($this->generateGetResultBody($property)) + ->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'return', + 'description' => $this->generateGetResultReturnTag($property) + ] + ]) + ) ); } diff --git a/src/Phpro/SoapClient/CodeGenerator/Assembler/SetterAssembler.php b/src/Phpro/SoapClient/CodeGenerator/Assembler/SetterAssembler.php index a5af358d..efcdf756 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Assembler/SetterAssembler.php +++ b/src/Phpro/SoapClient/CodeGenerator/Assembler/SetterAssembler.php @@ -2,10 +2,11 @@ namespace Phpro\SoapClient\CodeGenerator\Assembler; +use Laminas\Code\Generator\DocBlockGenerator; +use Laminas\Code\Generator\ParameterGenerator; use Phpro\SoapClient\CodeGenerator\Context\ContextInterface; use Phpro\SoapClient\CodeGenerator\Context\PropertyContext; use Phpro\SoapClient\CodeGenerator\Util\Normalizer; -use Phpro\SoapClient\CodeGenerator\LaminasCodeFactory\DocBlockGeneratorFactory; use Phpro\SoapClient\Exception\AssemblerException; use Laminas\Code\Generator\MethodGenerator; @@ -49,27 +50,30 @@ public function assemble(ContextInterface $context) $class = $context->getClass(); $property = $context->getProperty(); try { - $parameterOptions = ['name' => $property->getName()]; - if ($this->options->useTypeHints()) { - $parameterOptions['type'] = $property->getPhpType(); - } $methodName = Normalizer::generatePropertyMethod('set', $property->getName()); $class->removeMethod($methodName); + $param = (new ParameterGenerator($property->getName())); + if ($this->options->useTypeHints()) { + $param->setType($property->getPhpType()); + } + $methodGenerator = new MethodGenerator($methodName); $methodGenerator->setReturnType('void'); - $methodGenerator->setParameters([$parameterOptions]); + $methodGenerator->setParameter($param); $methodGenerator->setVisibility(MethodGenerator::VISIBILITY_PUBLIC); $methodGenerator->setBody(sprintf('$this->%1$s = $%1$s;', $property->getName())); if ($this->options->useDocBlocks()) { - $methodGenerator->setDocBlock(DocBlockGeneratorFactory::fromArray([ - 'tags' => [ - [ - 'name' => 'param', - 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), - ], - ], - ])); + $methodGenerator->setDocBlock( + (new DocBlockGenerator()) + ->setWordWrap(false) + ->setTags([ + [ + 'name' => 'param', + 'description' => sprintf('%s $%s', $property->getDocBlockType(), $property->getName()), + ] + ]) + ); } $class->addMethodFromGenerator($methodGenerator); diff --git a/src/Phpro/SoapClient/CodeGenerator/ClientFactoryGenerator.php b/src/Phpro/SoapClient/CodeGenerator/ClientFactoryGenerator.php index fa099b4d..f12e5345 100644 --- a/src/Phpro/SoapClient/CodeGenerator/ClientFactoryGenerator.php +++ b/src/Phpro/SoapClient/CodeGenerator/ClientFactoryGenerator.php @@ -2,6 +2,8 @@ namespace Phpro\SoapClient\CodeGenerator; +use Laminas\Code\Generator\DocBlockGenerator; +use Laminas\Code\Generator\ParameterGenerator; use Phpro\SoapClient\Caller\EngineCaller; use Phpro\SoapClient\Caller\EventDispatchingCaller; use Phpro\SoapClient\CodeGenerator\Context\ClientFactoryContext; @@ -64,24 +66,18 @@ public function generate(FileGenerator $file, $context): string $class->addUse(EngineCaller::class); $class->addUse(EncoderRegistry::class); $class->addMethodFromGenerator( - MethodGenerator::fromArray( - [ - 'name' => 'factory', - 'static' => true, - 'body' => sprintf(self::BODY, $context->getClientName(), $context->getClassmapName()), - 'returntype' => $context->getClientFqcn(), - 'parameters' => [ - [ - 'name' => 'wsdl', - 'type' => 'string', - ], - ], - 'docblock' => [ - 'shortdescription' => 'This factory can be used as a starting point '. - 'to create your own specialized factory. Feel free to modify.', - ], - ] - ) + (new MethodGenerator('factory')) + ->setStatic(true) + ->setBody(sprintf(self::BODY, $context->getClientName(), $context->getClassmapName())) + ->setReturnType($context->getClientFqcn()) + ->setParameter(new ParameterGenerator('wsdl', 'string')) + ->setDocBlock( + (new DocBlockGenerator()) + ->setShortDescription( + 'This factory can be used as a starting point '. + 'to create your own specialized factory. Feel free to modify.' + ) + ) ); $file->setClass($class); diff --git a/src/Phpro/SoapClient/CodeGenerator/LaminasCodeFactory/DocBlockGeneratorFactory.php b/src/Phpro/SoapClient/CodeGenerator/LaminasCodeFactory/DocBlockGeneratorFactory.php deleted file mode 100644 index ae0f1356..00000000 --- a/src/Phpro/SoapClient/CodeGenerator/LaminasCodeFactory/DocBlockGeneratorFactory.php +++ /dev/null @@ -1,15 +0,0 @@ -setWordWrap(false); - return $generator; - } -} diff --git a/src/Phpro/SoapClient/CodeGenerator/Model/Parameter.php b/src/Phpro/SoapClient/CodeGenerator/Model/Parameter.php index 94424e3a..7f5621c4 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Model/Parameter.php +++ b/src/Phpro/SoapClient/CodeGenerator/Model/Parameter.php @@ -82,19 +82,6 @@ public function getType(): string return '\\'.$this->namespace.'\\'.Normalizer::normalizeClassname($this->type); } - /** - * Get an array representation for creating a Generator - * - * @return array - */ - public function toArray(): array - { - return [ - 'name' => $this->name, - 'type' => $this->getType(), - ]; - } - public function getNamespace(): string { return $this->namespace;