From 20c49d851cb752f57d8673a0faa0dadca940c316 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Sun, 18 Jan 2026 01:24:35 -0600 Subject: [PATCH] Refactored usage to custom ruleset classes to standardize usage in down stream packages. Removes ruleset.php. Introduces Webware1x0Set. Introduces WebwareCopyRight. See .php-cs-fixer.dist.php for usage. Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- .php-cs-fixer.dist.php | 41 +-- composer.json | 2 +- composer.lock | 51 ++-- src/Webware1x0Set.php | 638 +++++++++++++++++++++++++++++++++++++++ src/WebwareCopyRight.php | 136 +++++++++ src/ruleset.php | 610 ------------------------------------- 6 files changed, 819 insertions(+), 659 deletions(-) create mode 100644 src/Webware1x0Set.php create mode 100644 src/WebwareCopyRight.php delete mode 100644 src/ruleset.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fa0dd09..1e3d11a 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,36 +5,27 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; +use Webware\CodingStandard\WebwareCopyRight; +use Webware\CodingStandard\Webware1x0Set; -$year = date('Y'); - -$fileHeader = <<
- - For the full copyright and license information, please view the LICENSE - file that was distributed with this source code. - HEADER; - -$ruleSet = require 'src/ruleset.php'; +$composerData = json_decode(file_get_contents('composer.json'), true); return (new Config()) + ->registerCustomRuleSets([ + new WebwareCopyRight( + packageName: $composerData['name'], + authorName: $composerData['authors'][0]['name'], + authorEmail: $composerData['authors'][0]['email'], + minYear: '2026', + ), + new Webware1x0Set(), + ]) ->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually ->setRiskyAllowed(true) - ->setRules( - array_merge( - $ruleSet, - [ - 'header_comment' => [ - 'header' => $fileHeader, - 'comment_type' => 'PHPDoc', - 'location' => 'after_declare_strict', - 'separate' => 'both', - ], - ] - ) - ) + ->setRules([ + '@Webware/copyright-header' => true, + '@Webware/coding-standard-1.0' => true, + ]) // 💡 by default, Fixer looks for `*.php` files excluding `./vendor/` - here, you can groom this config ->setFinder( (new Finder()) diff --git a/composer.json b/composer.json index a85fc55..cb6754e 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "check": [ "@cs-check" ], - "cs-check": "vendor/bin/php-cs-fixer check", + "cs-check": "vendor/bin/php-cs-fixer check -v --show-progress=dots --using-cache=no", "cs-fix": "vendor/bin/php-cs-fixer fix" } } diff --git a/composer.lock b/composer.lock index 664f766..9b5f038 100644 --- a/composer.lock +++ b/composer.lock @@ -402,16 +402,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.92.4", + "version": "v3.92.5", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "9e7488b19403423e02e8403cc1eb596baf4673b0" + "reference": "260cc8c4a1d2f6d2f22cd4f9c70aa72e55ebac58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/9e7488b19403423e02e8403cc1eb596baf4673b0", - "reference": "9e7488b19403423e02e8403cc1eb596baf4673b0", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/260cc8c4a1d2f6d2f22cd4f9c70aa72e55ebac58", + "reference": "260cc8c4a1d2f6d2f22cd4f9c70aa72e55ebac58", "shasum": "" }, "require": { @@ -494,7 +494,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.92.4" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.92.5" }, "funding": [ { @@ -502,7 +502,7 @@ "type": "github" } ], - "time": "2026-01-04T00:38:52+00:00" + "time": "2026-01-08T21:57:37+00:00" }, { "name": "psr/container", @@ -2681,12 +2681,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "9a341b84b3ebb8ad254193ce440b44c7d4375a4f" + "reference": "57ac71b06405e32e77d960bb8490683138573f04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/9a341b84b3ebb8ad254193ce440b44c7d4375a4f", - "reference": "9a341b84b3ebb8ad254193ce440b44c7d4375a4f", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/57ac71b06405e32e77d960bb8490683138573f04", + "reference": "57ac71b06405e32e77d960bb8490683138573f04", "shasum": "" }, "conflict": { @@ -2701,12 +2701,14 @@ "aimeos/ai-cms-grapesjs": ">=2021.04.1,<2021.10.8|>=2022.04.1,<2022.10.9|>=2023.04.1,<2023.10.15|>=2024.04.1,<2024.10.8|>=2025.04.1,<2025.10.2", "aimeos/ai-controller-frontend": "<2020.10.15|>=2021.04.1,<2021.10.8|>=2022.04.1,<2022.10.8|>=2023.04.1,<2023.10.9|==2024.04.1", "aimeos/aimeos-core": ">=2022.04.1,<2022.10.17|>=2023.04.1,<2023.10.17|>=2024.04.1,<2024.04.7", + "aimeos/aimeos-laravel": "==2021.10", "aimeos/aimeos-typo3": "<19.10.12|>=20,<20.10.5", "airesvsg/acf-to-rest-api": "<=3.1", "akaunting/akaunting": "<2.1.13", "akeneo/pim-community-dev": "<5.0.119|>=6,<6.0.53", - "alextselegidis/easyappointments": "<1.5.2.0-beta1", + "alextselegidis/easyappointments": "<=1.5.2", "alexusmai/laravel-file-manager": "<=3.3.1", + "algolia/algoliasearch-magento-2": "<=3.16.1|>=3.17.0.0-beta1,<=3.17.1", "alt-design/alt-redirect": "<1.6.4", "altcha-org/altcha": "<1.3.1", "alterphp/easyadmin-extension-bundle": ">=1.2,<1.2.11|>=1.3,<1.3.1", @@ -2780,7 +2782,7 @@ "bytefury/crater": "<6.0.2", "cachethq/cachet": "<2.5.1", "cadmium-org/cadmium-cms": "<=0.4.9", - "cakephp/cakephp": "<3.10.3|>=4,<4.0.10|>=4.1,<4.1.4|>=4.2,<4.2.12|>=4.3,<4.3.11|>=4.4,<4.4.10", + "cakephp/cakephp": "<3.10.3|>=4,<4.0.10|>=4.1,<4.1.4|>=4.2,<4.2.12|>=4.3,<4.3.11|>=4.4,<4.4.10|>=5.2.10,<5.2.12|==5.3", "cakephp/database": ">=4.2,<4.2.12|>=4.3,<4.3.11|>=4.4,<4.4.10", "cardgate/magento2": "<2.0.33", "cardgate/woocommerce": "<=3.1.15", @@ -2819,6 +2821,7 @@ "contao/core-bundle": "<4.13.57|>=5,<5.3.42|>=5.4,<5.6.5", "contao/listing-bundle": ">=3,<=3.5.30|>=4,<4.4.8", "contao/managed-edition": "<=1.5", + "coreshop/core-shop": "<=4.1.7", "corveda/phpsandbox": "<1.3.5", "cosenary/instagram": "<=2.3", "couleurcitron/tarteaucitron-wp": "<0.3", @@ -2870,7 +2873,7 @@ "drupal/commerce_alphabank_redirect": "<1.0.3", "drupal/commerce_eurobank_redirect": "<2.1.1", "drupal/config_split": "<1.10|>=2,<2.0.2", - "drupal/core": ">=6,<6.38|>=7,<7.102|>=8,<10.4.9|>=10.5,<10.5.6|>=11,<11.1.9|>=11.2,<11.2.8", + "drupal/core": ">=6,<6.38|>=7,<7.103|>=8,<10.4.9|>=10.5,<10.5.6|>=11,<11.1.9|>=11.2,<11.2.8", "drupal/core-recommended": ">=7,<7.102|>=8,<10.2.11|>=10.3,<10.3.9|>=11,<11.0.8", "drupal/currency": "<3.5", "drupal/drupal": ">=5,<5.11|>=6,<6.38|>=7,<7.102|>=8,<10.2.11|>=10.3,<10.3.9|>=11,<11.0.8", @@ -2985,7 +2988,7 @@ "geshi/geshi": "<=1.0.9.1", "getformwork/formwork": "<2.2", "getgrav/grav": "<1.11.0.0-beta1", - "getkirby/cms": "<3.9.8.3-dev|>=3.10,<3.10.1.2-dev|>=4,<4.7.1|>=5,<5.1.4", + "getkirby/cms": "<3.9.8.3-dev|>=3.10,<3.10.1.2-dev|>=4,<4.7.1|>=5,<=5.2.1", "getkirby/kirby": "<3.9.8.3-dev|>=3.10,<3.10.1.2-dev|>=4,<4.7.1", "getkirby/panel": "<2.5.14", "getkirby/starterkit": "<=3.7.0.2", @@ -3214,7 +3217,7 @@ "october/cms": "<1.0.469|==1.0.469|==1.0.471|==1.1.1", "october/october": "<3.7.5", "october/rain": "<1.0.472|>=1.1,<1.1.2", - "october/system": "<3.7.5", + "october/system": "<=3.7.12|>=4,<=4.0.11", "oliverklee/phpunit": "<3.5.15", "omeka/omeka-s": "<4.0.3", "onelogin/php-saml": "<2.21.1|>=3,<3.8.1|>=4,<4.3.1", @@ -3278,14 +3281,15 @@ "phpxmlrpc/extras": "<0.6.1", "phpxmlrpc/phpxmlrpc": "<4.9.2", "pi/pi": "<=2.5", - "pimcore/admin-ui-classic-bundle": "<1.7.6", + "pimcore/admin-ui-classic-bundle": "<=1.7.15|>=2.0.0.0-RC1-dev,<=2.2.2", "pimcore/customer-management-framework-bundle": "<4.2.1", "pimcore/data-hub": "<1.2.4", "pimcore/data-importer": "<1.8.9|>=1.9,<1.9.3", "pimcore/demo": "<10.3", "pimcore/ecommerce-framework-bundle": "<1.0.10", "pimcore/perspective-editor": "<1.5.1", - "pimcore/pimcore": "<11.5.4", + "pimcore/pimcore": "<=11.5.13|>=12.0.0.0-RC1-dev,<12.3.1", + "pimcore/web2print-tools-bundle": "<=5.2.1|>=6.0.0.0-RC1-dev,<=6.1", "piwik/piwik": "<1.11", "pixelfed/pixelfed": "<0.12.5", "plotly/plotly.js": "<2.25.2", @@ -3349,10 +3353,10 @@ "setasign/fpdi": "<2.6.4", "sfroemken/url_redirect": "<=1.2.1", "sheng/yiicms": "<1.2.1", - "shopware/core": "<6.6.10.9-dev|>=6.7,<6.7.4.1-dev", + "shopware/core": "<6.6.10.9-dev|>=6.7,<6.7.6.1-dev", "shopware/platform": "<6.6.10.7-dev|>=6.7,<6.7.3.1-dev", "shopware/production": "<=6.3.5.2", - "shopware/shopware": "<=5.7.17|>=6.4.6,<6.6.10.10-dev|>=6.7,<6.7.5.1-dev", + "shopware/shopware": "<=5.7.17|>=6.4.6,<6.6.10.10-dev|>=6.7,<6.7.6.1-dev", "shopware/storefront": "<6.6.10.10-dev|>=6.7,<6.7.5.1-dev", "shopxo/shopxo": "<=6.4", "showdoc/showdoc": "<2.10.4", @@ -3397,7 +3401,7 @@ "snipe/snipe-it": "<=8.3.4", "socalnick/scn-social-auth": "<1.15.2", "socialiteproviders/steam": "<1.1", - "solspace/craft-freeform": ">=5,<5.10.16", + "solspace/craft-freeform": "<4.1.29|>=5,<5.10.16", "soosyze/soosyze": "<=2", "spatie/browsershot": "<5.0.5", "spatie/image-optimizer": "<1.7.3", @@ -3505,10 +3509,10 @@ "twbs/bootstrap": "<3.4.1|>=4,<4.3.1", "twig/twig": "<3.11.2|>=3.12,<3.14.1|>=3.16,<3.19", "typo3/cms": "<9.5.29|>=10,<10.4.35|>=11,<11.5.23|>=12,<12.2", - "typo3/cms-backend": "<4.1.14|>=4.2,<4.2.15|>=4.3,<4.3.7|>=4.4,<4.4.4|>=7,<=7.6.50|>=8,<=8.7.39|>=9,<9.5.55|>=10,<10.4.54|>=11,<11.5.48|>=12,<12.4.37|>=13,<13.4.18", + "typo3/cms-backend": "<4.1.14|>=4.2,<4.2.15|>=4.3,<4.3.7|>=4.4,<4.4.4|>=7,<=7.6.50|>=8,<=8.7.39|>=9,<9.5.55|>=10,<=10.4.54|>=11,<=11.5.48|>=12,<=12.4.40|>=13,<=13.4.22|>=14,<=14.0.1", "typo3/cms-belog": ">=10,<=10.4.47|>=11,<=11.5.41|>=12,<=12.4.24|>=13,<=13.4.2", "typo3/cms-beuser": ">=9,<9.5.55|>=10,<10.4.54|>=11,<11.5.48|>=12,<12.4.37|>=13,<13.4.18", - "typo3/cms-core": "<=8.7.56|>=9,<9.5.55|>=10,<10.4.54|>=11,<11.5.48|>=12,<12.4.37|>=13,<13.4.18", + "typo3/cms-core": "<=8.7.56|>=9,<9.5.55|>=10,<=10.4.54|>=11,<=11.5.48|>=12,<=12.4.40|>=13,<=13.4.22|>=14,<=14.0.1", "typo3/cms-dashboard": ">=10,<10.4.54|>=11,<11.5.48|>=12,<12.4.37|>=13,<13.4.18", "typo3/cms-extbase": "<6.2.24|>=7,<7.6.8|==8.1.1", "typo3/cms-extensionmanager": ">=10,<=10.4.47|>=11,<=11.5.41|>=12,<=12.4.24|>=13,<=13.4.2", @@ -3520,7 +3524,8 @@ "typo3/cms-install": "<4.1.14|>=4.2,<4.2.16|>=4.3,<4.3.9|>=4.4,<4.4.5|>=12.2,<12.4.8|==13.4.2", "typo3/cms-lowlevel": ">=11,<=11.5.41", "typo3/cms-recordlist": ">=11,<11.5.48", - "typo3/cms-recycler": ">=9,<9.5.55|>=10,<10.4.54|>=11,<11.5.48|>=12,<12.4.37|>=13,<13.4.18", + "typo3/cms-recycler": ">=9,<9.5.55|>=10,<=10.4.54|>=11,<=11.5.48|>=12,<=12.4.40|>=13,<=13.4.22|>=14,<=14.0.1", + "typo3/cms-redirects": ">=10,<=10.4.54|>=11,<=11.5.48|>=12,<=12.4.40|>=13,<=13.4.22|>=14,<=14.0.1", "typo3/cms-rte-ckeditor": ">=9.5,<9.5.42|>=10,<10.4.39|>=11,<11.5.30", "typo3/cms-scheduler": ">=11,<=11.5.41", "typo3/cms-setup": ">=9,<=9.5.50|>=10,<=10.4.49|>=11,<=11.5.43|>=12,<=12.4.30|>=13,<=13.4.11", @@ -3679,7 +3684,7 @@ "type": "tidelift" } ], - "time": "2026-01-05T20:06:42+00:00" + "time": "2026-01-16T21:05:58+00:00" } ], "aliases": [], diff --git a/src/Webware1x0Set.php b/src/Webware1x0Set.php new file mode 100644 index 0000000..359cd58 --- /dev/null +++ b/src/Webware1x0Set.php @@ -0,0 +1,638 @@ + + * and contributors. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webware\CodingStandard; + +use PhpCsFixer\RuleSet\RuleSetDefinitionInterface; + +final class Webware1x0Set implements RuleSetDefinitionInterface +{ + public const SET_NAME = '@Webware/coding-standard-1.0'; + + public function getDescription(): string + { + return 'Webware Coding Standard ruleset. Extends @PER-CS3x0.'; + } + + public function getName(): string + { + return self::SET_NAME; + } + + public function isRisky(): bool + { + return true; + } + + public function getRules(): array + { + return [ + '@PER-CS3x0' => true, + // Basic + 'encoding' => true, + 'full_opening_tag' => true, + 'no_closing_tag' => true, + // Array Notation + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'no_trailing_comma_in_singleline' => [ + 'elements' => [ + 'array', + 'array_destructuring', + ], + ], + 'trim_array_spaces' => true, + 'whitespace_after_comma_in_array' => [ + 'ensure_single_space' => true, + ], + 'no_whitespace_before_comma_in_array' => [ + 'after_heredoc' => false, + ], + 'trailing_comma_in_multiline' => [ + 'elements' => [ + 'arrays', + ], + ], + // Attribute Notation + 'attribute_empty_parentheses' => [ + 'use_parentheses' => true, + ], + // Casing + 'constant_case' => [ + 'case' => 'lower', + ], + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'native_function_casing' => true, + 'native_type_declaration_casing' => true, + // Cast Notation + 'cast_spaces' => [ + 'space' => 'single', + ], + 'lowercase_cast' => true, + 'no_short_bool_cast' => true, + 'short_scalar_cast' => true, + // Class Notation + 'class_attributes_separation' => [ + 'elements' => [ + 'const' => 'one', + 'method' => 'one', + 'property' => 'one', + 'trait_import' => 'none', + ], + ], + 'class_definition' => [ + 'single_line' => true, + 'single_item_single_line' => true, + 'multi_line_extends_each_single_line' => true, + 'space_before_parenthesis' => false, + ], + 'no_blank_lines_after_class_opening' => true, + 'no_null_property_initialization' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'case', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + ], + 'sort_algorithm' => 'none', + ], + 'single_class_element_per_statement' => [ + 'elements' => [ + 'property', + 'const', + ], + ], + 'visibility_required' => [ + 'elements' => [ + 'property', + 'method', + 'const', + ], + ], + 'no_php4_constructor' => true, + // Comment + 'comment_to_phpdoc' => true, + 'multiline_comment_opening_closing' => true, + 'no_empty_comment' => true, + 'no_trailing_whitespace_in_comment' => true, + 'single_line_comment_spacing' => true, + 'single_line_comment_style' => [ + 'comment_types' => [ + 'asterisk', + ], + ], + // Control Structure + 'control_structure_braces' => true, + 'control_structure_continuation_position' => [ + 'position' => 'same_line', + ], + 'elseif' => true, + 'no_break_comment' => [ + 'comment_text' => 'no break', + ], + 'no_superfluous_elseif' => true, + 'no_useless_else' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'switch_continue_to_break' => true, + 'trailing_comma_in_multiline' => [ + 'elements' => [ + 'arrays', + 'match', + 'parameters', + ], + ], + // Function Notation + 'function_declaration' => [ + 'closure_function_spacing' => 'one', + 'closure_fn_spacing' => 'one', + ], + 'lambda_not_used_import' => true, + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'after_heredoc' => false, + 'keep_multiple_spaces_after_comma' => false, + ], + 'no_spaces_after_function_name' => true, + 'no_useless_sprintf' => true, + 'nullable_type_declaration_for_default_null_value' => [ + 'use_nullable_type_declaration' => true, + ], + 'return_type_declaration' => [ + 'space_before' => 'none', + ], + 'single_line_throw' => true, + // Import + 'fully_qualified_strict_types' => [ + 'import_symbols' => true, + 'phpdoc_tags' => [ + 'param', + 'phpstan-param', + 'phpstan-property', + 'phpstan-property-read', + 'phpstan-property-write', + 'phpstan-return', + 'phpstan-var', + 'property', + 'property-read', + 'property-write', + 'psalm-param', + 'psalm-property', + 'psalm-property-read', + 'psalm-property-write', + 'psalm-return', + 'psalm-var', + 'return', + 'see', + 'throws', + 'var', + ], + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], + 'group_import' => false, + 'no_leading_import_slash' => true, + 'no_unneeded_import_alias' => true, + 'no_unused_imports' => true, + 'ordered_imports' => [ + 'sort_algorithm' => 'alpha', + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + ], + 'single_import_per_statement' => [ + 'group_to_single_imports' => true, + ], + 'single_line_after_imports' => true, + 'blank_line_between_import_groups' => true, + // Language Construct + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'declare_equal_normalize' => [ + 'space' => 'none', + ], + 'declare_parentheses' => true, + 'single_space_around_construct' => [ + 'constructs_followed_by_a_single_space' => [ + 'abstract', + 'as', + 'attribute', + 'break', + 'case', + 'catch', + 'class', + 'clone', + 'comment', + 'const', + 'const_import', + 'continue', + 'do', + 'echo', + 'else', + 'elseif', + 'enum', + 'extends', + 'final', + 'finally', + 'for', + 'foreach', + 'function', + 'function_import', + 'global', + 'goto', + 'if', + 'implements', + 'include', + 'include_once', + 'instanceof', + 'insteadof', + 'interface', + 'match', + 'named_argument', + 'namespace', + 'new', + 'open_tag_with_echo', + 'php_doc', + 'php_open', + 'print', + 'private', + 'protected', + 'public', + 'readonly', + 'require', + 'require_once', + 'return', + 'static', + 'switch', + 'throw', + 'trait', + 'try', + 'type_colon', + 'use', + 'use_lambda', + 'use_trait', + 'var', + 'while', + 'yield', + 'yield_from', + ], + ], + // List Notation + 'list_syntax' => [ + 'syntax' => 'short', + ], + // Namespace Notation + 'blank_line_after_namespace' => true, + 'blank_lines_before_namespace' => [ + 'min_line_breaks' => 2, + 'max_line_breaks' => 2, + ], + 'clean_namespace' => true, + 'no_leading_namespace_whitespace' => true, + // Operator + 'assign_null_coalescing_to_coalesce_equal' => true, + 'binary_operator_spaces' => [ + 'default' => 'align_single_space_minimal', + 'operators' => [ + '=>' => 'align_single_space_minimal_by_scope', + ], + ], + 'concat_space' => [ + 'spacing' => 'one', + ], + 'logical_operators' => true, + 'new_with_parentheses' => [ + 'named_class' => true, + 'anonymous_class' => true, + ], + 'no_space_around_double_colon' => true, + 'no_useless_concat_operator' => [ + 'juggle_simple_strings' => true, + ], + 'no_useless_nullsafe_operator' => true, + 'not_operator_with_successor_space' => true, + 'object_operator_without_whitespace' => true, + 'operator_linebreak' => [ + 'only_booleans' => false, + 'position' => 'beginning', + ], + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'unary_operator_spaces' => [ + 'only_dec_inc' => false, + ], + // PHP Tag + 'blank_line_after_opening_tag' => true, + 'linebreak_after_opening_tag' => true, + // PHPDoc + 'align_multiline_comment' => [ + 'comment_type' => 'phpdocs_only', + ], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'api', + 'author', + 'category', + 'copyright', + 'created', + 'license', + 'package', + 'subpackage', + 'version', + ], + ], + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_phpdoc' => true, + 'no_superfluous_phpdoc_tags' => [ + 'remove_inheritdoc' => false, + 'allow_mixed' => true, + 'allow_unused_params' => false, + ], + 'phpdoc_align' => [ + 'align' => 'left', + ], + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag_normalizer' => [ + 'tags' => [ + 'example', + 'id', + 'internal', + 'inheritdoc', + 'inheritdocs', + 'link', + 'source', + 'toc', + 'tutorial', + ], + ], + 'phpdoc_line_span' => [ + 'const' => 'single', + 'property' => 'single', + 'method' => null, + ], + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => [ + 'replacements' => [ + 'property-read' => 'property', + 'property-write' => 'property', + 'type' => 'var', + 'link' => 'see', + ], + ], + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => [ + 'order' => [ + 'internal', + 'deprecated', + 'link', + 'see', + 'uses', + 'param', + 'return', + 'throws', + ], + ], + 'phpdoc_order_by_value' => [ + 'annotations' => [ + 'covers', + 'coversNothing', + 'dataProvider', + 'depends', + 'group', + 'internal', + 'method', + 'mixin', + 'property', + 'property-read', + 'property-write', + 'requires', + 'throws', + 'uses', + ], + ], + 'phpdoc_param_order' => true, + 'phpdoc_return_self_reference' => [ + 'replacements' => [ + 'this' => '$this', + '@this' => '$this', + '$self' => 'self', + '@self' => 'self', + '$static' => 'static', + '@static' => 'static', + ], + ], + 'phpdoc_scalar' => [ + 'types' => [ + 'boolean', + 'callback', + 'double', + 'integer', + 'real', + 'str', + ], + ], + 'phpdoc_separation' => [ + 'groups' => [ + [ + 'internal', + 'deprecated', + ], + [ + 'link', + 'see', + 'uses', + ], + [ + 'param', + 'return', + 'throws', + ], + ], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => false, + 'phpdoc_tag_casing' => [ + 'tags' => [ + 'inheritDoc', + ], + ], + 'phpdoc_tag_type' => [ + 'tags' => [ + 'api' => 'annotation', + 'author' => 'annotation', + 'copyright' => 'annotation', + 'deprecated' => 'annotation', + 'example' => 'annotation', + 'global' => 'annotation', + 'inheritDoc' => 'annotation', + 'internal' => 'annotation', + 'license' => 'annotation', + 'method' => 'annotation', + 'package' => 'annotation', + 'param' => 'annotation', + 'property' => 'annotation', + 'return' => 'annotation', + 'see' => 'annotation', + 'since' => 'annotation', + 'throws' => 'annotation', + 'todo' => 'annotation', + 'uses' => 'annotation', + 'var' => 'annotation', + 'version' => 'annotation', + ], + ], + 'phpdoc_to_comment' => [ + 'ignored_tags' => [ + 'psalm-suppress', + 'phpstan-ignore-line', + 'phpstan-ignore-next-line', + ], + ], + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_types' => [ + 'groups' => [ + 'simple', + 'alias', + 'meta', + ], + ], + 'phpdoc_types_order' => [ + 'sort_algorithm' => 'alpha', + 'null_adjustment' => 'always_last', + ], + 'phpdoc_var_annotation_correct_order' => true, + 'phpdoc_var_without_name' => true, + // Return Notation + 'no_useless_return' => true, + 'return_assignment' => true, + 'simplified_null_return' => true, + // Semicolon + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'no_empty_statement' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'semicolon_after_instruction' => true, + 'space_after_semicolon' => [ + 'remove_in_empty_for_expressions' => false, + ], + // Strict + 'declare_strict_types' => true, + 'strict_comparison' => true, + 'strict_param' => true, + // String Notation + 'explicit_string_variable' => true, + 'heredoc_to_nowdoc' => true, + 'simple_to_complex_string_variable' => true, + 'single_quote' => [ + 'strings_containing_single_quote_chars' => false, + ], + // Whitespace + 'array_indentation' => true, + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'case', + 'continue', + 'declare', + 'default', + 'exit', + 'goto', + 'include', + 'include_once', + 'phpdoc', + 'require', + 'require_once', + 'return', + 'switch', + 'throw', + 'try', + 'yield', + 'yield_from', + ], + ], + 'compact_nullable_type_declaration' => true, + 'heredoc_indentation' => [ + 'indentation' => 'same_as_start', + ], + 'indentation_type' => true, + 'line_ending' => true, + 'method_chaining_indentation' => true, + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'attribute', + 'break', + 'case', + 'continue', + 'curly_brace_block', + 'default', + 'extra', + 'parenthesis_brace_block', + 'return', + 'square_brace_block', + 'switch', + 'throw', + 'use', + ], + ], + 'no_spaces_around_offset' => [ + 'positions' => [ + 'inside', + 'outside', + ], + ], + 'no_trailing_whitespace' => true, + 'no_whitespace_in_blank_line' => true, + 'single_blank_line_at_eof' => true, + 'statement_indentation' => [ + 'stick_comment_to_next_continuous_control_statement' => true, + ], + 'type_declaration_spaces' => [ + 'elements' => [ + 'function', + 'property', + ], + ], + 'types_spaces' => [ + 'space' => 'none', + ], + ]; + } +} diff --git a/src/WebwareCopyRight.php b/src/WebwareCopyRight.php new file mode 100644 index 0000000..07b62ca --- /dev/null +++ b/src/WebwareCopyRight.php @@ -0,0 +1,136 @@ + + * and contributors. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webware\CodingStandard; + +use PhpCsFixer\RuleSet\RuleSetDefinitionInterface; + +use function date; +use function explode; +use function sprintf; +use function str_contains; +use function str_replace; +use function ucwords; + +final class WebwareCopyRight implements RuleSetDefinitionInterface +{ + public const SET_NAME = '@Webware/copyright-header'; + + private string $year; + + private string $copyText = <<<'HEADER' + This file is part of the %s package. + + Copyright (c) %s %s %s + and contributors. + + For the full copyright and license information, please view the LICENSE + file that was distributed with this source code. + HEADER; + + public function __construct( + // composer vendor/package name + private string $packageName, + private string $authorName, + private string $authorEmail, + private string $minYear = '2026', + ?string $copyText = null, + ) { + if ($copyText !== null) { + $this->copyText = $copyText; + } + + $this->formatPackageName(); + $this->formatAuthorName(); + $this->formatYear(); + $this->formatEmail(); + $this->buildCopyrightHeader(); + } + + public function getDescription(): string + { + return 'This ruleset class can be used to create a Copyright header for packages.'; + } + + public function getName(): string + { + return self::SET_NAME; + } + + public function isRisky(): bool + { + return false; + } + + public function getRules(): array + { + return [ + 'header_comment' => [ + 'header' => $this->copyText, + 'comment_type' => 'PHPDoc', + 'location' => 'after_declare_strict', + 'separate' => 'both', + ], + ]; + } + + private function formatPackageName(): void + { + if (str_contains($this->packageName, '/')) { + $parts = explode('/', $this->packageName); + $vendor = ucwords(str_replace(['-'], ' ', $parts[0])); + $package = ucwords(str_replace(['-'], ' ', $parts[1])); + $this->packageName = $vendor . ' ' . $package; + + return; + } + $this->packageName = ucwords(str_replace(['-'], ' ', $this->packageName)); + } + + private function formatAuthorName(): void + { + $this->authorName = ucwords($this->authorName); + } + + private function formatYear(): void + { + $currentYear = date('Y'); + if ($currentYear !== $this->minYear) { + $this->year = $this->minYear . '-' . $currentYear; + } else { + $this->year = $this->minYear; + } + } + + private function formatEmail(): void + { + if (! str_contains($this->authorEmail, '<')) { + $this->authorEmail = '<' . $this->authorEmail; + } + if (! str_contains($this->authorEmail, '>')) { + $this->authorEmail .= '>'; + } + } + + private function buildCopyrightHeader(): void + { + $this->copyText = sprintf( + $this->copyText, + $this->packageName, + $this->year, + $this->authorName, + $this->authorEmail + ); + } +} diff --git a/src/ruleset.php b/src/ruleset.php deleted file mode 100644 index 98ae7d4..0000000 --- a/src/ruleset.php +++ /dev/null @@ -1,610 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - '@PER-CS3x0' => true, - // Basic - 'encoding' => true, - 'full_opening_tag' => true, - 'no_closing_tag' => true, - // Array Notation - 'array_syntax' => [ - 'syntax' => 'short', - ], - 'no_trailing_comma_in_singleline' => [ - 'elements' => [ - 'array', - 'array_destructuring', - ], - ], - 'trim_array_spaces' => true, - 'whitespace_after_comma_in_array' => [ - 'ensure_single_space' => true, - ], - 'no_whitespace_before_comma_in_array' => [ - 'after_heredoc' => false, - ], - 'trailing_comma_in_multiline' => [ - 'elements' => [ - 'arrays', - ], - ], - // Attribute Notation - 'attribute_empty_parentheses' => [ - 'use_parentheses' => true, - ], - // Casing - 'constant_case' => [ - 'case' => 'lower', - ], - 'lowercase_keywords' => true, - 'lowercase_static_reference' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - 'native_function_casing' => true, - 'native_type_declaration_casing' => true, - // Cast Notation - 'cast_spaces' => [ - 'space' => 'single', - ], - 'lowercase_cast' => true, - 'no_short_bool_cast' => true, - 'short_scalar_cast' => true, - // Class Notation - 'class_attributes_separation' => [ - 'elements' => [ - 'const' => 'one', - 'method' => 'one', - 'property' => 'one', - 'trait_import' => 'none', - ], - ], - 'class_definition' => [ - 'single_line' => true, - 'single_item_single_line' => true, - 'multi_line_extends_each_single_line' => true, - 'space_before_parenthesis' => false, - ], - 'no_blank_lines_after_class_opening' => true, - 'no_null_property_initialization' => true, - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - 'case', - 'constant_public', - 'constant_protected', - 'constant_private', - 'property_public', - 'property_protected', - 'property_private', - 'construct', - 'destruct', - 'magic', - 'phpunit', - 'method_public', - 'method_protected', - 'method_private', - ], - 'sort_algorithm' => 'none', - ], - 'single_class_element_per_statement' => [ - 'elements' => [ - 'property', - 'const', - ], - ], - 'visibility_required' => [ - 'elements' => [ - 'property', - 'method', - 'const', - ], - ], - 'no_php4_constructor' => true, - // Comment - 'comment_to_phpdoc' => true, - 'multiline_comment_opening_closing' => true, - 'no_empty_comment' => true, - 'no_trailing_whitespace_in_comment' => true, - 'single_line_comment_spacing' => true, - 'single_line_comment_style' => [ - 'comment_types' => [ - 'asterisk', - ], - ], - // Control Structure - 'control_structure_braces' => true, - 'control_structure_continuation_position' => [ - 'position' => 'same_line', - ], - 'elseif' => true, - 'no_break_comment' => [ - 'comment_text' => 'no break', - ], - 'no_superfluous_elseif' => true, - 'no_useless_else' => true, - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'switch_continue_to_break' => true, - 'trailing_comma_in_multiline' => [ - 'elements' => [ - 'arrays', - 'match', - 'parameters', - ], - ], - // Function Notation - 'function_declaration' => [ - 'closure_function_spacing' => 'one', - 'closure_fn_spacing' => 'one', - ], - 'lambda_not_used_import' => true, - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline', - 'after_heredoc' => false, - 'keep_multiple_spaces_after_comma' => false, - ], - 'no_spaces_after_function_name' => true, - 'no_useless_sprintf' => true, - 'nullable_type_declaration_for_default_null_value' => [ - 'use_nullable_type_declaration' => true, - ], - 'return_type_declaration' => [ - 'space_before' => 'none', - ], - 'single_line_throw' => true, - // Import - 'fully_qualified_strict_types' => [ - 'import_symbols' => true, - 'phpdoc_tags' => [ - 'param', - 'phpstan-param', - 'phpstan-property', - 'phpstan-property-read', - 'phpstan-property-write', - 'phpstan-return', - 'phpstan-var', - 'property', - 'property-read', - 'property-write', - 'psalm-param', - 'psalm-property', - 'psalm-property-read', - 'psalm-property-write', - 'psalm-return', - 'psalm-var', - 'return', - 'see', - 'throws', - 'var', - ], - ], - 'global_namespace_import' => [ - 'import_classes' => true, - 'import_constants' => true, - 'import_functions' => true, - ], - 'group_import' => false, - 'no_leading_import_slash' => true, - 'no_unneeded_import_alias' => true, - 'no_unused_imports' => true, - 'ordered_imports' => [ - 'sort_algorithm' => 'alpha', - 'imports_order' => [ - 'class', - 'function', - 'const', - ], - ], - 'single_import_per_statement' => [ - 'group_to_single_imports' => true, - ], - 'single_line_after_imports' => true, - 'blank_line_between_import_groups' => true, - // Language Construct - 'combine_consecutive_issets' => true, - 'combine_consecutive_unsets' => true, - 'declare_equal_normalize' => [ - 'space' => 'none', - ], - 'declare_parentheses' => true, - 'single_space_around_construct' => [ - 'constructs_followed_by_a_single_space' => [ - 'abstract', - 'as', - 'attribute', - 'break', - 'case', - 'catch', - 'class', - 'clone', - 'comment', - 'const', - 'const_import', - 'continue', - 'do', - 'echo', - 'else', - 'elseif', - 'enum', - 'extends', - 'final', - 'finally', - 'for', - 'foreach', - 'function', - 'function_import', - 'global', - 'goto', - 'if', - 'implements', - 'include', - 'include_once', - 'instanceof', - 'insteadof', - 'interface', - 'match', - 'named_argument', - 'namespace', - 'new', - 'open_tag_with_echo', - 'php_doc', - 'php_open', - 'print', - 'private', - 'protected', - 'public', - 'readonly', - 'require', - 'require_once', - 'return', - 'static', - 'switch', - 'throw', - 'trait', - 'try', - 'type_colon', - 'use', - 'use_lambda', - 'use_trait', - 'var', - 'while', - 'yield', - 'yield_from', - ], - ], - // List Notation - 'list_syntax' => [ - 'syntax' => 'short', - ], - // Namespace Notation - 'blank_line_after_namespace' => true, - 'blank_lines_before_namespace' => [ - 'min_line_breaks' => 2, - 'max_line_breaks' => 2, - ], - 'clean_namespace' => true, - 'no_leading_namespace_whitespace' => true, - // Operator - 'assign_null_coalescing_to_coalesce_equal' => true, - 'binary_operator_spaces' => [ - 'default' => 'align_single_space_minimal', - 'operators' => [ - '=>' => 'align_single_space_minimal_by_scope', - ], - ], - 'concat_space' => [ - 'spacing' => 'one', - ], - 'logical_operators' => true, - 'new_with_parentheses' => [ - 'named_class' => true, - 'anonymous_class' => true, - ], - 'no_space_around_double_colon' => true, - 'no_useless_concat_operator' => [ - 'juggle_simple_strings' => true, - ], - 'no_useless_nullsafe_operator' => true, - 'not_operator_with_successor_space' => true, - 'object_operator_without_whitespace' => true, - 'operator_linebreak' => [ - 'only_booleans' => false, - 'position' => 'beginning', - ], - 'standardize_not_equals' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => true, - 'unary_operator_spaces' => [ - 'only_dec_inc' => false, - ], - // PHP Tag - 'blank_line_after_opening_tag' => true, - 'linebreak_after_opening_tag' => true, - // PHPDoc - 'align_multiline_comment' => [ - 'comment_type' => 'phpdocs_only', - ], - 'general_phpdoc_annotation_remove' => [ - 'annotations' => [ - 'api', - 'author', - 'category', - 'copyright', - 'created', - 'license', - 'package', - 'subpackage', - 'version', - ], - ], - 'no_blank_lines_after_phpdoc' => true, - 'no_empty_phpdoc' => true, - 'no_superfluous_phpdoc_tags' => [ - 'remove_inheritdoc' => false, - 'allow_mixed' => true, - 'allow_unused_params' => false, - ], - 'phpdoc_align' => [ - 'align' => 'left', - ], - 'phpdoc_annotation_without_dot' => false, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag_normalizer' => [ - 'tags' => [ - 'example', - 'id', - 'internal', - 'inheritdoc', - 'inheritdocs', - 'link', - 'source', - 'toc', - 'tutorial', - ], - ], - 'phpdoc_line_span' => [ - 'const' => 'single', - 'property' => 'single', - 'method' => null, - ], - 'phpdoc_no_access' => true, - 'phpdoc_no_alias_tag' => [ - 'replacements' => [ - 'property-read' => 'property', - 'property-write' => 'property', - 'type' => 'var', - 'link' => 'see', - ], - ], - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, - 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => [ - 'order' => [ - 'internal', - 'deprecated', - 'link', - 'see', - 'uses', - 'param', - 'return', - 'throws', - ], - ], - 'phpdoc_order_by_value' => [ - 'annotations' => [ - 'covers', - 'coversNothing', - 'dataProvider', - 'depends', - 'group', - 'internal', - 'method', - 'mixin', - 'property', - 'property-read', - 'property-write', - 'requires', - 'throws', - 'uses', - ], - ], - 'phpdoc_param_order' => true, - 'phpdoc_return_self_reference' => [ - 'replacements' => [ - 'this' => '$this', - '@this' => '$this', - '$self' => 'self', - '@self' => 'self', - '$static' => 'static', - '@static' => 'static', - ], - ], - 'phpdoc_scalar' => [ - 'types' => [ - 'boolean', - 'callback', - 'double', - 'integer', - 'real', - 'str', - ], - ], - 'phpdoc_separation' => [ - 'groups' => [ - [ - 'internal', - 'deprecated', - ], - [ - 'link', - 'see', - 'uses', - ], - [ - 'param', - 'return', - 'throws', - ], - ], - ], - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_summary' => false, - 'phpdoc_tag_casing' => [ - 'tags' => [ - 'inheritDoc', - ], - ], - 'phpdoc_tag_type' => [ - 'tags' => [ - 'api' => 'annotation', - 'author' => 'annotation', - 'copyright' => 'annotation', - 'deprecated' => 'annotation', - 'example' => 'annotation', - 'global' => 'annotation', - 'inheritDoc' => 'annotation', - 'internal' => 'annotation', - 'license' => 'annotation', - 'method' => 'annotation', - 'package' => 'annotation', - 'param' => 'annotation', - 'property' => 'annotation', - 'return' => 'annotation', - 'see' => 'annotation', - 'since' => 'annotation', - 'throws' => 'annotation', - 'todo' => 'annotation', - 'uses' => 'annotation', - 'var' => 'annotation', - 'version' => 'annotation', - ], - ], - 'phpdoc_to_comment' => [ - 'ignored_tags' => [ - 'psalm-suppress', - 'phpstan-ignore-line', - 'phpstan-ignore-next-line', - ], - ], - 'phpdoc_trim' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_types' => [ - 'groups' => [ - 'simple', - 'alias', - 'meta', - ], - ], - 'phpdoc_types_order' => [ - 'sort_algorithm' => 'alpha', - 'null_adjustment' => 'always_last', - ], - 'phpdoc_var_annotation_correct_order' => true, - 'phpdoc_var_without_name' => true, - // Return Notation - 'no_useless_return' => true, - 'return_assignment' => true, - 'simplified_null_return' => true, - // Semicolon - 'multiline_whitespace_before_semicolons' => [ - 'strategy' => 'no_multi_line', - ], - 'no_empty_statement' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'semicolon_after_instruction' => true, - 'space_after_semicolon' => [ - 'remove_in_empty_for_expressions' => false, - ], - // Strict - 'declare_strict_types' => true, - 'strict_comparison' => true, - 'strict_param' => true, - // String Notation - 'explicit_string_variable' => true, - 'heredoc_to_nowdoc' => true, - 'simple_to_complex_string_variable' => true, - 'single_quote' => [ - 'strings_containing_single_quote_chars' => false, - ], - // Whitespace - 'array_indentation' => true, - 'blank_line_before_statement' => [ - 'statements' => [ - 'break', - 'case', - 'continue', - 'declare', - 'default', - 'exit', - 'goto', - 'include', - 'include_once', - 'phpdoc', - 'require', - 'require_once', - 'return', - 'switch', - 'throw', - 'try', - 'yield', - 'yield_from', - ], - ], - 'compact_nullable_type_declaration' => true, - 'heredoc_indentation' => [ - 'indentation' => 'same_as_start', - ], - 'indentation_type' => true, - 'line_ending' => true, - 'method_chaining_indentation' => true, - 'no_extra_blank_lines' => [ - 'tokens' => [ - 'attribute', - 'break', - 'case', - 'continue', - 'curly_brace_block', - 'default', - 'extra', - 'parenthesis_brace_block', - 'return', - 'square_brace_block', - 'switch', - 'throw', - 'use', - ], - ], - 'no_spaces_around_offset' => [ - 'positions' => [ - 'inside', - 'outside', - ], - ], - 'no_trailing_whitespace' => true, - 'no_whitespace_in_blank_line' => true, - 'single_blank_line_at_eof' => true, - 'statement_indentation' => [ - 'stick_comment_to_next_continuous_control_statement' => true, - ], - 'type_declaration_spaces' => [ - 'elements' => [ - 'function', - 'property', - ], - ], - 'types_spaces' => [ - 'space' => 'none', - ], -];