From f9dd6ae41dbeb9164f0f005b15fe675894f2769f Mon Sep 17 00:00:00 2001 From: nikita tarasov Date: Thu, 30 Dec 2021 17:05:40 +0300 Subject: [PATCH 01/12] update dependencies --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index dc59adb..66cd676 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ ], "require": { "squizlabs/php_codesniffer": "3.*", - "friendsofphp/php-cs-fixer": "^2.16.0", - "phpmd/phpmd": "^2.8.1", - "magento/magento-coding-standard": "5", + "friendsofphp/php-cs-fixer": "~3.4.0", + "phpmd/phpmd": "^2.9.1", + "magento/magento-coding-standard": "16", "php-parallel-lint/php-parallel-lint": "^1.0.0", - "phpro/grumphp": "~1.3.0", - "phpstan/phpstan": ">=0.12.3 <=0.12.23" + "phpro/grumphp": "~1.5.0", + "phpstan/phpstan": "~1.2.0" }, "autoload": { "psr-4": { From ad80b9639c5e33681849b80e7e40bc2ce37ce5c5 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Tue, 8 Mar 2022 19:39:25 +0300 Subject: [PATCH 02/12] Update to magento/magento-coding-standard 19 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 66cd676..865d3bc 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "squizlabs/php_codesniffer": "3.*", "friendsofphp/php-cs-fixer": "~3.4.0", "phpmd/phpmd": "^2.9.1", - "magento/magento-coding-standard": "16", + "magento/magento-coding-standard": "19", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", "phpstan/phpstan": "~1.2.0" From 393cf6ab7afbc390cca355c4b291c3f9e68ba0fe Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Tue, 8 Mar 2022 19:57:34 +0300 Subject: [PATCH 03/12] Setup compatibility with magento project --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 865d3bc..7db7f3c 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "squizlabs/php_codesniffer": "3.*", "friendsofphp/php-cs-fixer": "~3.4.0", "phpmd/phpmd": "^2.9.1", - "magento/magento-coding-standard": "19", + "magento/magento-coding-standard": "v2.4-magento-compatibitity-dev", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", "phpstan/phpstan": "~1.2.0" @@ -26,5 +26,11 @@ "Mygento\\CS\\Config\\": "config", "Mygento\\CS\\Stan\\": "stan" } + }, + "repositories": { + "magento-coding-standard": { + "type": "git", + "url": "https://github.com/Daseraf/magento-coding-standard.git" + } } } From 444efb9d2197e017e52ba227a73c3442328fe3df Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Tue, 8 Mar 2022 20:13:01 +0300 Subject: [PATCH 04/12] Setup compatibility with magento project --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7db7f3c..9febeec 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "squizlabs/php_codesniffer": "3.*", "friendsofphp/php-cs-fixer": "~3.4.0", "phpmd/phpmd": "^2.9.1", - "magento/magento-coding-standard": "v2.4-magento-compatibitity-dev", + "magento/magento-coding-standard": "v19-project-compatibility", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", "phpstan/phpstan": "~1.2.0" From 6caafef0f59610b00b49ab0b0fba23d351e83459 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Tue, 8 Mar 2022 20:24:02 +0300 Subject: [PATCH 05/12] Setup compatibility with magento project --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9febeec..e73306b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "squizlabs/php_codesniffer": "3.*", "friendsofphp/php-cs-fixer": "~3.4.0", "phpmd/phpmd": "^2.9.1", - "magento/magento-coding-standard": "v19-project-compatibility", + "magento/magento-coding-standard": "dev-v2.4-magento-compatibitity", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", "phpstan/phpstan": "~1.2.0" @@ -28,7 +28,7 @@ } }, "repositories": { - "magento-coding-standard": { + "magento/magento-coding-standard": { "type": "git", "url": "https://github.com/Daseraf/magento-coding-standard.git" } From f2d2664da83e92bbbb599427e8f3759dc4320d96 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Wed, 9 Mar 2022 11:41:40 +0300 Subject: [PATCH 06/12] Update CS-fixer configuration --- config/Base.php | 166 +++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 85 deletions(-) diff --git a/config/Base.php b/config/Base.php index 0e6eb04..721acd0 100644 --- a/config/Base.php +++ b/config/Base.php @@ -2,6 +2,8 @@ namespace Mygento\CS\Config; +use PhpCsFixer\ConfigInterface; + class Base extends \PhpCsFixer\Config { /** @@ -27,7 +29,7 @@ public function __construct($header = null, array $customRules = []) /** * {@inheritdoc} */ - public function setFinder($finder) + public function setFinder(iterable $finder): ConfigInterface { $finder->exclude('dev/tests/functional/generated') ->exclude('dev/tests/functional/var') @@ -42,92 +44,86 @@ public function setFinder($finder) ->exclude('pub/static') ->exclude('setup/vendor') ->exclude('var'); - parent::setFinder($finder); + + return parent::setFinder($finder); } - public function getRules() - { - $rules = [ - '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], - 'concat_space' => ['spacing' => 'one'], - 'include' => true, - 'new_with_braces' => true, - 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => true, - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_unused_imports' => true, - 'no_whitespace_in_blank_line' => true, - 'object_operator_without_whitespace' => true, - 'ordered_imports' => true, - 'standardize_not_equals' => true, - 'ternary_operator_spaces' => true, - // mygento - 'phpdoc_order' => true, - 'phpdoc_types' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'single_quote' => true, - 'standardize_not_equals' => true, - 'ternary_to_null_coalescing' => true, - 'lowercase_cast' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'return_type_declaration' => true, - 'no_useless_return' => true, - // mygento 2 - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'binary_operator_spaces' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => ['statements' => ["return", "throw", "try"]], - 'cast_spaces' => true, - 'class_attributes_separation' => ['elements' => ['method', 'property']], - 'explicit_indirect_variable' => true, - 'explicit_string_variable' => true, - 'function_typehint_space' => true, - 'lowercase_cast' => true, - 'lowercase_static_reference' => true, - 'method_chaining_indentation' => true, - 'multiline_comment_opening_closing' => true, - 'native_function_casing' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_extra_blank_lines' => [ - 'tokens' => ["break", "continue", "curly_brace_block", "extra", "parenthesis_brace_block", "return", "square_brace_block", "throw", "use"] - ], - 'no_short_bool_cast' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - 'no_superfluous_elseif' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_useless_else' => true, - 'no_whitespace_in_blank_line' => true, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => [ - 'order' => ["use_trait", "constant_public", "constant_protected", "constant_private", "property_public", "property_protected", "property_private", "construct", "destruct", "magic", "phpunit", "method_public", "method_protected", "method_private"] - ], - 'phpdoc_align' => ['align' => 'left'], - 'phpdoc_indent' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_trim' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last' - ], - //'phpdoc_var_without_name' => false, - 'return_assignment' => true, - //'single_line_comment_style' => false, - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true, - ]; + /** + * {@inheritdoc} + */ + public function getRules(): array + {$rules = [ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'include' => true, + 'new_with_braces' => true, + 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'multiline_whitespace_before_semicolons' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + // mygento + 'phpdoc_order' => true, + 'phpdoc_types' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'single_quote' => true, + 'ternary_to_null_coalescing' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'return_type_declaration' => true, + 'no_useless_return' => true, + 'align_multiline_comment' => true, + 'array_indentation' => true, + 'binary_operator_spaces' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => ['statements' => ["return", "throw", "try"]], + 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none']], + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'function_typehint_space' => true, + 'lowercase_cast' => true, + 'lowercase_static_reference' => true, + 'method_chaining_indentation' => true, + 'multiline_comment_opening_closing' => true, + 'native_function_casing' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_extra_blank_lines' => [ + 'tokens' => ["break", "continue", "curly_brace_block", "extra", "parenthesis_brace_block", "return", "square_brace_block", "throw", "use"] + ], + 'no_short_bool_cast' => true, + 'no_spaces_around_offset' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_useless_else' => true, + 'ordered_class_elements' => [ + 'order' => ["use_trait", "constant_public", "constant_protected", "constant_private", "property_public", "property_protected", "property_private", "construct", "destruct", "magic", "phpunit", "method_public", "method_protected", "method_private"] + ], + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_indent' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_trim' => true, + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last' + ], + 'return_assignment' => true, + 'trailing_comma_in_multiline' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, + ]; if (null !== $this->header) { $rules['header_comment'] = [ From 93ad8c83fc55536aff43d5554f70a2e7f97801f6 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Thu, 10 Mar 2022 15:18:29 +0300 Subject: [PATCH 07/12] Update CS-fixer configuration --- config/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/Base.php b/config/Base.php index 721acd0..4f48808 100644 --- a/config/Base.php +++ b/config/Base.php @@ -87,7 +87,7 @@ public function getRules(): array 'blank_line_after_opening_tag' => true, 'blank_line_before_statement' => ['statements' => ["return", "throw", "try"]], 'cast_spaces' => true, - 'class_attributes_separation' => ['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none']], + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one', 'trait_import' => 'none']], 'explicit_indirect_variable' => true, 'explicit_string_variable' => true, 'function_typehint_space' => true, From ed4c15523ff48886e8d61f21bfcd1eaf6200946a Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Thu, 10 Mar 2022 22:12:24 +0300 Subject: [PATCH 08/12] Add bitexpert/phpstan-magento --- composer.json | 3 +- stan/DataObject.php | 17 ----- stan/MagicMethod.php | 105 ------------------------------ stan/MethodReflections.php | 130 ------------------------------------- stan/autoload.php | 31 --------- stan/extension.neon | 4 -- 6 files changed, 2 insertions(+), 288 deletions(-) delete mode 100644 stan/DataObject.php delete mode 100644 stan/MagicMethod.php delete mode 100644 stan/MethodReflections.php delete mode 100644 stan/autoload.php delete mode 100644 stan/extension.neon diff --git a/composer.json b/composer.json index e73306b..f204a0c 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "magento/magento-coding-standard": "dev-v2.4-magento-compatibitity", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", - "phpstan/phpstan": "~1.2.0" + "phpstan/phpstan": "~1.4.0", + "bitexpert/phpstan-magento": "^0.17.0" }, "autoload": { "psr-4": { diff --git a/stan/DataObject.php b/stan/DataObject.php deleted file mode 100644 index ba44689..0000000 --- a/stan/DataObject.php +++ /dev/null @@ -1,17 +0,0 @@ -getParentClassesNames(); - $parentClasses[] = $classReflection->getName(); - - return in_array(\Magento\Framework\DataObject::class, $parentClasses, true) && - in_array(substr($methodName, 0, 3), ['get', 'set', 'uns', 'has']); - } -} diff --git a/stan/MagicMethod.php b/stan/MagicMethod.php deleted file mode 100644 index d02c492..0000000 --- a/stan/MagicMethod.php +++ /dev/null @@ -1,105 +0,0 @@ -name = $name; - $this->declaringClass = $declaringClass; - $this->variants = $variants; - } - - public function getDeclaringClass(): ClassReflection - { - return $this->declaringClass; - } - - public function isStatic(): bool - { - return false; - } - - public function isPrivate(): bool - { - return false; - } - - public function isPublic(): bool - { - return true; - } - - public function getName(): string - { - return $this->name; - } - - public function getPrototype(): ClassMemberReflection - { - return $this; - } - - public function getVariants(): array - { - return $this->variants; - } - - public function getDocComment(): ?string - { - return null; - } - - public function isDeprecated(): \PHPStan\TrinaryLogic - { - return \PHPStan\TrinaryLogic::createNo(); - } - - public function getDeprecatedDescription(): ?string - { - return ''; - } - - public function isFinal(): \PHPStan\TrinaryLogic - { - return \PHPStan\TrinaryLogic::createNo(); - } - - public function isInternal(): \PHPStan\TrinaryLogic - { - return \PHPStan\TrinaryLogic::createNo(); - } - - public function getThrowType(): ?\PHPStan\Type\Type - { - return null; - } - - public function hasSideEffects(): \PHPStan\TrinaryLogic - { - if (in_array(substr($this->name, 0, 3), ['set', 'uns'])) { - return \PHPStan\TrinaryLogic::createYes(); - } - - return \PHPStan\TrinaryLogic::createNo(); - } -} diff --git a/stan/MethodReflections.php b/stan/MethodReflections.php deleted file mode 100644 index 723cdac..0000000 --- a/stan/MethodReflections.php +++ /dev/null @@ -1,130 +0,0 @@ -returnGetMagicMethod($classReflection, $methodName); - case 'set': - return $this->returnSetMagicMethod($classReflection, $methodName); - case 'uns': - return $this->returnUnsetMagicMethod($classReflection, $methodName); - case 'has': - return $this->returnHasMagicMethod($classReflection, $methodName); - default: - throw new \PHPStan\ShouldNotHappenException(); - } - } - - private function returnMethod($methodName, $classReflection, $params, $returnType) - { - $variants = new FunctionVariant( - TemplateTypeMap::createEmpty(), - null, - $params, - false, - $returnType - ); - - return new MagicMethod($methodName, $classReflection, [$variants]); - } - - private function returnGetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection - { - $params = [ - new DummyParameter( - 'key', - new StringType(), - true, - null, - false, - null - ), - new DummyParameter( - 'index', - new UnionType([new StringType(), new IntegerType(), new NullType()]), - true, - null, - false, - null - ), - ]; - - return $this->returnMethod($methodName, $classReflection, $params, new MixedType()); - } - - private function returnSetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection - { - $params = [ - new DummyParameter( - 'key', - new UnionType([new StringType(), new ArrayType(new MixedType(), new MixedType())]), - true, - null, - false, - null - ), - new DummyParameter( - 'value', - new MixedType(), - true, - null, - false, - null - ), - ]; - - return $this->returnMethod($methodName, $classReflection, $params, new ObjectType($classReflection->getName())); - } - - private function returnUnsetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection - { - $params = [ - new DummyParameter( - 'key', - new UnionType([new NullType(), new StringType(), new ArrayType(new MixedType(), new MixedType())]), - true, - null, - false, - null - ), - ]; - - return $this->returnMethod($methodName, $classReflection, $params, new ObjectType($classReflection->getName())); - } - - private function returnHasMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection - { - $params = [ - new DummyParameter( - 'key', - new StringType(), - true, - null, - false, - null - ), - ]; - - return $this->returnMethod($methodName, $classReflection, $params, new BooleanType()); - } -} diff --git a/stan/autoload.php b/stan/autoload.php deleted file mode 100644 index 4e4df64..0000000 --- a/stan/autoload.php +++ /dev/null @@ -1,31 +0,0 @@ - Date: Fri, 11 Mar 2022 11:13:55 +0300 Subject: [PATCH 09/12] Restore Mygento Stan reflection --- stan/DataObject.php | 17 +++++ stan/MagicMethod.php | 105 ++++++++++++++++++++++++++++++ stan/MethodReflections.php | 130 +++++++++++++++++++++++++++++++++++++ stan/autoload.php | 31 +++++++++ stan/extension.neon | 4 ++ 5 files changed, 287 insertions(+) create mode 100644 stan/DataObject.php create mode 100644 stan/MagicMethod.php create mode 100644 stan/MethodReflections.php create mode 100644 stan/autoload.php create mode 100644 stan/extension.neon diff --git a/stan/DataObject.php b/stan/DataObject.php new file mode 100644 index 0000000..ba44689 --- /dev/null +++ b/stan/DataObject.php @@ -0,0 +1,17 @@ +getParentClassesNames(); + $parentClasses[] = $classReflection->getName(); + + return in_array(\Magento\Framework\DataObject::class, $parentClasses, true) && + in_array(substr($methodName, 0, 3), ['get', 'set', 'uns', 'has']); + } +} diff --git a/stan/MagicMethod.php b/stan/MagicMethod.php new file mode 100644 index 0000000..d02c492 --- /dev/null +++ b/stan/MagicMethod.php @@ -0,0 +1,105 @@ +name = $name; + $this->declaringClass = $declaringClass; + $this->variants = $variants; + } + + public function getDeclaringClass(): ClassReflection + { + return $this->declaringClass; + } + + public function isStatic(): bool + { + return false; + } + + public function isPrivate(): bool + { + return false; + } + + public function isPublic(): bool + { + return true; + } + + public function getName(): string + { + return $this->name; + } + + public function getPrototype(): ClassMemberReflection + { + return $this; + } + + public function getVariants(): array + { + return $this->variants; + } + + public function getDocComment(): ?string + { + return null; + } + + public function isDeprecated(): \PHPStan\TrinaryLogic + { + return \PHPStan\TrinaryLogic::createNo(); + } + + public function getDeprecatedDescription(): ?string + { + return ''; + } + + public function isFinal(): \PHPStan\TrinaryLogic + { + return \PHPStan\TrinaryLogic::createNo(); + } + + public function isInternal(): \PHPStan\TrinaryLogic + { + return \PHPStan\TrinaryLogic::createNo(); + } + + public function getThrowType(): ?\PHPStan\Type\Type + { + return null; + } + + public function hasSideEffects(): \PHPStan\TrinaryLogic + { + if (in_array(substr($this->name, 0, 3), ['set', 'uns'])) { + return \PHPStan\TrinaryLogic::createYes(); + } + + return \PHPStan\TrinaryLogic::createNo(); + } +} diff --git a/stan/MethodReflections.php b/stan/MethodReflections.php new file mode 100644 index 0000000..723cdac --- /dev/null +++ b/stan/MethodReflections.php @@ -0,0 +1,130 @@ +returnGetMagicMethod($classReflection, $methodName); + case 'set': + return $this->returnSetMagicMethod($classReflection, $methodName); + case 'uns': + return $this->returnUnsetMagicMethod($classReflection, $methodName); + case 'has': + return $this->returnHasMagicMethod($classReflection, $methodName); + default: + throw new \PHPStan\ShouldNotHappenException(); + } + } + + private function returnMethod($methodName, $classReflection, $params, $returnType) + { + $variants = new FunctionVariant( + TemplateTypeMap::createEmpty(), + null, + $params, + false, + $returnType + ); + + return new MagicMethod($methodName, $classReflection, [$variants]); + } + + private function returnGetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection + { + $params = [ + new DummyParameter( + 'key', + new StringType(), + true, + null, + false, + null + ), + new DummyParameter( + 'index', + new UnionType([new StringType(), new IntegerType(), new NullType()]), + true, + null, + false, + null + ), + ]; + + return $this->returnMethod($methodName, $classReflection, $params, new MixedType()); + } + + private function returnSetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection + { + $params = [ + new DummyParameter( + 'key', + new UnionType([new StringType(), new ArrayType(new MixedType(), new MixedType())]), + true, + null, + false, + null + ), + new DummyParameter( + 'value', + new MixedType(), + true, + null, + false, + null + ), + ]; + + return $this->returnMethod($methodName, $classReflection, $params, new ObjectType($classReflection->getName())); + } + + private function returnUnsetMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection + { + $params = [ + new DummyParameter( + 'key', + new UnionType([new NullType(), new StringType(), new ArrayType(new MixedType(), new MixedType())]), + true, + null, + false, + null + ), + ]; + + return $this->returnMethod($methodName, $classReflection, $params, new ObjectType($classReflection->getName())); + } + + private function returnHasMagicMethod(ClassReflection $classReflection, string $methodName): MethodReflection + { + $params = [ + new DummyParameter( + 'key', + new StringType(), + true, + null, + false, + null + ), + ]; + + return $this->returnMethod($methodName, $classReflection, $params, new BooleanType()); + } +} diff --git a/stan/autoload.php b/stan/autoload.php new file mode 100644 index 0000000..4e4df64 --- /dev/null +++ b/stan/autoload.php @@ -0,0 +1,31 @@ + Date: Fri, 11 Mar 2022 11:44:45 +0300 Subject: [PATCH 10/12] Restore Mygento Stan reflection --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f204a0c..e73306b 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ "magento/magento-coding-standard": "dev-v2.4-magento-compatibitity", "php-parallel-lint/php-parallel-lint": "^1.0.0", "phpro/grumphp": "~1.5.0", - "phpstan/phpstan": "~1.4.0", - "bitexpert/phpstan-magento": "^0.17.0" + "phpstan/phpstan": "~1.2.0" }, "autoload": { "psr-4": { From 8f1cd739f4d1ab6a06cf16afaecf6b068baadce7 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Fri, 11 Mar 2022 12:33:30 +0300 Subject: [PATCH 11/12] Add autoload.php for extension.neon --- stan/extension.neon | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stan/extension.neon b/stan/extension.neon index c3351c8..0bb3e33 100644 --- a/stan/extension.neon +++ b/stan/extension.neon @@ -1,4 +1,7 @@ +parameters: + bootstrapFiles: + - autoload.php services: - class: Mygento\CS\Stan\DataObject tags: - - phpstan.broker.methodsClassReflectionExtension + - phpstan.broker.methodsClassReflectionExtension \ No newline at end of file From a8d782d0325e9de16b3368437c97359a455a9676 Mon Sep 17 00:00:00 2001 From: Stanislav Matyavin Date: Mon, 14 Mar 2022 13:31:12 +0300 Subject: [PATCH 12/12] Fix CS Fixer rules list --- config/Base.php | 145 ++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/config/Base.php b/config/Base.php index 4f48808..8afcccc 100644 --- a/config/Base.php +++ b/config/Base.php @@ -52,78 +52,79 @@ public function setFinder(iterable $finder): ConfigInterface * {@inheritdoc} */ public function getRules(): array - {$rules = [ - '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], - 'concat_space' => ['spacing' => 'one'], - 'include' => true, - 'new_with_braces' => true, - 'no_empty_statement' => true, - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'multiline_whitespace_before_semicolons' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_unused_imports' => true, - 'no_whitespace_in_blank_line' => true, - 'object_operator_without_whitespace' => true, - 'ordered_imports' => true, - 'standardize_not_equals' => true, - 'ternary_operator_spaces' => true, - // mygento - 'phpdoc_order' => true, - 'phpdoc_types' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'single_quote' => true, - 'ternary_to_null_coalescing' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'return_type_declaration' => true, - 'no_useless_return' => true, - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'binary_operator_spaces' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => ['statements' => ["return", "throw", "try"]], - 'cast_spaces' => true, - 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one', 'trait_import' => 'none']], - 'explicit_indirect_variable' => true, - 'explicit_string_variable' => true, - 'function_typehint_space' => true, - 'lowercase_cast' => true, - 'lowercase_static_reference' => true, - 'method_chaining_indentation' => true, - 'multiline_comment_opening_closing' => true, - 'native_function_casing' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_extra_blank_lines' => [ - 'tokens' => ["break", "continue", "curly_brace_block", "extra", "parenthesis_brace_block", "return", "square_brace_block", "throw", "use"] - ], - 'no_short_bool_cast' => true, - 'no_spaces_around_offset' => true, - 'no_superfluous_elseif' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_useless_else' => true, - 'ordered_class_elements' => [ - 'order' => ["use_trait", "constant_public", "constant_protected", "constant_private", "property_public", "property_protected", "property_private", "construct", "destruct", "magic", "phpunit", "method_public", "method_protected", "method_private"] - ], - 'phpdoc_align' => ['align' => 'left'], - 'phpdoc_indent' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_trim' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last' - ], - 'return_assignment' => true, - 'trailing_comma_in_multiline' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true, - ]; + { + $rules = [ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'include' => true, + 'new_with_braces' => true, + 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'multiline_whitespace_before_semicolons' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + // mygento + 'phpdoc_order' => true, + 'phpdoc_types' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'single_quote' => true, + 'ternary_to_null_coalescing' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'return_type_declaration' => true, + 'no_useless_return' => true, + 'align_multiline_comment' => true, + 'array_indentation' => true, + 'binary_operator_spaces' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => ['statements' => ["return", "throw", "try"]], + 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one', 'trait_import' => 'none']], + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'function_typehint_space' => true, + 'lowercase_cast' => true, + 'lowercase_static_reference' => true, + 'method_chaining_indentation' => true, + 'multiline_comment_opening_closing' => true, + 'native_function_casing' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_extra_blank_lines' => [ + 'tokens' => ["break", "continue", "curly_brace_block", "extra", "parenthesis_brace_block", "return", "square_brace_block", "throw", "use"] + ], + 'no_short_bool_cast' => true, + 'no_spaces_around_offset' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_useless_else' => true, + 'ordered_class_elements' => [ + 'order' => ["use_trait", "constant_public", "constant_protected", "constant_private", "property_public", "property_protected", "property_private", "construct", "destruct", "magic", "phpunit", "method_public", "method_protected", "method_private"] + ], + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_indent' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_trim' => true, + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last' + ], + 'return_assignment' => true, + 'trailing_comma_in_multiline' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, + ]; if (null !== $this->header) { $rules['header_comment'] = [