From 2ca859b294a927309ab8a4d5fc325ff32d429337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faugeron?= Date: Tue, 13 Aug 2024 07:35:28 +0100 Subject: [PATCH 1/4] Renamed branch master to main --- CONTRIBUTING.md | 64 ++++++++++++++++++++++++++++++++++--------------- VERSIONING.md | 4 ++-- composer.json | 5 ---- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b705730..ee6cc71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,45 +19,71 @@ Here's some tips to make you the best contributor ever: ## Standard code Use [PHP CS fixer](http://cs.sensiolabs.org/) to make your code compliant with -Memio TwigTemplateEngine's coding standards: +Memio's coding standards: - ./vendor/bin/php-cs-fixer fix --config=sf23 . +```console +$ ./vendor/bin/php-cs-fixer fix . +``` ## Specifications -Memio TwigTemplateEngine drives its development using [phpspec](http://www.phpspec.net/): +Memio drives its development using [phpspec](http://www.phpspec.net/). - # Generate the specification class: - phpspec describe 'Memio\Memio\MyNewClass' +First bootstrap the code for the Specification: - # Customize the specification class: - $EDITOR tests/spec/Memio/TwigTemplateEngine/MyNewClass.php +```console +$ phpspec describe 'Memio\Memio\MyNewUseCase' +``` - # Generate the specified class: - phpspec run +Next, write the actual code of the Specification: - # Customize the class: - $EDITOR src/Memio/TwigTemplateEngine/MyNewClass.php +```console +$ $EDITOR spec/Memio/TwigTemplateEngine/MyNewUseCase.php +``` - phpspec run # Should be green! +Then bootstrap the code for the corresponding Use Case: + +```console +$ phpspec run +``` + +Follow that by writing the actual code of the Use Case: + +```console +$ $EDITOR src/Memio/TwigTemplateEngine/MyNewUseCase.php +``` + +Finally run the specification: + +```console +$ phpspec run +``` + +Results should be green! ## Keeping your fork up-to-date To keep your fork up-to-date, you should track the upstream (original) one using the following command: - git remote add upstream https://github.com/memio/twig-template-engine.git +```console +$ git remote add upstream https://github.com/memio/twig-template-engine.git +``` Then get the upstream changes: - git checkout master - git pull --rebase origin master - git pull --rebase upstream master - git checkout - git rebase master +```console +git checkout main +git pull --rebase origin main +git pull --rebase upstream main +git checkout +git rebase main +``` Finally, publish your changes: - git push -f origin +```console +$ git push -f origin +``` Your pull request will be automatically updated. diff --git a/VERSIONING.md b/VERSIONING.md index 9e005bd..c116035 100644 --- a/VERSIONING.md +++ b/VERSIONING.md @@ -22,6 +22,6 @@ API of this project. The branching is inspired by [@jbenet](https://github.com/jbenet) [simple git branching model](https://gist.github.com/jbenet/ee6c9ac48068889b0912): -> 1. `master` must always be deployable. +> 1. `main` must always be deployable. > 2. **all changes** are made through feature branches (pull-request + merge) -> 3. rebase to avoid/resolve conflicts; merge in to `master` +> 3. rebase to avoid/resolve conflicts; merge in to `main` diff --git a/composer.json b/composer.json index 2b15fd7..f0b17e8 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,5 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.10", "phpspec/phpspec": "^4.3" - }, - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } } } From 90ebc1c17878d9de7ffb6f4029f616f9908b4b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faugeron?= Date: Tue, 13 Aug 2024 07:36:06 +0100 Subject: [PATCH 2/4] Updated License to 2024 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 7bf1a25..e6896e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 Loïc Faugeron +Copyright (c) 2015-2024 Loïc Faugeron Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 273d0411434cc696164b2e3ac62d371694663273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faugeron?= Date: Tue, 13 Aug 2024 07:37:45 +0100 Subject: [PATCH 3/4] Removed travis and insight --- .travis.yml | 20 -------------------- README.md | 16 ++++++++++------ 2 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 610601e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -php: - - 7.0 - - 7.1 - - 7.2 - -before_script: - - composer selfupdate - - composer update $COMPOSER_FLAGS - -script: - - echo '[phpspec] Running specification tests'; ./vendor/bin/phpspec run -n -f dot - - output=$(php -n ./vendor/bin/php-cs-fixer fix -v --dry-run --config=sf23 .); if [[ $(grep -o F <<< $output | wc -l) -gt 3 ]]; then while read -r line; do echo -e "\e[00;31m$line\e[00m"; done <<< "$output"; false; fi; diff --git a/README.md b/README.md index 352abe5..5090885 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Memio's TwigTemplateEngine [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d36f6c6e-c3c1-44f5-9573-c76ad99c0253/mini.png)](https://insight.sensiolabs.com/projects/d36f6c6e-c3c1-44f5-9573-c76ad99c0253) [![Travis CI](https://travis-ci.org/memio/twig-template-engine.png)](https://travis-ci.org/memio/twig-template-engine) +# Memio's TwigTemplateEngine Memio is a highly opinionated PHP code generator library. It is composed of small independent packages, one being `PrettyPrinter`: the actual code generator. @@ -16,7 +16,9 @@ This package, `TwigTemplateEngine`, provides an implementation and templates for Install it using [Composer](https://getcomposer.org/download): - composer require memio/twig-template-engine:^2.0 +```console +composer require memio/twig-template-engine:^2.0 +``` ## Example @@ -73,7 +75,7 @@ echo $prettyPrinter->generateCode($myService); With this simple example, we get the following output: -``` +```php Date: Tue, 13 Aug 2024 08:42:23 +0100 Subject: [PATCH 4/4] Added php 8 and phpspec 7 support, dropped support for php >7.2 --- composer.json | 8 +-- .../Line/ContractLineStrategySpec.php | 22 +++++--- .../Line/FileLineStrategySpec.php | 19 ++++--- .../TwigExtension/Line/LineSpec.php | 26 ++++----- .../Line/MethodPhpdocLineStrategySpec.php | 55 +++++++------------ .../Line/ObjectLineStrategySpec.php | 53 ++++++++++-------- .../Line/StructurePhpdocLineStrategySpec.php | 53 ++++++++++-------- .../Line/ContractLineStrategy.php | 8 +-- .../TwigExtension/Line/FileLineStrategy.php | 7 ++- .../Line/MethodPhpdocLineStrategy.php | 15 ++--- .../TwigExtension/Line/ObjectLineStrategy.php | 14 ++--- .../Line/StructurePhpdocLineStrategy.php | 14 +++-- 12 files changed, 151 insertions(+), 143 deletions(-) diff --git a/composer.json b/composer.json index f0b17e8..f9c45e6 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,13 @@ "Memio\\TwigTemplateEngine\\Config\\": "config" }}, "require": { - "memio/model": "^2.0", - "memio/pretty-printer": "^2.0", - "php": "^7.0", + "memio/model": "^3.0", + "memio/pretty-printer": "^3.0", + "php": "^7.2 || ^8.0", "twig/twig": "^1.18 || ^2.0 || ^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.10", - "phpspec/phpspec": "^4.3" + "phpspec/phpspec": "^6.1 || ^7.0" } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php index 01e01cd..939c5da 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php @@ -11,30 +11,34 @@ namespace spec\Memio\TwigTemplateEngine\TwigExtension\Line; +use Memio\Model\Constant; use Memio\Model\Contract; +use Memio\Model\Method; use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy; +use Memio\TwigTemplateEngine\TwigExtension\Line\ContractLineStrategy; use PhpSpec\ObjectBehavior; class ContractLineStrategySpec extends ObjectBehavior { - const CONSTANT_BLOCK = 'constants'; - function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_contracts(Contract $contract) + function it_supports_contracts() { + $contract = (new Contract('Memio\PrettyPrinter\TemplateEngine')); + $this->supports($contract)->shouldBe(true); } - function it_needs_line_after_constants_if_contract_has_both_constants_and_methods( - Contract $contract - ) { - $contract->allConstants()->willReturn([1]); - $contract->allMethods()->willReturn([2]); + function it_needs_an_empty_line_after_constants_if_it_also_has_methods() + { + $contract = (new Contract('Memio\PrettyPrinter\TemplateEngine')) + ->addConstant(new Constant('CONSTANT_ONE', 1)) + ->addMethod(new Method('methodOne')) + ; - $this->needsLineAfter($contract, self::CONSTANT_BLOCK)->shouldBe(true); + $this->needsLineAfter($contract, ContractLineStrategy::CONSTANTS_BLOCK)->shouldBe(true); } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php index a1e6d8b..9e65398 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php @@ -12,28 +12,31 @@ namespace spec\Memio\TwigTemplateEngine\TwigExtension\Line; use Memio\Model\File; +use Memio\Model\FullyQualifiedName; +use Memio\TwigTemplateEngine\TwigExtension\Line\FileLineStrategy; use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy; use PhpSpec\ObjectBehavior; class FileLineStrategySpec extends ObjectBehavior { - const IMPORT_BLOCK = 'fully_qualified_names'; - function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_files(File $file) + function it_supports_files() { + $file = new File('src/Memio/Model/Contract.php'); + $this->supports($file)->shouldBe(true); } - function it_needs_line_after_fully_qualified_names_if_file_has_fully_qualified_names( - File $file - ) { - $file->allFullyQualifiedNames()->willReturn([1]); + function it_needs_an_empty_line_after_use_statements() + { + $file = (new File('src/Memio/Model/Contract.php')) + ->addFullyQualifiedName(new FullyQualifiedName('Memio\Model\Phpdoc\StructurePhpdoc')) + ; - $this->needsLineAfter($file, self::IMPORT_BLOCK)->shouldBe(true); + $this->needsLineAfter($file, FileLineStrategy::USE_STATEMENTS_BLOCK)->shouldBe(true); } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php index 618f5e1..6053946 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php @@ -18,32 +18,32 @@ class LineSpec extends ObjectBehavior { - const BLOCK = 'constants'; - const STRATEGY_RETURN = true; - - function let(LineStrategy $lineStrategy) - { - $this->add($lineStrategy); - } - function it_executes_the_first_strategy_that_supports_given_model( - Argument $model, LineStrategy $lineStrategy ) { + $this->add($lineStrategy); + + $model = new Argument('string', 'filename'); + $block = 'arguments'; + $strategyReturn = true; + $lineStrategy->supports($model)->willReturn(true); - $lineStrategy->needsLineAfter($model, self::BLOCK)->willReturn(self::STRATEGY_RETURN); + $lineStrategy->needsLineAfter($model, $block)->willReturn($strategyReturn); - $this->needsLineAfter($model, self::BLOCK)->shouldBe(self::STRATEGY_RETURN); + $this->needsLineAfter($model, $block)->shouldBe($strategyReturn); } function it_fails_when_no_strategy_supports_given_model( - Argument $model, LineStrategy $lineStrategy ) { + $this->add($lineStrategy); + + $model = new Argument('string', 'filename'); + $lineStrategy->supports($model)->willReturn(false); $this->shouldThrow( InvalidArgumentException::class - )->duringNeedsLineAfter($model, self::BLOCK); + )->duringNeedsLineAfter($model, 'arguments'); } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php index 8ae2de2..b8d3c5f 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php @@ -26,52 +26,39 @@ function it_is_a_line_strategy() $this->shouldImplement(LineStrategy::class); } - function it_supports_method_phpdocs(MethodPhpdoc $methodPhpdoc) + function it_supports_method_phpdocs() { + $methodPhpdoc = new MethodPhpdoc(); + $this->supports($methodPhpdoc)->shouldBe(true); } - function it_needs_line_after_description_if_it_has_any_other_tag( - Description $description, - DeprecationTag $deprecationTag, - MethodPhpdoc $methodPhpdoc - ) { - $methodPhpdoc->getApiTag()->willReturn(null); - $methodPhpdoc->getDescription()->willReturn($description); - $methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag); - $methodPhpdoc->getParameterTags()->willReturn([]); - $methodPhpdoc->getReturnTag()->willReturn(null); - $methodPhpdoc->getThrowTags()->willReturn([]); + function it_needs_a_new_line_after_description_if_it_has_any_other_tag() + { + $methodPhpdoc = (new MethodPhpdoc()) + ->setDescription(new Description('Helpful description')) + ->setDeprecationTag(new DeprecationTag()) + ; $this->needsLineAfter($methodPhpdoc, 'description')->shouldBe(true); } - function it_needs_line_after_parameter_tags_if_it_has_api_or_deprecation_tags( - DeprecationTag $deprecationTag, - MethodPhpdoc $methodPhpdoc, - ParameterTag $parameterTag - ) { - $methodPhpdoc->getApiTag()->willReturn(null); - $methodPhpdoc->getDescription()->willReturn(null); - $methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag); - $methodPhpdoc->getParameterTags()->willReturn([$parameterTag]); - $methodPhpdoc->getReturnTag()->willReturn(null); - $methodPhpdoc->getThrowTags()->willReturn([]); + function it_needs_a_new_line_after_parameter_tags_if_it_has_a_deprecation_tag() + { + $methodPhpdoc = (new MethodPhpdoc()) + ->addParameterTag(new ParameterTag('string', 'filename')) + ->setDeprecationTag(new DeprecationTag()) + ; $this->needsLineAfter($methodPhpdoc, 'parameter_tags')->shouldBe(true); } - function it_needs_line_after_deprecation_it_also_has_an_api_tag( - ApiTag $apiTag, - DeprecationTag $deprecationTag, - MethodPhpdoc $methodPhpdoc - ) { - $methodPhpdoc->getDeprecationTag()->willReturn($deprecationTag); - $methodPhpdoc->getDescription()->willReturn(null); - $methodPhpdoc->getApiTag()->willReturn($apiTag); - $methodPhpdoc->getParameterTags()->willReturn([]); - $methodPhpdoc->getReturnTag()->willReturn(null); - $methodPhpdoc->getThrowTags()->willReturn([]); + function it_needs_a_new_line_after_deprecation_if_it_also_has_an_api_tag() + { + $methodPhpdoc = (new MethodPhpdoc()) + ->setDeprecationTag(new DeprecationTag()) + ->setApiTag(new ApiTag()) + ; $this->needsLineAfter($methodPhpdoc, 'deprecation_tag')->shouldBe(true); } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php index 9172669..cd4b0fc 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php @@ -12,50 +12,55 @@ namespace spec\Memio\TwigTemplateEngine\TwigExtension\Line; use Memio\Model\Objekt; +use Memio\Model\Constant; +use Memio\Model\Method; +use Memio\Model\Property; use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy; +use Memio\TwigTemplateEngine\TwigExtension\Line\ObjectLineStrategy; use PhpSpec\ObjectBehavior; class ObjectLineStrategySpec extends ObjectBehavior { - const CONSTANT_BLOCK = 'constants'; - const PROPERTY_BLOCK = 'properties'; - function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_objects(Objekt $object) + function it_supports_objects() { - $this->supports($object)->shouldBe(true); + $objekt = new Objekt('Memio\Model\Objekt'); + + $this->supports($objekt)->shouldBe(true); } - function it_needs_line_after_constants_if_object_has_both_constants_and_properties( - Objekt $object - ) { - $object->allConstants()->willReturn([1]); - $object->allProperties()->willReturn([2]); - $object->allMethods()->willReturn([]); + function it_needs_an_empty_line_after_constants_if_it_also_has_properties() + { + $objekt = (new Objekt('Memio\Model\Objekt')) + ->addConstant(new Constant('CONSTANT_ONE', 1)) + ->addProperty(new Property('filename')) + ->addProperty(new Property('content')) + ; - $this->needsLineAfter($object, self::CONSTANT_BLOCK)->shouldBe(true); + $this->needsLineAfter($objekt, ObjectLineStrategy::CONSTANTS_BLOCK)->shouldBe(true); } - function it_needs_line_after_constants_if_object_has_both_constants_and_methods( - Objekt $object - ) { - $object->allConstants()->willReturn([1]); - $object->allProperties()->willReturn([]); - $object->allMethods()->willReturn([2]); + function it_needs_an_empty_line_after_constants_if_it_also_has_methods() + { + $objekt = (new Objekt('Memio\Model\Objekt')) + ->addConstant(new Constant('CONSTANT_ONE', 1)) + ->addMethod(new Method('write')) + ; - $this->needsLineAfter($object, self::CONSTANT_BLOCK)->shouldBe(true); + $this->needsLineAfter($objekt, ObjectLineStrategy::CONSTANTS_BLOCK)->shouldBe(true); } - function it_needs_line_after_properties_if_object_has_both_properties_and_methods(Objekt $object) + function it_needs_an_empty_line_after_properties_if_it_also_has_methods() { - $object->allConstants()->willReturn([]); - $object->allProperties()->willReturn([1]); - $object->allMethods()->willReturn([2]); + $objekt = (new Objekt('Memio\Model\Objekt')) + ->addProperty(new Property('filename')) + ->addMethod(new Method('write')) + ; - $this->needsLineAfter($object, self::PROPERTY_BLOCK)->shouldBe(true); + $this->needsLineAfter($objekt, ObjectLineStrategy::PROPERTIES_BLOCK)->shouldBe(true); } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php index a70c7bd..0bca958 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php @@ -16,6 +16,7 @@ use Memio\Model\Phpdoc\Description; use Memio\Model\Phpdoc\DeprecationTag; use Memio\TwigTemplateEngine\TwigExtension\Line\LineStrategy; +use Memio\TwigTemplateEngine\TwigExtension\Line\StructurePhpdocLineStrategy; use PhpSpec\ObjectBehavior; class StructurePhpdocLineStrategySpec extends ObjectBehavior @@ -25,34 +26,40 @@ function it_is_a_line_strategy() $this->shouldImplement(LineStrategy::class); } - function it_supports_structure_phpdocs(StructurePhpdoc $structurePhpdoc) + function it_supports_structure_phpdocs() { + $structurePhpdoc = new StructurePhpdoc(); + $this->supports($structurePhpdoc)->shouldBe(true); } - function it_needs_line_after_description_if_description_and_deprecation_or_api_are_defined( - ApiTag $apiTag, - Description $description, - DeprecationTag $deprecationTag, - StructurePhpdoc $structurePhpdoc - ) { - $structurePhpdoc->getApiTag()->willReturn($apiTag); - $structurePhpdoc->getDescription()->willReturn($description); - $structurePhpdoc->getDeprecationTag()->willReturn($deprecationTag); - - $this->needsLineAfter($structurePhpdoc, 'description')->shouldBe(true); + function it_needs_an_empty_line_after_description_if_it_also_has_an_api_tag() + { + $structurePhpdoc = (new StructurePhpdoc()) + ->setDescription(new Description('helpful description')) + ->setApiTag(new ApiTag()) + ; + + $this->needsLineAfter($structurePhpdoc, StructurePhpdocLineStrategy::DESCRPTION)->shouldBe(true); } - function it_needs_line_after_deprecation_if_deprecation_and_api_are_defined( - ApiTag $apiTag, - Description $description, - DeprecationTag $deprecationTag, - StructurePhpdoc $structurePhpdoc - ) { - $structurePhpdoc->getApiTag()->willReturn($apiTag); - $structurePhpdoc->getDescription()->willReturn($description); - $structurePhpdoc->getDeprecationTag()->willReturn($deprecationTag); - - $this->needsLineAfter($structurePhpdoc, 'deprecation_tag')->shouldBe(true); + function it_needs_an_empty_line_after_description_if_it_also_has_a_deprecation_tag() + { + $structurePhpdoc = (new StructurePhpdoc()) + ->setDescription(new Description('helpful description')) + ->setDeprecationTag(new DeprecationTag()) + ; + + $this->needsLineAfter($structurePhpdoc, StructurePhpdocLineStrategy::DESCRPTION)->shouldBe(true); + } + + function it_needs_an_empty_line_after_deprecation_tag_if_it_also_has_an_api_tag() + { + $structurePhpdoc = (new StructurePhpdoc()) + ->setDeprecationTag(new DeprecationTag()) + ->setApiTag(new ApiTag()) + ; + + $this->needsLineAfter($structurePhpdoc, StructurePhpdocLineStrategy::DEPRECATION_TAG)->shouldBe(true); } } diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php index 067d46f..49f50ba 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php @@ -16,6 +16,8 @@ class ContractLineStrategy implements LineStrategy { + const CONSTANTS_BLOCK = 'constants'; + public function supports($model): bool { return $model instanceof Contract; @@ -23,10 +25,8 @@ public function supports($model): bool public function needsLineAfter($model, string $block): bool { - $constants = $model->allConstants(); - $methods = $model->allMethods(); - if ('constants' === $block) { - return !empty($constants) && !empty($methods); + if (self::CONSTANTS_BLOCK === $block) { + return [] !== $model->constants && [] !== $model->methods; } throw new InvalidArgumentException('The function needs_line_after does not support given "'.$block.'"'); diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php index 070ffd4..bfb28e6 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php @@ -16,6 +16,8 @@ class FileLineStrategy implements LineStrategy { + const USE_STATEMENTS_BLOCK = 'fully_qualified_names'; + public function supports($model): bool { return $model instanceof File; @@ -23,9 +25,8 @@ public function supports($model): bool public function needsLineAfter($model, string $block): bool { - $fullyQualifiedNames = $model->allFullyQualifiedNames(); - if ('fully_qualified_names' === $block) { - return !empty($fullyQualifiedNames); + if (self::USE_STATEMENTS_BLOCK === $block) { + return [] !== $model->fullyQualifiedNames; } throw new InvalidArgumentException('The function needs_line_after does not support given "'.$block.'"'); diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategy.php index 9b29503..0217fbe 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategy.php @@ -22,15 +22,12 @@ public function supports($model): bool public function needsLineAfter($model, string $block): bool { - $parameterTags = $model->getParameterTags(); - $throwTags = $model->getThrowTags(); - - $hasApiTag = (null !== $model->getApiTag()); - $hasParameterTags = (!empty($parameterTags)); - $hasDescription = (null !== $model->getDescription()); - $hasDeprecationTag = (null !== $model->getDeprecationTag()); - $hasReturnTag = (null !== $model->getReturnTag()); - $hasThrowTags = (!empty($throwTags)); + $hasApiTag = (null !== $model->apiTag); + $hasParameterTags = ([] !== $model->parameterTags); + $hasDescription = (null !== $model->description); + $hasDeprecationTag = (null !== $model->deprecationTag); + $hasReturnTag = (null !== $model->returnTag); + $hasThrowTags = ([] !== $model->throwTags); if ('description' === $block) { return $hasDescription && ($hasReturnTag || $hasApiTag || $hasDeprecationTag || $hasParameterTags || $hasThrowTags); diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php index dc449f3..f38b164 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php @@ -16,6 +16,9 @@ class ObjectLineStrategy implements LineStrategy { + const CONSTANTS_BLOCK = 'constants'; + const PROPERTIES_BLOCK = 'properties'; + public function supports($model): bool { return $model instanceof Objekt; @@ -23,14 +26,11 @@ public function supports($model): bool public function needsLineAfter($model, string $block): bool { - $constants = $model->allConstants(); - $properties = $model->allProperties(); - $methods = $model->allMethods(); - if ('constants' === $block) { - return !empty($constants) && (!empty($properties) || !empty($methods)); + if (self::CONSTANTS_BLOCK === $block) { + return [] !== $model->constants && ([] !== $model->properties || [] !== $model->methods); } - if ('properties' === $block) { - return !empty($properties) && !empty($methods); + if (self::PROPERTIES_BLOCK === $block) { + return [] !== $model->properties && [] !== $model->methods; } throw new InvalidArgumentException('The function needs_line_after does not support given "'.$block.'"'); diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php index dc5f04b..207d17d 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php @@ -15,6 +15,9 @@ class StructurePhpdocLineStrategy implements LineStrategy { + const DESCRPTION = 'description'; + const DEPRECATION_TAG = 'deprecation_tag'; + public function supports($model): bool { return $model instanceof StructurePhpdoc; @@ -22,13 +25,14 @@ public function supports($model): bool public function needsLineAfter($model, string $block): bool { - $hasDescription = (null !== $model->getDescription()); - $hasApiTag = (null !== $model->getApiTag()); - $hasDeprecationTag = (null !== $model->getDeprecationTag()); - if ('description' === $block) { + $hasDescription = (null !== $model->description); + $hasApiTag = (null !== $model->apiTag); + $hasDeprecationTag = (null !== $model->deprecationTag); + + if (self::DESCRPTION === $block) { return $hasDescription && ($hasApiTag || $hasDeprecationTag); } - if ('deprecation_tag' === $block) { + if (self::DEPRECATION_TAG === $block) { return $hasApiTag && $hasDeprecationTag; } }