diff --git a/composer.json b/composer.json index a50c8a44..182fd593 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "GPL-3.0-or-later", "require": { "php": ">=7.4", - "moodlehq/moodle-cs": "^v3.4.8", + "moodlehq/moodle-cs": "^v3.4.10", "phpcompatibility/php-compatibility": "dev-develop#96072c30" }, "config": { diff --git a/composer.lock b/composer.lock index 166057fc..9168f0a5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bd0a96a20590db32325fc04f2993298a", + "content-hash": "f911c1a21380142d6ee33490dc0eee6a", "packages": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -86,16 +86,16 @@ }, { "name": "moodlehq/moodle-cs", - "version": "v3.4.8", + "version": "v3.4.10", "source": { "type": "git", "url": "https://github.com/moodlehq/moodle-cs.git", - "reference": "91661a17a23ed17e7ae4276f8c19df789b8882c2" + "reference": "89ff0acd727f8611cbafe5aea524614090b24ad9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/moodlehq/moodle-cs/zipball/91661a17a23ed17e7ae4276f8c19df789b8882c2", - "reference": "91661a17a23ed17e7ae4276f8c19df789b8882c2", + "url": "https://api.github.com/repos/moodlehq/moodle-cs/zipball/89ff0acd727f8611cbafe5aea524614090b24ad9", + "reference": "89ff0acd727f8611cbafe5aea524614090b24ad9", "shasum": "" }, "require": { @@ -152,7 +152,7 @@ "source": "https://github.com/moodlehq/moodle-cs", "wiki": "https://github.com/moodlehq/moodle-cs/wiki" }, - "time": "2024-06-14T14:47:25+00:00" + "time": "2024-07-04T16:34:56+00:00" }, { "name": "phpcompatibility/php-compatibility", diff --git a/vendor/autoload.php b/vendor/autoload.php index 39f3cf97..c27f5fcd 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitbd0a96a20590db32325fc04f2993298a::getLoader(); +return ComposerAutoloaderInitf911c1a21380142d6ee33490dc0eee6a::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index d43dec46..1e61f460 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitbd0a96a20590db32325fc04f2993298a +class ComposerAutoloaderInitf911c1a21380142d6ee33490dc0eee6a { private static $loader; @@ -24,12 +24,12 @@ public static function getLoader() require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitbd0a96a20590db32325fc04f2993298a', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitf911c1a21380142d6ee33490dc0eee6a', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitbd0a96a20590db32325fc04f2993298a', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitf911c1a21380142d6ee33490dc0eee6a', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitbd0a96a20590db32325fc04f2993298a::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitf911c1a21380142d6ee33490dc0eee6a::getInitializer($loader)); $loader->register(true); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 7e9c208f..0b11a09d 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitbd0a96a20590db32325fc04f2993298a +class ComposerStaticInitf911c1a21380142d6ee33490dc0eee6a { public static $prefixLengthsPsr4 = array ( 'P' => @@ -72,9 +72,9 @@ class ComposerStaticInitbd0a96a20590db32325fc04f2993298a public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitbd0a96a20590db32325fc04f2993298a::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitbd0a96a20590db32325fc04f2993298a::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitbd0a96a20590db32325fc04f2993298a::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitf911c1a21380142d6ee33490dc0eee6a::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitf911c1a21380142d6ee33490dc0eee6a::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitf911c1a21380142d6ee33490dc0eee6a::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 23987323..23fa4f31 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -83,17 +83,17 @@ }, { "name": "moodlehq/moodle-cs", - "version": "v3.4.8", - "version_normalized": "3.4.8.0", + "version": "v3.4.10", + "version_normalized": "3.4.10.0", "source": { "type": "git", "url": "https://github.com/moodlehq/moodle-cs.git", - "reference": "91661a17a23ed17e7ae4276f8c19df789b8882c2" + "reference": "89ff0acd727f8611cbafe5aea524614090b24ad9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/moodlehq/moodle-cs/zipball/91661a17a23ed17e7ae4276f8c19df789b8882c2", - "reference": "91661a17a23ed17e7ae4276f8c19df789b8882c2", + "url": "https://api.github.com/repos/moodlehq/moodle-cs/zipball/89ff0acd727f8611cbafe5aea524614090b24ad9", + "reference": "89ff0acd727f8611cbafe5aea524614090b24ad9", "shasum": "" }, "require": { @@ -116,7 +116,7 @@ "sebastian/phpcpd": "^6.0", "thor-juhasz/phpunit-coverage-check": "^0.3.0" }, - "time": "2024-06-14T14:47:25+00:00", + "time": "2024-07-04T16:34:56+00:00", "type": "phpcodesniffer-standard", "installation-source": "dist", "autoload": { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index bc24b234..4e224225 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'moodlehq/local_codechecker', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '3ec6941b73874fb0bc33ded196e8a5c6fe80be6f', + 'reference' => 'b49b9077544290509a775bff341b74ec26e75c8c', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -22,16 +22,16 @@ 'moodlehq/local_codechecker' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '3ec6941b73874fb0bc33ded196e8a5c6fe80be6f', + 'reference' => 'b49b9077544290509a775bff341b74ec26e75c8c', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => false, ), 'moodlehq/moodle-cs' => array( - 'pretty_version' => 'v3.4.8', - 'version' => '3.4.8.0', - 'reference' => '91661a17a23ed17e7ae4276f8c19df789b8882c2', + 'pretty_version' => 'v3.4.10', + 'version' => '3.4.10.0', + 'reference' => '89ff0acd727f8611cbafe5aea524614090b24ad9', 'type' => 'phpcodesniffer-standard', 'install_path' => __DIR__ . '/../moodlehq/moodle-cs', 'aliases' => array(), diff --git a/vendor/moodlehq/moodle-cs/moodle/Sniffs/Commenting/MissingDocblockSniff.php b/vendor/moodlehq/moodle-cs/moodle/Sniffs/Commenting/MissingDocblockSniff.php index 82bc55f6..e2903ce1 100644 --- a/vendor/moodlehq/moodle-cs/moodle/Sniffs/Commenting/MissingDocblockSniff.php +++ b/vendor/moodlehq/moodle-cs/moodle/Sniffs/Commenting/MissingDocblockSniff.php @@ -83,6 +83,11 @@ protected function processScopes(File $phpcsFile, int $stackPtr): void { // Skip methods of classes, traits and interfaces. continue; } + if ($token['code'] === T_ANON_CLASS && !empty($token['conditions'])) { + // Skip anonymous classes. + continue; + } + $artifactCount++; if ($token['code'] === T_FUNCTION) { diff --git a/vendor/moodlehq/moodle-cs/moodle/Sniffs/Files/BoilerplateCommentSniff.php b/vendor/moodlehq/moodle-cs/moodle/Sniffs/Files/BoilerplateCommentSniff.php index eb5f9870..22d2754e 100644 --- a/vendor/moodlehq/moodle-cs/moodle/Sniffs/Files/BoilerplateCommentSniff.php +++ b/vendor/moodlehq/moodle-cs/moodle/Sniffs/Files/BoilerplateCommentSniff.php @@ -166,7 +166,22 @@ public function process(File $phpcsFile, $stackPtr): void return; } - $tokenptr++; + // Let's jump over all the extra (allowed) consecutive comments to find the first non-comment token. + $lastComment = $tokenptr; + $nextComment = $tokenptr; + while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) { + // Only \n is allowed as spacing since the previous comment line. + if (strpos($tokens[$nextComment - 1]['content'], "\n") === false) { + // Stop looking for consecutive comments, some spacing broke the sequence. + break; + } + if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) { + // Stop looking for comments, the lines are not consecutive. + break; + } + $lastComment = $nextComment; + } + $tokenptr = $lastComment + 1; // Move to the last found comment + 1. $nextnonwhitespace = $phpcsFile->findNext(T_WHITESPACE, $tokenptr, null, true); @@ -218,8 +233,16 @@ private function fullComment(): array private function insertBoilerplate(File $file, int $stackptr): void { - $prefix = substr($file->getTokens()[$stackptr]['content'], -1) === "\n" ? '' : "\n"; - $file->fixer->addContent($stackptr, $prefix . implode("\n", $this->fullComment()) . "\n"); + $token = $file->getTokens()[$stackptr]; + $paddedComment = implode("\n", $this->fullComment()) . "\n"; + + if ($token['code'] === T_OPEN_TAG) { + $replacement = trim($token['content']) . "\n" . $paddedComment; + $file->fixer->replaceToken($stackptr, $replacement); + } else { + $prefix = substr($token['content'], -1) === "\n" ? '' : "\n"; + $file->fixer->addContent($stackptr, $prefix . $paddedComment); + } } private function moveBoilerplate(File $file, int $start, int $target): void @@ -265,6 +288,11 @@ private function completeBoilerplate(File $file, $stackptr, int $lineindex): voi */ private function regexForLine(string $line): string { + // We need to match the blank lines in their entirety. + if ($line === '//') { + return '/^\/\/$/'; + } + return str_replace( ['Moodle', 'https\\:'], ['.*', 'https?\\:'], diff --git a/vendor/moodlehq/moodle-cs/moodle/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/vendor/moodlehq/moodle-cs/moodle/Sniffs/NamingConventions/ValidFunctionNameSniff.php index a0b58f7a..9c1350b6 100644 --- a/vendor/moodlehq/moodle-cs/moodle/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/vendor/moodlehq/moodle-cs/moodle/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -27,6 +27,7 @@ namespace MoodleHQ\MoodleCS\moodle\Sniffs\NamingConventions; +use MoodleHQ\MoodleCS\moodle\Util\Attributes; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Util\Tokens; @@ -108,6 +109,11 @@ protected function processTokenWithinScope(File $phpcsfile, $stackptr, $currscop $scope = $methodprops['scope']; $scopespecified = $methodprops['scope_specified']; + if (Attributes::hasOverrideAttribute($phpcsfile, $stackptr)) { + // This method has an `#[\Override]` attribute, so it is allowed to have a different name. + return; + } + // Only lower-case accepted. if ( preg_match('/[A-Z]+/', $methodname) && diff --git a/vendor/moodlehq/moodle-cs/moodle/Util/Attributes.php b/vendor/moodlehq/moodle-cs/moodle/Util/Attributes.php index ef6ad71d..644aa3bf 100644 --- a/vendor/moodlehq/moodle-cs/moodle/Util/Attributes.php +++ b/vendor/moodlehq/moodle-cs/moodle/Util/Attributes.php @@ -20,6 +20,7 @@ use PHP_CodeSniffer\Files\File; use PHPCSUtils\Utils\Context; use PHPCSUtils\Utils\Namespaces; +use PHPCSUtils\Utils\ObjectDeclarations; /** * Utilities related to PHP Attributes. @@ -108,4 +109,65 @@ public static function getAttributeProperties( return $properties; } + + /** + * Check if a function has an \Override Attribute. + * + * Note: Override attributes can only be valid on methods of classes which extend or implement another class. + * + * @param File $phpcsFile + * @param int $stackPtr + * @return bool + */ + public static function hasOverrideAttribute( + File $phpcsFile, + int $stackPtr + ): bool { + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; + if ($token['code'] !== T_FUNCTION) { + // Not a function so can't have an Override Attribute. + return false; + } + + if (empty($token['conditions'])) { + // Not in a class or interface. + return false; + } + + $extendsOrImplements = false; + foreach ($token['conditions'] as $condition => $conditionCode) { + $extendsOrImplements = $extendsOrImplements || ObjectDeclarations::findExtendedClassName( + $phpcsFile, + $condition + ); + $extendsOrImplements = $extendsOrImplements || ObjectDeclarations::findImplementedInterfaceNames( + $phpcsFile, + $condition + ); + $extendsOrImplements = $extendsOrImplements || ObjectDeclarations::findExtendedInterfaceNames( + $phpcsFile, + $condition + ); + + if ($extendsOrImplements) { + break; + } + } + + if (!$extendsOrImplements) { + // The OVerride attrinbute can only apply to a class which has a parent. + return false; + } + + $attributes = self::getAttributePointers($phpcsFile, $stackPtr); + foreach ($attributes as $attributePtr) { + $attribute = self::getAttributeProperties($phpcsFile, $attributePtr); + if ($attribute['attribute_name'] === '\Override') { + return true; + } + } + + return false; + } } diff --git a/vendor/moodlehq/moodle-cs/moodle/Util/Docblocks.php b/vendor/moodlehq/moodle-cs/moodle/Util/Docblocks.php index 6b86cb7e..a67b5d20 100644 --- a/vendor/moodlehq/moodle-cs/moodle/Util/Docblocks.php +++ b/vendor/moodlehq/moodle-cs/moodle/Util/Docblocks.php @@ -256,6 +256,11 @@ protected static function getDocTagFromOpenTag( ]; while ($stackPtr = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true)) { + // If we have arrived to a stop token, and haven't found the file docblock yet, then there isn't one. + if (in_array($tokens[$stackPtr]['code'], $stopAtTypes)) { + return null; + } + if ($tokens[$stackPtr]['code'] === T_NAMESPACE || $tokens[$stackPtr]['code'] === T_USE) { $stackPtr = $phpcsFile->findNext(T_SEMICOLON, $stackPtr + 1); continue;