diff --git a/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php index 4273777..99bfaf0 100644 --- a/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php @@ -13,9 +13,7 @@ class DisableMagicSerializeSniff implements Sniff { /** @var list */ public array $disabledFunctions = [ - '__serialize', '__sleep', - '__unserialize', '__wakeup', ]; @@ -45,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr): void if (in_array($name, $this->disabledFunctions, true)) { $phpcsFile->addError( sprintf( - 'The method "%s" is forbidden, please use Serializable interface.', + 'The method "%s" is deprecated, please use __serialize and __unserialize instead.', $name ), $stackPtr, diff --git a/Inpsyde/Sniffs/CodeQuality/DisableSerializeInterfaceSniff.php b/Inpsyde/Sniffs/CodeQuality/DisableSerializeInterfaceSniff.php new file mode 100644 index 0000000..7784eed --- /dev/null +++ b/Inpsyde/Sniffs/CodeQuality/DisableSerializeInterfaceSniff.php @@ -0,0 +1,51 @@ + + */ + public function register(): array + { + return [ + \T_CLASS, + \T_ANON_CLASS, + \T_ENUM, + \T_INTERFACE, + ]; + } + + /** + * @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 + $tokenCode = $phpcsFile->getTokens()[$stackPtr]['code']; + $find = ($tokenCode === \T_INTERFACE) + ? ObjectDeclarations::findExtendedInterfaceNames($phpcsFile, $stackPtr) + : ObjectDeclarations::findImplementedInterfaceNames($phpcsFile, $stackPtr); + + if (($find === false) || !in_array('Serializable', $find, true)) { + return; + } + + $phpcsFile->addError( + 'The Serializable interface is deprecated, please use __serialize and __unserialize instead.', + $stackPtr, + 'Found' + ); + } +}