From cbae88b8543b162435d0b41cafb71ffa9498f913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Mierzy=C5=84ski?= Date: Thu, 5 Jun 2025 14:02:35 +0200 Subject: [PATCH 1/5] Updated phpmd rules --- .../Pimcore11/phpcs/.php-cs-fixer.dist.php | 85 +++++++++++++++++++ Standards/Pimcore11/phpmd/rulesetmd.xml | 34 ++++++++ Standards/Pimcore11/phpstan/phpstan.neon | 15 ++++ composer.json | 4 +- 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php create mode 100644 Standards/Pimcore11/phpmd/rulesetmd.xml create mode 100644 Standards/Pimcore11/phpstan/phpstan.neon diff --git a/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php b/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php new file mode 100644 index 0000000..6cc7663 --- /dev/null +++ b/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php @@ -0,0 +1,85 @@ + true, + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + + // keep aligned = and => operators as they are: do not force aligning, but do not remove it + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => ['statements' => ['return']], + 'blank_lines_before_namespace' => true, + 'encoding' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], + 'lowercase_cast' => true, + 'method_argument_space' => ['on_multiline' => 'ignore'], + 'class_attributes_separation' => ['elements' => ['method' => 'one']], + 'class_definition' => ['single_line' => true], + 'clean_namespace' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_parentheses' => true, + 'empty_loop_body' => ['style' => 'braces'], + 'fully_qualified_strict_types' => true, + 'function_declaration' => true, + 'general_phpdoc_tag_rename' => ['replacements' => ['inheritDocs' => 'inheritDoc']], + 'lambda_not_used_import' => true, + 'linebreak_after_opening_tag' => true, + 'magic_constant_casing' => true, + 'native_function_casing' => true, + 'no_alternative_syntax' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_short_bool_cast' => true, + 'no_spaces_around_offset' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unused_imports' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => true, + 'phpdoc_indent' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'return_type_declaration' => true, + 'short_scalar_cast' => true, + 'single_space_around_construct' => true, + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'trim_array_spaces' => true, + 'type_declaration_spaces' => true, + 'types_spaces' => ['space' => 'single'], + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, +]; + +$finder = (new PhpCsFixer\Finder) + ->in([ + __DIR__ . '/../../../../../src', + ]) + + // do not fix views + ->notName('*.html.php') + + // using notPath instead of exclude here as they can be nested (install-profiles) + ->notPath( __DIR__ . '/../../../../../var\/config') + ->notPath( __DIR__ . '/../../../../../var\/classes'); + + +foreach ($finder as $file) { + dump($file->getRealPath()); +}; + +// do not enable self_accessor as it breaks pimcore models relying on get_called_class() +return (new PhpCsFixer\Config) + ->setRules($rules) + ->setFinder($finder); diff --git a/Standards/Pimcore11/phpmd/rulesetmd.xml b/Standards/Pimcore11/phpmd/rulesetmd.xml new file mode 100644 index 0000000..225a52d --- /dev/null +++ b/Standards/Pimcore11/phpmd/rulesetmd.xml @@ -0,0 +1,34 @@ + + + + Pimcore 11 rule set + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Standards/Pimcore11/phpstan/phpstan.neon b/Standards/Pimcore11/phpstan/phpstan.neon new file mode 100644 index 0000000..261993a --- /dev/null +++ b/Standards/Pimcore11/phpstan/phpstan.neon @@ -0,0 +1,15 @@ +includes: + - vendor/ekino/phpstan-banned-code/extension.neon + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-doctrine/extension.neon + - vendor/phpstan/phpstan-symfony/extension.neon +parameters: + bootstrapFiles: + - scripts/phpstan-bootstrap.php + level: 8 + symfony: + containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml + scanDirectories: + - var/cache/dev/Symfony/Config + scanFiles: + - vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php \ No newline at end of file diff --git a/composer.json b/composer.json index ef7c4d1..e3cff3c 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,9 @@ } ], "require": { - "squizlabs/php_codesniffer": "@stable" + "squizlabs/php_codesniffer": "@stable", + "friendsofphp/php-cs-fixer": "^3.4", + "ekino/phpstan-banned-code": "^3.0" }, "require-dev": { "sclable/xml-lint": "^0.2.4" From 4c1b8730e38a68f3265a1e0742ebb19e61aea58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Mierzy=C5=84ski?= Date: Thu, 5 Jun 2025 14:16:00 +0200 Subject: [PATCH 2/5] Changed phpstan-banned-code version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e3cff3c..91ad073 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "require": { "squizlabs/php_codesniffer": "@stable", "friendsofphp/php-cs-fixer": "^3.4", - "ekino/phpstan-banned-code": "^3.0" + "ekino/phpstan-banned-code": "^2.0" }, "require-dev": { "sclable/xml-lint": "^0.2.4" From 356230f24013530c499bec98e7cea303cbc27e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Mierzy=C5=84ski?= Date: Thu, 5 Jun 2025 14:33:13 +0200 Subject: [PATCH 3/5] Updated config for CS Fixer --- Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php | 11 +++-------- composer.json | 4 +++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php b/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php index 6cc7663..f631a99 100644 --- a/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php +++ b/Standards/Pimcore11/phpcs/.php-cs-fixer.dist.php @@ -64,20 +64,15 @@ $finder = (new PhpCsFixer\Finder) ->in([ - __DIR__ . '/../../../../../src', + __DIR__ . '/../../../../../../src', ]) // do not fix views ->notName('*.html.php') // using notPath instead of exclude here as they can be nested (install-profiles) - ->notPath( __DIR__ . '/../../../../../var\/config') - ->notPath( __DIR__ . '/../../../../../var\/classes'); - - -foreach ($finder as $file) { - dump($file->getRealPath()); -}; + ->notPath(__DIR__ . '/../../../../../../var\/config') + ->notPath(__DIR__ . '/../../../../../../var\/classes'); // do not enable self_accessor as it breaks pimcore models relying on get_called_class() return (new PhpCsFixer\Config) diff --git a/composer.json b/composer.json index 91ad073..d2b4b44 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,9 @@ "require": { "squizlabs/php_codesniffer": "@stable", "friendsofphp/php-cs-fixer": "^3.4", - "ekino/phpstan-banned-code": "^2.0" + "ekino/phpstan-banned-code": "^2.0", + "phpmd/phpmd": "^2.15", + "phpstan/phpstan": "1.*" }, "require-dev": { "sclable/xml-lint": "^0.2.4" From e3a8a88f54ebf9497f3f833cb54ba4e7db01efb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Mierzy=C5=84ski?= Date: Thu, 5 Jun 2025 14:39:22 +0200 Subject: [PATCH 4/5] Added additional tools --- composer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d2b4b44..261443b 100644 --- a/composer.json +++ b/composer.json @@ -33,9 +33,11 @@ "require": { "squizlabs/php_codesniffer": "@stable", "friendsofphp/php-cs-fixer": "^3.4", - "ekino/phpstan-banned-code": "^2.0", "phpmd/phpmd": "^2.15", - "phpstan/phpstan": "1.*" + "ekino/phpstan-banned-code": "^2.0", + "phpstan/phpstan": "1.*", + "phpstan/phpstan-doctrine": "1.*", + "phpstan/phpstan-symfony": "1.*" }, "require-dev": { "sclable/xml-lint": "^0.2.4" From 2002e8ce82f6f2ea22129b556e4fe20a2d7787cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Mierzy=C5=84ski?= Date: Thu, 5 Jun 2025 14:48:43 +0200 Subject: [PATCH 5/5] Added configuration for phpstan --- .../Pimcore11/phpstan/phpstan-bootstrap.php | 4 ++++ Standards/Pimcore11/phpstan/phpstan.neon | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 Standards/Pimcore11/phpstan/phpstan-bootstrap.php diff --git a/Standards/Pimcore11/phpstan/phpstan-bootstrap.php b/Standards/Pimcore11/phpstan/phpstan-bootstrap.php new file mode 100644 index 0000000..ec16c66 --- /dev/null +++ b/Standards/Pimcore11/phpstan/phpstan-bootstrap.php @@ -0,0 +1,4 @@ +