diff --git a/dependabot.yml b/.github/dependabot.yml similarity index 100% rename from dependabot.yml rename to .github/dependabot.yml diff --git a/.github/workflows/quality-assurance-php.yml b/.github/workflows/quality-assurance-php.yml index cee505f..d5dfc5e 100644 --- a/.github/workflows/quality-assurance-php.yml +++ b/.github/workflows/quality-assurance-php.yml @@ -8,6 +8,7 @@ on: - '**phpcs.xml.dist' - '**phpunit.xml.dist' - '**psalm.xml' + - '**ruleset.xml' workflow_dispatch: inputs: jobs: diff --git a/.psalm/autoloader.php b/.psalm/autoloader.php deleted file mode 100644 index 86ace84..0000000 --- a/.psalm/autoloader.php +++ /dev/null @@ -1,14 +0,0 @@ -> + * + * phpcs:disable Inpsyde.CodeQuality.NoAccessors + */ + public function getGroups(): array + { + // phpcs:enable Inpsyde.CodeQuality.NoAccessors + return [ + 'call_user_func' => [ + 'type' => 'error', + 'message' => 'Usage of %s() is forbidden.', + 'functions' => [ + 'call_user_func', + 'call_user_func_array', + ], + ], + ]; + } +} diff --git a/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php new file mode 100644 index 0000000..2d8180a --- /dev/null +++ b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php @@ -0,0 +1,74 @@ + */ + public array $disabledFunctions = [ + '__serialize', + '__sleep', + '__unserialize', + '__wakeup', + ]; + + /** + * @return list + */ + public function register(): array + { + return [T_FUNCTION]; + } + + /** + * @param File $phpcsFile + * @param int $stackPtr + * @return void + * + * phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration + */ + public function process(File $phpcsFile, $stackPtr) + { + // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration + if (!Scopes::isOOMethod($phpcsFile, $stackPtr)) { + return; + } + + $name = FunctionDeclarations::getName($phpcsFile, $stackPtr); + if (in_array($name, $this->disabledFunctions, true)) { + $phpcsFile->addError( + sprintf( + 'The method "%s" is forbidden, please use Serializable interface.', + $name + ), + $stackPtr, + 'Found' + ); + } + } +} diff --git a/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php b/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php new file mode 100644 index 0000000..3c8ad58 --- /dev/null +++ b/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php @@ -0,0 +1,71 @@ + + */ + public function register(): array + { + return [T_FUNCTION]; + } + + /** + * @param File $phpcsFile + * @param int $stackPtr + * @return void + * + * phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration + */ + public function process(File $phpcsFile, $stackPtr): void + { + // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration + if (Scopes::isOOMethod($phpcsFile, $stackPtr)) { + return; + } + + $namespace = Namespaces::determineNamespace($phpcsFile, $stackPtr); + if ($namespace !== '') { + return; + } + $name = FunctionDeclarations::getName($phpcsFile, $stackPtr); + if (!$name) { + return; + } + + $message = sprintf('The function "%s" is in root namespace.', $name); + + $phpcsFile->addError($message, $stackPtr, 'Found'); + } +} diff --git a/Inpsyde/ruleset.xml b/Inpsyde/ruleset.xml index c70db7a..d51b281 100644 --- a/Inpsyde/ruleset.xml +++ b/Inpsyde/ruleset.xml @@ -1,5 +1,5 @@ - + PHP 7+ coding standards for Inpsyde WordPress projects. @@ -13,45 +13,22 @@ - - - warning - - - warning - - - warning - - - warning - - - warning - - - warning - - - warning - - - - - + + + + + + @@ -81,7 +58,6 @@ - @@ -131,10 +107,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -144,6 +148,13 @@ + + + + + + + @@ -156,6 +167,13 @@ + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/psalm.xml b/psalm.xml index 53e46c1..7399676 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@