diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 514b12f..3505bae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + php: ['8.0', '8.1', '8.2', '8.3'] #, '8.4', '8.5'] include: - php: '8.0' run-qa: true diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index a588fa0..c7beae3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -27,20 +27,25 @@ * ; * ``` */ - $finder = (new PhpCsFixer\Finder()) ->in(__DIR__) + ->ignoreDotFiles(false) ; return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, - // [Symfony] defaults to `camelCase`, we set it to `snake_case` (phpspec style) + // [Symfony] defaults to `camelCase`, we set it to `snake_case` (phpspec style) 'php_unit_method_casing' => ['case' => 'snake_case'], - // [Symfony] defaults to `true`, we set it to `false` for phpspec - 'visibility_required' => false, + // [Symfony] defaults to `['elements' => ['const', 'method', 'property']]` + // We exclude `method` for phpspec (no visibility keyword) + // We exclude `const` because we support PHP 8.0 (const visibility is optional) + 'modifier_keywords' => ['elements' => ['property']], + + // [Symfony] defaults to `['elements' => ['arguments', 'arrays', 'parameters']]` + 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays', 'parameters']], ]) ->setUsingCache(true) ->setFinder($finder) diff --git a/composer.json b/composer.json index f664be6..70ec11c 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ "require": { "memio/model": "^3.0", "memio/pretty-printer": "^3.0", - "php": "^7.2 || ^8.0", - "twig/twig": "^1.18 || ^2.0 || ^3.0" + "php": "^8.0", + "twig/twig": "^3.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.19.3", - "phpspec/phpspec": "^6.1 || ^7.0", + "friendsofphp/php-cs-fixer": "^3.0", + "phpspec/phpspec": "^7.0", "rector/rector": "^2.3", "rector/swiss-knife": "^2.3", "phpstan/phpstan": "^2.1" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7319f18..365106a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,6 +3,6 @@ includes: parameters: level: 0 - phpVersion: 70200 + phpVersion: 80000 paths: - src/ diff --git a/rector.php b/rector.php index f2db8c0..5649d8f 100644 --- a/rector.php +++ b/rector.php @@ -9,7 +9,7 @@ return RectorConfig::configure() ->withCache( '/tmp/rector', - FileCacheStorage::class + FileCacheStorage::class, ) ->withPaths([ __DIR__, @@ -23,7 +23,7 @@ ]) ->withSets([ // —— PHP —————————————————————————————————————————————————————————————— - SetList::PHP_72, + SetList::PHP_80, ]) ->withRules([ ]); diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php index 9a6068a..9aa10a7 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategySpec.php @@ -20,19 +20,19 @@ class ContractLineStrategySpec extends ObjectBehavior { - function it_is_a_line_strategy() + public function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_contracts() + public function it_supports_contracts() { $contract = (new Contract('Memio\PrettyPrinter\TemplateEngine')); $this->supports($contract)->shouldBe(true); } - function it_needs_an_empty_line_after_constants_if_it_also_has_methods() + public 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)) diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php index 9e65398..4fd4ee0 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategySpec.php @@ -19,19 +19,19 @@ class FileLineStrategySpec extends ObjectBehavior { - function it_is_a_line_strategy() + public function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_files() + public function it_supports_files() { $file = new File('src/Memio/Model/Contract.php'); $this->supports($file)->shouldBe(true); } - function it_needs_an_empty_line_after_use_statements() + public function it_needs_an_empty_line_after_use_statements() { $file = (new File('src/Memio/Model/Contract.php')) ->addFullyQualifiedName(new FullyQualifiedName('Memio\Model\Phpdoc\StructurePhpdoc')) diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php index 6053946..8c177e5 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/LineSpec.php @@ -18,8 +18,8 @@ class LineSpec extends ObjectBehavior { - function it_executes_the_first_strategy_that_supports_given_model( - LineStrategy $lineStrategy + public function it_executes_the_first_strategy_that_supports_given_model( + LineStrategy $lineStrategy, ) { $this->add($lineStrategy); @@ -33,8 +33,8 @@ function it_executes_the_first_strategy_that_supports_given_model( $this->needsLineAfter($model, $block)->shouldBe($strategyReturn); } - function it_fails_when_no_strategy_supports_given_model( - LineStrategy $lineStrategy + public function it_fails_when_no_strategy_supports_given_model( + LineStrategy $lineStrategy, ) { $this->add($lineStrategy); @@ -43,7 +43,7 @@ function it_fails_when_no_strategy_supports_given_model( $lineStrategy->supports($model)->willReturn(false); $this->shouldThrow( - InvalidArgumentException::class + InvalidArgumentException::class, )->duringNeedsLineAfter($model, 'arguments'); } } diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php index 38f8431..44c2340 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/MethodPhpdocLineStrategySpec.php @@ -21,19 +21,19 @@ class MethodPhpdocLineStrategySpec extends ObjectBehavior { - function it_is_a_line_strategy() + public function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_method_phpdocs() + public function it_supports_method_phpdocs() { $methodPhpdoc = new MethodPhpdoc(); $this->supports($methodPhpdoc)->shouldBe(true); } - function it_needs_a_new_line_after_description_if_it_has_any_other_tag() + public function it_needs_a_new_line_after_description_if_it_has_any_other_tag() { $methodPhpdoc = (new MethodPhpdoc()) ->setDescription(new Description('Helpful description')) @@ -43,7 +43,7 @@ function it_needs_a_new_line_after_description_if_it_has_any_other_tag() $this->needsLineAfter($methodPhpdoc, 'description')->shouldBe(true); } - function it_needs_a_new_line_after_parameter_tags_if_it_has_a_deprecation_tag() + public function it_needs_a_new_line_after_parameter_tags_if_it_has_a_deprecation_tag() { $methodPhpdoc = (new MethodPhpdoc()) ->addParameterTag(new ParameterTag('string', 'filename')) @@ -53,7 +53,7 @@ function it_needs_a_new_line_after_parameter_tags_if_it_has_a_deprecation_tag() $this->needsLineAfter($methodPhpdoc, 'parameter_tags')->shouldBe(true); } - function it_needs_a_new_line_after_deprecation_if_it_also_has_an_api_tag() + public function it_needs_a_new_line_after_deprecation_if_it_also_has_an_api_tag() { $methodPhpdoc = (new MethodPhpdoc()) ->setDeprecationTag(new DeprecationTag()) diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php index 75b112d..7466758 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategySpec.php @@ -21,19 +21,19 @@ class ObjectLineStrategySpec extends ObjectBehavior { - function it_is_a_line_strategy() + public function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_objects() + public function it_supports_objects() { $objekt = new Objekt('Memio\Model\Objekt'); $this->supports($objekt)->shouldBe(true); } - function it_needs_an_empty_line_after_constants_if_it_also_has_properties() + public 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)) @@ -44,7 +44,7 @@ function it_needs_an_empty_line_after_constants_if_it_also_has_properties() $this->needsLineAfter($objekt, ObjectLineStrategy::CONSTANTS_BLOCK)->shouldBe(true); } - function it_needs_an_empty_line_after_constants_if_it_also_has_methods() + public 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)) @@ -54,7 +54,7 @@ function it_needs_an_empty_line_after_constants_if_it_also_has_methods() $this->needsLineAfter($objekt, ObjectLineStrategy::CONSTANTS_BLOCK)->shouldBe(true); } - function it_needs_an_empty_line_after_properties_if_it_also_has_methods() + public function it_needs_an_empty_line_after_properties_if_it_also_has_methods() { $objekt = (new Objekt('Memio\Model\Objekt')) ->addProperty(new Property('filename')) diff --git a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php index 16ed446..b491991 100644 --- a/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategySpec.php @@ -21,19 +21,19 @@ class StructurePhpdocLineStrategySpec extends ObjectBehavior { - function it_is_a_line_strategy() + public function it_is_a_line_strategy() { $this->shouldImplement(LineStrategy::class); } - function it_supports_structure_phpdocs() + public function it_supports_structure_phpdocs() { $structurePhpdoc = new StructurePhpdoc(); $this->supports($structurePhpdoc)->shouldBe(true); } - function it_needs_an_empty_line_after_description_if_it_also_has_an_api_tag() + public function it_needs_an_empty_line_after_description_if_it_also_has_an_api_tag() { $structurePhpdoc = (new StructurePhpdoc()) ->setDescription(new Description('helpful description')) @@ -43,7 +43,7 @@ function it_needs_an_empty_line_after_description_if_it_also_has_an_api_tag() $this->needsLineAfter($structurePhpdoc, StructurePhpdocLineStrategy::DESCRPTION)->shouldBe(true); } - function it_needs_an_empty_line_after_description_if_it_also_has_a_deprecation_tag() + public function it_needs_an_empty_line_after_description_if_it_also_has_a_deprecation_tag() { $structurePhpdoc = (new StructurePhpdoc()) ->setDescription(new Description('helpful description')) @@ -53,7 +53,7 @@ function it_needs_an_empty_line_after_description_if_it_also_has_a_deprecation_t $this->needsLineAfter($structurePhpdoc, StructurePhpdocLineStrategy::DESCRPTION)->shouldBe(true); } - function it_needs_an_empty_line_after_deprecation_tag_if_it_also_has_an_api_tag() + public function it_needs_an_empty_line_after_deprecation_tag_if_it_also_has_an_api_tag() { $structurePhpdoc = (new StructurePhpdoc()) ->setDeprecationTag(new DeprecationTag()) diff --git a/spec/Memio/TwigTemplateEngine/TwigTemplateEngineSpec.php b/spec/Memio/TwigTemplateEngine/TwigTemplateEngineSpec.php index 3f5f462..2e17b0b 100644 --- a/spec/Memio/TwigTemplateEngine/TwigTemplateEngineSpec.php +++ b/spec/Memio/TwigTemplateEngine/TwigTemplateEngineSpec.php @@ -18,23 +18,23 @@ class TwigTemplateEngineSpec extends ObjectBehavior { - const TEMPLATE_PATH = '/tmp/templates'; - const TEMPLATE = 'argument'; - const OUTPUT = '$dateTime'; + public const TEMPLATE_PATH = '/tmp/templates'; + public const TEMPLATE = 'argument'; + public const OUTPUT = '$dateTime'; - function let(Environment $twig) + public function let(Environment $twig) { $this->beConstructedWith($twig); } - function it_is_a_template_engine() + public function it_is_a_template_engine() { $this->shouldHaveType(TemplateEngine::class); } - function it_can_have_more_paths( + public function it_can_have_more_paths( Environment $twig, - FilesystemLoader $loader + FilesystemLoader $loader, ) { $twig->getLoader()->willReturn($loader); $loader->prependPath(self::TEMPLATE_PATH)->shouldBeCalled(); @@ -42,8 +42,8 @@ function it_can_have_more_paths( $this->addPath(self::TEMPLATE_PATH); } - function it_renders_templates_using_twig( - Environment $twig + public function it_renders_templates_using_twig( + Environment $twig, ) { $parameters = ['name' => 'dateTime']; diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php index a922ae2..ef60eb0 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ContractLineStrategy.php @@ -16,7 +16,7 @@ class ContractLineStrategy implements LineStrategy { - const CONSTANTS_BLOCK = 'constants'; + public const CONSTANTS_BLOCK = 'constants'; public function supports($model): bool { diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php index c044faf..b8a6f22 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/FileLineStrategy.php @@ -16,7 +16,7 @@ class FileLineStrategy implements LineStrategy { - const USE_STATEMENTS_BLOCK = 'fully_qualified_names'; + public const USE_STATEMENTS_BLOCK = 'fully_qualified_names'; public function supports($model): bool { diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/Line.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/Line.php index e095096..332683b 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/Line.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/Line.php @@ -33,6 +33,6 @@ public function needsLineAfter($model, string $block): bool } } - throw new InvalidArgumentException('No strategy supports given model '.get_class($model)); + throw new InvalidArgumentException('No strategy supports given model '.$model::class); } } diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php index d5f4884..10d48e5 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/ObjectLineStrategy.php @@ -16,8 +16,8 @@ class ObjectLineStrategy implements LineStrategy { - const CONSTANTS_BLOCK = 'constants'; - const PROPERTIES_BLOCK = 'properties'; + public const CONSTANTS_BLOCK = 'constants'; + public const PROPERTIES_BLOCK = 'properties'; public function supports($model): bool { diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php b/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php index 8a7e922..20a2fc0 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Line/StructurePhpdocLineStrategy.php @@ -15,8 +15,8 @@ class StructurePhpdocLineStrategy implements LineStrategy { - const DESCRPTION = 'description'; - const DEPRECATION_TAG = 'deprecation_tag'; + public const DESCRPTION = 'description'; + public const DEPRECATION_TAG = 'deprecation_tag'; public function supports($model): bool { diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Type.php b/src/Memio/TwigTemplateEngine/TwigExtension/Type.php index c8f5c40..0eadc3b 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Type.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Type.php @@ -65,7 +65,7 @@ public function hasTypehint($model): bool public function filterNamespace(string $stringType): string { - $nullablePrefix = '?' === substr($stringType, 0, 1) + $nullablePrefix = str_starts_with($stringType, '?') ? '?' : ''; diff --git a/src/Memio/TwigTemplateEngine/TwigExtension/Whitespace.php b/src/Memio/TwigTemplateEngine/TwigExtension/Whitespace.php index d464b08..deb08f7 100644 --- a/src/Memio/TwigTemplateEngine/TwigExtension/Whitespace.php +++ b/src/Memio/TwigTemplateEngine/TwigExtension/Whitespace.php @@ -13,7 +13,6 @@ use Memio\Model\FullyQualifiedName; use Memio\Model\Phpdoc\ParameterTag; -use Memio\Model\Type as ModelType; use Memio\TwigTemplateEngine\TwigExtension\Line\Line; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; @@ -21,11 +20,8 @@ class Whitespace extends AbstractExtension { - private $line; - - public function __construct(Line $line) + public function __construct(private Line $line) { - $this->line = $line; } public function getFunctions(): array @@ -48,10 +44,9 @@ public function align(string $current, array $collection): string $elementLength = strlen($current); $longestElement = $elementLength; foreach ($collection as $element) { - if (ParameterTag::class === get_class($element)) { - $type = $element->getType(); - $modelType = new ModelType($element->getType()); - if ($modelType->isObject()) { + if (ParameterTag::class === $element::class) { + $type = $element->type->getName(); + if ($element->type->isObject()) { $fullyQualifiedName = new FullyQualifiedName($type); $type = $fullyQualifiedName->getName(); } @@ -65,7 +60,7 @@ public function align(string $current, array $collection): string public function indent( string $text, int $level = 1, - string $type = 'code' + string $type = 'code', ): string { $lines = explode("\n", $text); $indentedLines = []; diff --git a/src/Memio/TwigTemplateEngine/TwigTemplateEngine.php b/src/Memio/TwigTemplateEngine/TwigTemplateEngine.php index 6886724..52c847b 100644 --- a/src/Memio/TwigTemplateEngine/TwigTemplateEngine.php +++ b/src/Memio/TwigTemplateEngine/TwigTemplateEngine.php @@ -16,11 +16,8 @@ class TwigTemplateEngine implements TemplateEngine { - private $twig; - - public function __construct(Environment $twig) + public function __construct(private Environment $twig) { - $this->twig = $twig; } public function addPath(string $path)