diff --git a/composer.json b/composer.json index 92d1996b..1b1d4f3f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "", "type": "bitrix-d7-module", "require": { - "squizlabs/php_codesniffer": "3.6" + "squizlabs/php_codesniffer": "3.7.2" }, "autoload" : { "files": ["./vendor/squizlabs/php_codesniffer/autoload.php"] diff --git a/vendor/autoload.php b/vendor/autoload.php index 35717a0c..daccce78 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -9,4 +9,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit087501d35256718afd57a326e98e2cf2::getLoader(); +return ComposerAutoloaderInit41c4a817d788db8b07afa066797a1139::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 78ca7a18..2fcfe25b 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit087501d35256718afd57a326e98e2cf2 +class ComposerAutoloaderInit41c4a817d788db8b07afa066797a1139 { private static $loader; @@ -24,18 +24,18 @@ public static function getLoader() require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInit087501d35256718afd57a326e98e2cf2', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit41c4a817d788db8b07afa066797a1139', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit087501d35256718afd57a326e98e2cf2', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit41c4a817d788db8b07afa066797a1139', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit087501d35256718afd57a326e98e2cf2::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit41c4a817d788db8b07afa066797a1139::getInitializer($loader)); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit087501d35256718afd57a326e98e2cf2::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit41c4a817d788db8b07afa066797a1139::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire087501d35256718afd57a326e98e2cf2($fileIdentifier, $file); + composerRequire41c4a817d788db8b07afa066797a1139($fileIdentifier, $file); } return $loader; @@ -47,7 +47,7 @@ public static function getLoader() * @param string $file * @return void */ -function composerRequire087501d35256718afd57a326e98e2cf2($fileIdentifier, $file) +function composerRequire41c4a817d788db8b07afa066797a1139($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 25d45126..6d507ec5 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit087501d35256718afd57a326e98e2cf2 +class ComposerStaticInit41c4a817d788db8b07afa066797a1139 { public static $files = array ( 'a059625496c8f9f5b18f05115c70e8d0' => __DIR__ . '/..' . '/squizlabs/php_codesniffer/autoload.php', @@ -17,7 +17,7 @@ class ComposerStaticInit087501d35256718afd57a326e98e2cf2 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->classMap = ComposerStaticInit087501d35256718afd57a326e98e2cf2::$classMap; + $loader->classMap = ComposerStaticInit41c4a817d788db8b07afa066797a1139::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index cd43634e..c5b5e50c 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,17 +2,17 @@ "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "3.6.0", - "version_normalized": "3.6.0.0", + "version": "3.7.2", + "version_normalized": "3.7.2.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", - "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", "shasum": "" }, "require": { @@ -24,7 +24,7 @@ "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, - "time": "2021-04-09T00:54:41+00:00", + "time": "2023-02-22T23:07:41+00:00", "bin": [ "bin/phpcs", "bin/phpcbf" @@ -50,7 +50,8 @@ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 6344d70c..35877984 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,9 +1,9 @@ array( 'name' => 'intervolga/edu', - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', - 'reference' => NULL, + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'cdb2a0bc17c20a959f88161c6a096e353525534e', 'type' => 'bitrix-d7-module', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -11,18 +11,18 @@ ), 'versions' => array( 'intervolga/edu' => array( - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', - 'reference' => NULL, + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'cdb2a0bc17c20a959f88161c6a096e353525534e', 'type' => 'bitrix-d7-module', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'dev_requirement' => false, ), 'squizlabs/php_codesniffer' => array( - 'pretty_version' => '3.6.0', - 'version' => '3.6.0.0', - 'reference' => 'ffced0d2c8fa8e6cdc4d695a743271fab6c38625', + 'pretty_version' => '3.7.2', + 'version' => '3.7.2.0', + 'reference' => 'ed8e00df0a83aa96acf703f8c2979ff33341f879', 'type' => 'library', 'install_path' => __DIR__ . '/../squizlabs/php_codesniffer', 'aliases' => array(), diff --git a/vendor/squizlabs/php_codesniffer/CodeSniffer.conf.dist b/vendor/squizlabs/php_codesniffer/CodeSniffer.conf.dist index 62dc395c..f95058fa 100644 --- a/vendor/squizlabs/php_codesniffer/CodeSniffer.conf.dist +++ b/vendor/squizlabs/php_codesniffer/CodeSniffer.conf.dist @@ -5,5 +5,5 @@ 'show_warnings' => '0', 'show_progress' => '1', 'report_width' => '120', -) +); ?> diff --git a/vendor/squizlabs/php_codesniffer/README.md b/vendor/squizlabs/php_codesniffer/README.md index c0ea8e39..859de432 100644 --- a/vendor/squizlabs/php_codesniffer/README.md +++ b/vendor/squizlabs/php_codesniffer/README.md @@ -33,9 +33,9 @@ php phpcbf.phar -h ### Composer If you use Composer, you can install PHP_CodeSniffer system-wide with the following command: - - composer global require "squizlabs/php_codesniffer=*" - +```bash +composer global require "squizlabs/php_codesniffer=*" +``` Make sure you have the composer bin dir in your PATH. The default value is `~/.composer/vendor/bin/`, but you can check the value that you need to use by running `composer global config bin-dir --absolute`. Or alternatively, include a dependency for `squizlabs/php_codesniffer` in your `composer.json` file. For example: @@ -49,47 +49,48 @@ Or alternatively, include a dependency for `squizlabs/php_codesniffer` in your ` ``` You will then be able to run PHP_CodeSniffer from the vendor bin directory: - - ./vendor/bin/phpcs -h - ./vendor/bin/phpcbf -h - +```bash +./vendor/bin/phpcs -h +./vendor/bin/phpcbf -h +``` ### Phive If you use Phive, you can install PHP_CodeSniffer as a project tool using the following commands: - - phive install phpcs - phive install phpcbf - +```bash +phive install phpcs +phive install phpcbf +``` You will then be able to run PHP_CodeSniffer from the tools directory: - - ./tools/phpcs -h - ./tools/phpcbf -h - +```bash +./tools/phpcs -h +./tools/phpcbf -h +``` ### PEAR If you use PEAR, you can install PHP_CodeSniffer using the PEAR installer. This will make the `phpcs` and `phpcbf` commands immediately available for use. To install PHP_CodeSniffer using the PEAR installer, first ensure you have [installed PEAR](http://pear.php.net/manual/en/installation.getting.php) and then run the following command: - - pear install PHP_CodeSniffer - +```bash +pear install PHP_CodeSniffer +``` ### Git Clone You can also download the PHP_CodeSniffer source and run the `phpcs` and `phpcbf` commands directly from the Git clone: - - git clone https://github.com/squizlabs/PHP_CodeSniffer.git - cd PHP_CodeSniffer - php bin/phpcs -h - php bin/phpcbf -h - +```bash +git clone https://github.com/squizlabs/PHP_CodeSniffer.git +cd PHP_CodeSniffer +php bin/phpcs -h +php bin/phpcbf -h +``` ## Getting Started The default coding standard used by PHP_CodeSniffer is the PEAR coding standard. To check a file against the PEAR coding standard, simply specify the file's location: - - $ phpcs /path/to/code/myfile.php - +```bash +phpcs /path/to/code/myfile.php +``` Or if you wish to check an entire directory you can specify the directory location instead of a file. - - $ phpcs /path/to/code-directory - +```bash +phpcs /path/to/code-directory +``` If you wish to check your code against the PSR-12 coding standard, use the `--standard` command line argument: - - $ phpcs --standard=PSR12 /path/to/code-directory +```bash +phpcs --standard=PSR12 /path/to/code-directory +``` If PHP_CodeSniffer finds any coding standard errors, a report will be shown after running the command. diff --git a/vendor/squizlabs/php_codesniffer/composer.json b/vendor/squizlabs/php_codesniffer/composer.json index 7605a5df..37f41a0b 100644 --- a/vendor/squizlabs/php_codesniffer/composer.json +++ b/vendor/squizlabs/php_codesniffer/composer.json @@ -4,7 +4,8 @@ "type": "library", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "license": "BSD-3-Clause", diff --git a/vendor/squizlabs/php_codesniffer/licence.txt b/vendor/squizlabs/php_codesniffer/licence.txt index f95432c8..9f95b677 100644 --- a/vendor/squizlabs/php_codesniffer/licence.txt +++ b/vendor/squizlabs/php_codesniffer/licence.txt @@ -8,7 +8,7 @@ modification, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Squiz Pty Ltd nor the + * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/vendor/squizlabs/php_codesniffer/src/Config.php b/vendor/squizlabs/php_codesniffer/src/Config.php index 22b20492..bfca9e1d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Config.php +++ b/vendor/squizlabs/php_codesniffer/src/Config.php @@ -14,6 +14,7 @@ use PHP_CodeSniffer\Exceptions\DeepExitException; use PHP_CodeSniffer\Exceptions\RuntimeException; +use PHP_CodeSniffer\Util\Common; /** * Stores the configuration used to run PHPCS and PHPCBF. @@ -79,7 +80,7 @@ class Config * * @var string */ - const VERSION = '3.6.0'; + const VERSION = '3.7.2'; /** * Package stability; either stable, beta or alpha. @@ -363,11 +364,11 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true) $lastDir = $currentDir; $currentDir = dirname($currentDir); - } while ($currentDir !== '.' && $currentDir !== $lastDir && @is_readable($currentDir) === true); + } while ($currentDir !== '.' && $currentDir !== $lastDir && Common::isReadable($currentDir) === true); }//end if if (defined('STDIN') === false - || strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' + || stripos(PHP_OS, 'WIN') === 0 ) { return; } @@ -459,7 +460,7 @@ public function setCommandLineValues($args) /** * Restore default values for all possible command line arguments. * - * @return array + * @return void */ public function restoreDefaults() { @@ -1516,7 +1517,7 @@ public static function getExecutablePath($name) return self::$executablePaths[$name]; } - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + if (stripos(PHP_OS, 'WIN') === 0) { $cmd = 'where '.escapeshellarg($name).' 2> nul'; } else { $cmd = 'which '.escapeshellarg($name).' 2> /dev/null'; @@ -1596,7 +1597,7 @@ public static function setConfigData($key, $value, $temp=false) if ($temp === false) { $output = '<'.'?php'."\n".' $phpCodeSnifferConfig = '; $output .= var_export($phpCodeSnifferConfig, true); - $output .= "\n?".'>'; + $output .= ";\n?".'>'; if (file_put_contents($configFile, $output) === false) { $error = 'ERROR: Config file '.$configFile.' could not be written'.PHP_EOL.PHP_EOL; @@ -1656,7 +1657,7 @@ public static function getAllConfigData() return []; } - if (is_readable($configFile) === false) { + if (Common::isReadable($configFile) === false) { $error = 'ERROR: Config file '.$configFile.' is not readable'.PHP_EOL.PHP_EOL; throw new DeepExitException($error, 3); } diff --git a/vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php b/vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php index 3275bf09..60143030 100644 --- a/vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php +++ b/vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php @@ -38,7 +38,7 @@ public function __construct($content, Ruleset $ruleset, Config $config) // This is done by including: phpcs_input_file: [file path] // as the first line of content. $path = 'STDIN'; - if ($content !== null) { + if ($content !== '') { if (substr($content, 0, 17) === 'phpcs_input_file:') { $eolPos = strpos($content, $this->eolChar); $filename = trim(substr($content, 17, ($eolPos - 17))); diff --git a/vendor/squizlabs/php_codesniffer/src/Files/File.php b/vendor/squizlabs/php_codesniffer/src/Files/File.php index aef4fbf2..ad1ca0b2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Files/File.php +++ b/vendor/squizlabs/php_codesniffer/src/Files/File.php @@ -356,7 +356,7 @@ public function process() || $token['code'] === T_DOC_COMMENT_TAG || ($inTests === true && $token['code'] === T_INLINE_HTML)) ) { - $commentText = ltrim($this->tokens[$stackPtr]['content'], ' /*'); + $commentText = ltrim($this->tokens[$stackPtr]['content'], " \t/*#"); $commentTextLower = strtolower($commentText); if (strpos($commentText, '@codingStandards') !== false) { if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) { @@ -1223,7 +1223,7 @@ public function getFilename() /** - * Returns the declaration names for classes, interfaces, traits, and functions. + * Returns the declaration name for classes, interfaces, traits, enums, and functions. * * @param int $stackPtr The position of the declaration token which * declared the class, interface, trait, or function. @@ -1232,7 +1232,7 @@ public function getFilename() * or NULL if the function or class is anonymous. * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type * T_FUNCTION, T_CLASS, T_ANON_CLASS, - * T_CLOSURE, T_TRAIT, or T_INTERFACE. + * T_CLOSURE, T_TRAIT, T_ENUM, or T_INTERFACE. */ public function getDeclarationName($stackPtr) { @@ -1246,8 +1246,9 @@ public function getDeclarationName($stackPtr) && $tokenCode !== T_CLASS && $tokenCode !== T_INTERFACE && $tokenCode !== T_TRAIT + && $tokenCode !== T_ENUM ) { - throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT'); + throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM'); } if ($tokenCode === T_FUNCTION @@ -1283,6 +1284,7 @@ public function getDeclarationName($stackPtr) * 'name' => '$var', // The variable name. * 'token' => integer, // The stack pointer to the variable name. * 'content' => string, // The full content of the variable definition. + * 'has_attributes' => boolean, // Does the parameter have one or more attributes attached ? * 'pass_by_reference' => boolean, // Is the variable passed by reference? * 'reference_token' => integer, // The stack pointer to the reference operator * // or FALSE if the param is not passed by reference. @@ -1309,6 +1311,8 @@ public function getDeclarationName($stackPtr) * Parameters declared using PHP 8 constructor property promotion, have these additional array indexes: * 'property_visibility' => string, // The property visibility as declared. * 'visibility_token' => integer, // The stack pointer to the visibility modifier token. + * 'property_readonly' => bool, // TRUE if the readonly keyword was found. + * 'readonly_token' => integer, // The stack pointer to the readonly modifier token. * * @param int $stackPtr The position in the stack of the function token * to acquire the parameters for. @@ -1355,6 +1359,7 @@ public function getMethodParameters($stackPtr) $defaultStart = null; $equalToken = null; $paramCount = 0; + $hasAttributes = false; $passByReference = false; $referenceToken = false; $variableLength = false; @@ -1364,6 +1369,7 @@ public function getMethodParameters($stackPtr) $typeHintEndToken = false; $nullableType = false; $visibilityToken = null; + $readonlyToken = null; for ($i = $paramStart; $i <= $closer; $i++) { // Check to see if this token has a parenthesis or bracket opener. If it does @@ -1373,18 +1379,25 @@ public function getMethodParameters($stackPtr) if (isset($this->tokens[$i]['parenthesis_opener']) === true) { // Don't do this if it's the close parenthesis for the method. if ($i !== $this->tokens[$i]['parenthesis_closer']) { - $i = ($this->tokens[$i]['parenthesis_closer'] + 1); + $i = $this->tokens[$i]['parenthesis_closer']; + continue; } } if (isset($this->tokens[$i]['bracket_opener']) === true) { - // Don't do this if it's the close parenthesis for the method. if ($i !== $this->tokens[$i]['bracket_closer']) { - $i = ($this->tokens[$i]['bracket_closer'] + 1); + $i = $this->tokens[$i]['bracket_closer']; + continue; } } switch ($this->tokens[$i]['code']) { + case T_ATTRIBUTE: + $hasAttributes = true; + + // Skip to the end of the attribute. + $i = $this->tokens[$i]['attribute_closer']; + break; case T_BITWISE_AND: if ($defaultStart === null) { $passByReference = true; @@ -1456,6 +1469,7 @@ public function getMethodParameters($stackPtr) case T_NAMESPACE: case T_NS_SEPARATOR: case T_TYPE_UNION: + case T_TYPE_INTERSECTION: case T_FALSE: case T_NULL: // Part of a type hint or default value. @@ -1482,6 +1496,11 @@ public function getMethodParameters($stackPtr) $visibilityToken = $i; } break; + case T_READONLY: + if ($defaultStart === null) { + $readonlyToken = $i; + } + break; case T_CLOSE_PARENTHESIS: case T_COMMA: // If it's null, then there must be no parameters for this @@ -1501,6 +1520,7 @@ public function getMethodParameters($stackPtr) $vars[$paramCount]['default_equal_token'] = $equalToken; } + $vars[$paramCount]['has_attributes'] = $hasAttributes; $vars[$paramCount]['pass_by_reference'] = $passByReference; $vars[$paramCount]['reference_token'] = $referenceToken; $vars[$paramCount]['variable_length'] = $variableLength; @@ -1513,6 +1533,12 @@ public function getMethodParameters($stackPtr) if ($visibilityToken !== null) { $vars[$paramCount]['property_visibility'] = $this->tokens[$visibilityToken]['content']; $vars[$paramCount]['visibility_token'] = $visibilityToken; + $vars[$paramCount]['property_readonly'] = false; + } + + if ($readonlyToken !== null) { + $vars[$paramCount]['property_readonly'] = true; + $vars[$paramCount]['readonly_token'] = $readonlyToken; } if ($this->tokens[$i]['code'] === T_COMMA) { @@ -1526,6 +1552,7 @@ public function getMethodParameters($stackPtr) $paramStart = ($i + 1); $defaultStart = null; $equalToken = null; + $hasAttributes = false; $passByReference = false; $referenceToken = false; $variableLength = false; @@ -1535,6 +1562,7 @@ public function getMethodParameters($stackPtr) $typeHintEndToken = false; $nullableType = false; $visibilityToken = null; + $readonlyToken = null; $paramCount++; break; @@ -1658,16 +1686,17 @@ public function getMethodProperties($stackPtr) } $valid = [ - T_STRING => T_STRING, - T_CALLABLE => T_CALLABLE, - T_SELF => T_SELF, - T_PARENT => T_PARENT, - T_STATIC => T_STATIC, - T_FALSE => T_FALSE, - T_NULL => T_NULL, - T_NAMESPACE => T_NAMESPACE, - T_NS_SEPARATOR => T_NS_SEPARATOR, - T_TYPE_UNION => T_TYPE_UNION, + T_STRING => T_STRING, + T_CALLABLE => T_CALLABLE, + T_SELF => T_SELF, + T_PARENT => T_PARENT, + T_STATIC => T_STATIC, + T_FALSE => T_FALSE, + T_NULL => T_NULL, + T_NAMESPACE => T_NAMESPACE, + T_NS_SEPARATOR => T_NS_SEPARATOR, + T_TYPE_UNION => T_TYPE_UNION, + T_TYPE_INTERSECTION => T_TYPE_INTERSECTION, ]; for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) { @@ -1732,6 +1761,7 @@ public function getMethodProperties($stackPtr) * 'scope' => string, // Public, private, or protected. * 'scope_specified' => boolean, // TRUE if the scope was explicitly specified. * 'is_static' => boolean, // TRUE if the static keyword was found. + * 'is_readonly' => boolean, // TRUE if the readonly keyword was found. * 'type' => string, // The type of the var (empty if no type specified). * 'type_token' => integer, // The stack pointer to the start of the type * // or FALSE if there is no type. @@ -1764,23 +1794,26 @@ public function getMemberProperties($stackPtr) && $this->tokens[$ptr]['code'] !== T_TRAIT) ) { if (isset($this->tokens[$ptr]) === true - && $this->tokens[$ptr]['code'] === T_INTERFACE + && ($this->tokens[$ptr]['code'] === T_INTERFACE + || $this->tokens[$ptr]['code'] === T_ENUM) ) { - // T_VARIABLEs in interfaces can actually be method arguments - // but they wont be seen as being inside the method because there + // T_VARIABLEs in interfaces/enums can actually be method arguments + // but they won't be seen as being inside the method because there // are no scope openers and closers for abstract methods. If it is in // parentheses, we can be pretty sure it is a method argument. if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false || empty($this->tokens[$stackPtr]['nested_parenthesis']) === true ) { - $error = 'Possible parse error: interfaces may not include member vars'; - $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar'); + $error = 'Possible parse error: %ss may not include member vars'; + $code = sprintf('Internal.ParseError.%sHasMemberVar', ucfirst($this->tokens[$ptr]['content'])); + $data = [strtolower($this->tokens[$ptr]['content'])]; + $this->addWarning($error, $stackPtr, $code, $data); return []; } } else { throw new RuntimeException('$stackPtr is not a class member var'); } - } + }//end if // Make sure it's not a method parameter. if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) { @@ -1800,6 +1833,7 @@ public function getMemberProperties($stackPtr) T_PROTECTED => T_PROTECTED, T_STATIC => T_STATIC, T_VAR => T_VAR, + T_READONLY => T_READONLY, ]; $valid += Util\Tokens::$emptyTokens; @@ -1807,6 +1841,7 @@ public function getMemberProperties($stackPtr) $scope = 'public'; $scopeSpecified = false; $isStatic = false; + $isReadonly = false; $startOfStatement = $this->findPrevious( [ @@ -1839,6 +1874,9 @@ public function getMemberProperties($stackPtr) case T_STATIC: $isStatic = true; break; + case T_READONLY: + $isReadonly = true; + break; } }//end for @@ -1850,15 +1888,16 @@ public function getMemberProperties($stackPtr) if ($i < $stackPtr) { // We've found a type. $valid = [ - T_STRING => T_STRING, - T_CALLABLE => T_CALLABLE, - T_SELF => T_SELF, - T_PARENT => T_PARENT, - T_FALSE => T_FALSE, - T_NULL => T_NULL, - T_NAMESPACE => T_NAMESPACE, - T_NS_SEPARATOR => T_NS_SEPARATOR, - T_TYPE_UNION => T_TYPE_UNION, + T_STRING => T_STRING, + T_CALLABLE => T_CALLABLE, + T_SELF => T_SELF, + T_PARENT => T_PARENT, + T_FALSE => T_FALSE, + T_NULL => T_NULL, + T_NAMESPACE => T_NAMESPACE, + T_NS_SEPARATOR => T_NS_SEPARATOR, + T_TYPE_UNION => T_TYPE_UNION, + T_TYPE_INTERSECTION => T_TYPE_INTERSECTION, ]; for ($i; $i < $stackPtr; $i++) { @@ -1890,6 +1929,7 @@ public function getMemberProperties($stackPtr) 'scope' => $scope, 'scope_specified' => $scopeSpecified, 'is_static' => $isStatic, + 'is_readonly' => $isReadonly, 'type' => $type, 'type_token' => $typeToken, 'type_end_token' => $typeEndToken, @@ -2285,8 +2325,9 @@ public function findNext( public function findStartOfStatement($start, $ignore=null) { $startTokens = Util\Tokens::$blockOpeners; - $startTokens[T_OPEN_SHORT_ARRAY] = true; - $startTokens[T_OPEN_TAG] = true; + $startTokens[T_OPEN_SHORT_ARRAY] = true; + $startTokens[T_OPEN_TAG] = true; + $startTokens[T_OPEN_TAG_WITH_ECHO] = true; $endTokens = [ T_CLOSE_TAG => true, @@ -2731,11 +2772,11 @@ public function findExtendedClassName($stackPtr) /** - * Returns the names of the interfaces that the specified class implements. + * Returns the names of the interfaces that the specified class or enum implements. * * Returns FALSE on error or if there are no implemented interface names. * - * @param int $stackPtr The stack position of the class. + * @param int $stackPtr The stack position of the class or enum token. * * @return array|false */ @@ -2748,6 +2789,7 @@ public function findImplementedInterfaceNames($stackPtr) if ($this->tokens[$stackPtr]['code'] !== T_CLASS && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS + && $this->tokens[$stackPtr]['code'] !== T_ENUM ) { return false; } diff --git a/vendor/squizlabs/php_codesniffer/src/Files/FileList.php b/vendor/squizlabs/php_codesniffer/src/Files/FileList.php index e889fc3d..66833a3e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Files/FileList.php +++ b/vendor/squizlabs/php_codesniffer/src/Files/FileList.php @@ -16,6 +16,7 @@ use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Exceptions\DeepExitException; +use ReturnTypeWillChange; class FileList implements \Iterator, \Countable { @@ -169,6 +170,7 @@ private function getFilterClass() * * @return void */ + #[ReturnTypeWillChange] public function rewind() { reset($this->files); @@ -181,6 +183,7 @@ public function rewind() * * @return \PHP_CodeSniffer\Files\File */ + #[ReturnTypeWillChange] public function current() { $path = key($this->files); @@ -198,6 +201,7 @@ public function current() * * @return void */ + #[ReturnTypeWillChange] public function key() { return key($this->files); @@ -210,6 +214,7 @@ public function key() * * @return void */ + #[ReturnTypeWillChange] public function next() { next($this->files); @@ -222,6 +227,7 @@ public function next() * * @return boolean */ + #[ReturnTypeWillChange] public function valid() { if (current($this->files) === false) { @@ -238,6 +244,7 @@ public function valid() * * @return integer */ + #[ReturnTypeWillChange] public function count() { return $this->numFiles; diff --git a/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php b/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php index 5bed499b..a1246a2c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php +++ b/vendor/squizlabs/php_codesniffer/src/Filters/Filter.php @@ -12,6 +12,7 @@ use PHP_CodeSniffer\Util; use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; +use ReturnTypeWillChange; class Filter extends \RecursiveFilterIterator { @@ -89,6 +90,7 @@ public function __construct($iterator, $basedir, Config $config, Ruleset $rulese * * @return bool */ + #[ReturnTypeWillChange] public function accept() { $filePath = $this->current(); @@ -130,6 +132,7 @@ public function accept() * * @return \RecursiveIterator */ + #[ReturnTypeWillChange] public function getChildren() { $filterClass = get_called_class(); diff --git a/vendor/squizlabs/php_codesniffer/src/Fixer.php b/vendor/squizlabs/php_codesniffer/src/Fixer.php index ed6adb15..b8dc05b1 100644 --- a/vendor/squizlabs/php_codesniffer/src/Fixer.php +++ b/vendor/squizlabs/php_codesniffer/src/Fixer.php @@ -184,6 +184,9 @@ public function fixFile() } echo ']... '; + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo PHP_EOL; + } } if ($this->numFixes === 0 && $this->inConflict === false) { @@ -418,6 +421,7 @@ public function endChangeset() } $this->changeset = []; + return true; }//end endChangeset() diff --git a/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php b/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php index 25249e85..0ecde76e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php +++ b/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php @@ -44,6 +44,9 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false, ob_end_clean(); $startTime = microtime(true); echo "\t=> Fixing file: $errors/$errors violations remaining"; + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo PHP_EOL; + } } $fixed = $phpcsFile->fixer->fixFile(); diff --git a/vendor/squizlabs/php_codesniffer/src/Reports/Code.php b/vendor/squizlabs/php_codesniffer/src/Reports/Code.php index c54c1e1a..47c5581e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Reports/Code.php +++ b/vendor/squizlabs/php_codesniffer/src/Reports/Code.php @@ -225,7 +225,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false, if (strpos($tokenContent, "\t") !== false) { $token = $tokens[$i]; $token['content'] = $tokenContent; - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + if (stripos(PHP_OS, 'WIN') === 0) { $tab = "\000"; } else { $tab = "\033[30;1m»\033[0m"; diff --git a/vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php b/vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php index 947f3d80..6427567f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php +++ b/vendor/squizlabs/php_codesniffer/src/Reports/Gitblame.php @@ -78,7 +78,7 @@ protected function getBlameContent($filename) } $rawContent = stream_get_contents($handle); - fclose($handle); + pclose($handle); $blames = explode("\n", $rawContent); chdir($cwd); diff --git a/vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php b/vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php index b0af6643..f88a0683 100644 --- a/vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php +++ b/vendor/squizlabs/php_codesniffer/src/Reports/Hgblame.php @@ -97,7 +97,7 @@ protected function getBlameContent($filename) } $rawContent = stream_get_contents($handle); - fclose($handle); + pclose($handle); $blames = explode("\n", $rawContent); chdir($cwd); diff --git a/vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php b/vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php index f4719fe5..a7f65e15 100644 --- a/vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php +++ b/vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php @@ -61,7 +61,7 @@ protected function getBlameContent($filename) } $rawContent = stream_get_contents($handle); - fclose($handle); + pclose($handle); $blames = explode("\n", $rawContent); diff --git a/vendor/squizlabs/php_codesniffer/src/Ruleset.php b/vendor/squizlabs/php_codesniffer/src/Ruleset.php index 7e659706..f90e7b6d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Ruleset.php +++ b/vendor/squizlabs/php_codesniffer/src/Ruleset.php @@ -249,7 +249,12 @@ public function explain() // one last time and clear the output buffer. $sniffs[] = ''; - echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL; + $summaryLine = PHP_EOL."The $this->name standard contains 1 sniff".PHP_EOL; + if ($sniffCount !== 1) { + $summaryLine = str_replace('1 sniff', "$sniffCount sniffs", $summaryLine); + } + + echo $summaryLine; ob_start(); diff --git a/vendor/squizlabs/php_codesniffer/src/Runner.php b/vendor/squizlabs/php_codesniffer/src/Runner.php index 320a8f20..e0cbca71 100644 --- a/vendor/squizlabs/php_codesniffer/src/Runner.php +++ b/vendor/squizlabs/php_codesniffer/src/Runner.php @@ -53,6 +53,8 @@ class Runner */ public function runPHPCS() { + $this->registerOutOfMemoryShutdownMessage('phpcs'); + try { Util\Timing::startTiming(); Runner::checkRequirements(); @@ -153,6 +155,8 @@ public function runPHPCS() */ public function runPHPCBF() { + $this->registerOutOfMemoryShutdownMessage('phpcbf'); + if (defined('PHP_CODESNIFFER_CBF') === false) { define('PHP_CODESNIFFER_CBF', true); } @@ -232,7 +236,7 @@ public function runPHPCBF() /** * Exits if the minimum requirements of PHP_CodeSniffer are not met. * - * @return array + * @return void * @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the requirements are not met. */ public function checkRequirements() @@ -291,7 +295,7 @@ public function init() // Ensure this option is enabled or else line endings will not always // be detected properly for files created on a Mac with the /r line ending. - ini_set('auto_detect_line_endings', true); + @ini_set('auto_detect_line_endings', true); // Disable the PCRE JIT as this caused issues with parallel running. ini_set('pcre.jit', false); @@ -460,10 +464,7 @@ private function run() if ($pid === -1) { throw new RuntimeException('Failed to create child process'); } else if ($pid !== 0) { - $childProcs[] = [ - 'pid' => $pid, - 'out' => $childOutFilename, - ]; + $childProcs[$pid] = $childOutFilename; } else { // Move forward to the start of the batch. $todo->rewind(); @@ -487,6 +488,7 @@ private function run() $file = $todo->current(); if ($file->ignored === true) { + $todo->next(); continue; } @@ -535,7 +537,7 @@ private function run() $output .= ";\n?".'>'; file_put_contents($childOutFilename, $output); - exit($pid); + exit(); }//end if }//end for @@ -718,54 +720,61 @@ private function processChildProcs($childProcs) $success = true; while (count($childProcs) > 0) { - foreach ($childProcs as $key => $procData) { - $res = pcntl_waitpid($procData['pid'], $status, WNOHANG); - if ($res === $procData['pid']) { - if (file_exists($procData['out']) === true) { - include $procData['out']; - - unlink($procData['out']); - unset($childProcs[$key]); - - $numProcessed++; - - if (isset($childOutput) === false) { - // The child process died, so the run has failed. - $file = new DummyFile(null, $this->ruleset, $this->config); - $file->setErrorCounts(1, 0, 0, 0); - $this->printProgress($file, $totalBatches, $numProcessed); - $success = false; - continue; - } + $pid = pcntl_waitpid(0, $status); + if ($pid <= 0) { + continue; + } - $this->reporter->totalFiles += $childOutput['totalFiles']; - $this->reporter->totalErrors += $childOutput['totalErrors']; - $this->reporter->totalWarnings += $childOutput['totalWarnings']; - $this->reporter->totalFixable += $childOutput['totalFixable']; - $this->reporter->totalFixed += $childOutput['totalFixed']; + $childProcessStatus = pcntl_wexitstatus($status); + if ($childProcessStatus !== 0) { + $success = false; + } - if (isset($debugOutput) === true) { - echo $debugOutput; - } + $out = $childProcs[$pid]; + unset($childProcs[$pid]); + if (file_exists($out) === false) { + continue; + } - if (isset($childCache) === true) { - foreach ($childCache as $path => $cache) { - Cache::set($path, $cache); - } - } + include $out; + unlink($out); - // Fake a processed file so we can print progress output for the batch. - $file = new DummyFile(null, $this->ruleset, $this->config); - $file->setErrorCounts( - $childOutput['totalErrors'], - $childOutput['totalWarnings'], - $childOutput['totalFixable'], - $childOutput['totalFixed'] - ); - $this->printProgress($file, $totalBatches, $numProcessed); - }//end if - }//end if - }//end foreach + $numProcessed++; + + if (isset($childOutput) === false) { + // The child process died, so the run has failed. + $file = new DummyFile('', $this->ruleset, $this->config); + $file->setErrorCounts(1, 0, 0, 0); + $this->printProgress($file, $totalBatches, $numProcessed); + $success = false; + continue; + } + + $this->reporter->totalFiles += $childOutput['totalFiles']; + $this->reporter->totalErrors += $childOutput['totalErrors']; + $this->reporter->totalWarnings += $childOutput['totalWarnings']; + $this->reporter->totalFixable += $childOutput['totalFixable']; + $this->reporter->totalFixed += $childOutput['totalFixed']; + + if (isset($debugOutput) === true) { + echo $debugOutput; + } + + if (isset($childCache) === true) { + foreach ($childCache as $path => $cache) { + Cache::set($path, $cache); + } + } + + // Fake a processed file so we can print progress output for the batch. + $file = new DummyFile('', $this->ruleset, $this->config); + $file->setErrorCounts( + $childOutput['totalErrors'], + $childOutput['totalWarnings'], + $childOutput['totalFixable'], + $childOutput['totalFixed'] + ); + $this->printProgress($file, $totalBatches, $numProcessed); }//end while return $success; @@ -886,4 +895,42 @@ public function printProgress(File $file, $numFiles, $numProcessed) }//end printProgress() + /** + * Registers a PHP shutdown function to provide a more informative out of memory error. + * + * @param string $command The command which was used to initiate the PHPCS run. + * + * @return void + */ + private function registerOutOfMemoryShutdownMessage($command) + { + // Allocate all needed memory beforehand as much as possible. + $errorMsg = PHP_EOL.'The PHP_CodeSniffer "%1$s" command ran out of memory.'.PHP_EOL; + $errorMsg .= 'Either raise the "memory_limit" of PHP in the php.ini file or raise the memory limit at runtime'.PHP_EOL; + $errorMsg .= 'using `%1$s -d memory_limit=512M` (replace 512M with the desired memory limit).'.PHP_EOL; + $errorMsg = sprintf($errorMsg, $command); + $memoryError = 'Allowed memory size of'; + $errorArray = [ + 'type' => 42, + 'message' => 'Some random dummy string to take up memory and take up some more memory and some more', + 'file' => 'Another random string, which would be a filename this time. Should be relatively long to allow for deeply nested files', + 'line' => 31427, + ]; + + register_shutdown_function( + static function () use ( + $errorMsg, + $memoryError, + $errorArray + ) { + $errorArray = error_get_last(); + if (is_array($errorArray) === true && strpos($errorArray['message'], $memoryError) !== false) { + echo $errorMsg; + } + } + ); + + }//end registerOutOfMemoryShutdownMessage() + + }//end class diff --git a/vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php b/vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php index 141b9a13..efe9969d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php @@ -104,9 +104,9 @@ public function process(File $phpcsFile, $stackPtr) /** * Find next separator in array - either: comma or double arrow. * - * @param File $phpcsFile The current file being checked. - * @param int $ptr The position of current token. - * @param int $arrayEnd The token that ends the array definition. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. + * @param int $ptr The position of current token. + * @param int $arrayEnd The token that ends the array definition. * * @return int */ diff --git a/vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php b/vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php index c9d7daea..3f0fb6a1 100644 --- a/vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php @@ -45,7 +45,7 @@ public function register(); * is found. * * The stackPtr variable indicates where in the stack the token was found. - * A sniff can acquire information this token, along with all the other + * A sniff can acquire information about this token, along with all the other * tokens within the stack by first acquiring the token stack: * * diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml index 6226a3ff..6fa08be7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml @@ -15,6 +15,14 @@ class Foo { { +} + ]]> + + + + + { } ]]> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml index dd3e7731..aea86369 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml @@ -10,13 +10,10 @@ if (! $someVar || ! $x instanceOf stdClass) {}; ]]> - + $someVar || !$x instanceOf stdClass) {}; - ]]> - - - $someVar || ! $x instanceOf stdClass) {}; ]]> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml index 30e0def9..338c8389 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml @@ -10,13 +10,10 @@ $a = (null !== $extra); ]]> - + - - - findNext(Tokens::$emptyTokens, ($end + 1), null, true); if ($next === false) { break; @@ -227,15 +230,20 @@ public function process(File $phpcsFile, $stackPtr) continue; } + // Account for TRY... CATCH/FINALLY statements. + if (($type === T_TRY + || $type === T_CATCH + || $type === T_FINALLY) + && ($nextType === T_CATCH + || $nextType === T_FINALLY) + ) { + continue; + } + // Account for DO... WHILE conditions. if ($type === T_DO && $nextType === T_WHILE) { $end = $phpcsFile->findNext(T_SEMICOLON, ($next + 1)); } - - // Account for TRY... CATCH statements. - if ($type === T_TRY && $nextType === T_CATCH) { - $end = $tokens[$next]['scope_closer']; - } } else if ($type === T_CLOSURE) { // There should be a semicolon after the closing brace. $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php index ee52a1b9..d5375dc5 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php @@ -34,7 +34,10 @@ class EndFileNewlineSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php index 2c7fcd35..41c9c749 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/EndFileNoNewlineSniff.php @@ -34,7 +34,10 @@ class EndFileNoNewlineSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/ExecutableFileSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/ExecutableFileSniff.php index 51534bf3..e1213d5f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/ExecutableFileSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/ExecutableFileSniff.php @@ -23,7 +23,10 @@ class ExecutableFileSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php index 763e7863..845e1bcf 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php @@ -41,7 +41,10 @@ class LineEndingsSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php index 2f442b11..a9fd4c5d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php @@ -23,7 +23,10 @@ class LowercasedFilenameSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php index 9bcc00c1..52d5d84c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one class is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound'); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php index f7cfa8d3..9a6f5bcc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextInterface = $phpcsFile->findNext($this->register(), $start); if ($nextInterface !== false) { $error = 'Only one interface is allowed in a file'; $phpcsFile->addError($error, $nextInterface, 'MultipleFound'); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php index d9d71b69..4d417e06 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() @@ -43,7 +44,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one object structure is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound'); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php index dd97da85..7ae523f7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one trait is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound'); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php index b1b3cc64..802e5944 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php @@ -80,25 +80,6 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - - // Ignore assignments used in a condition, like an IF or FOR. - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - // If the parenthesis is on the same line as the assignment, - // then it should be ignored as it is specifically being grouped. - $parens = $tokens[$stackPtr]['nested_parenthesis']; - $lastParen = array_pop($parens); - if ($tokens[$lastParen]['line'] === $tokens[$stackPtr]['line']) { - return; - } - - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) { - if (isset($tokens[$start]['parenthesis_owner']) === true) { - return; - } - } - } - $lastAssign = $this->checkAlignment($phpcsFile, $stackPtr); return ($lastAssign + 1); @@ -120,6 +101,23 @@ public function checkAlignment($phpcsFile, $stackPtr, $end=null) { $tokens = $phpcsFile->getTokens(); + // Ignore assignments used in a condition, like an IF or FOR or closure param defaults. + if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { + // If the parenthesis is on the same line as the assignment, + // then it should be ignored as it is specifically being grouped. + $parens = $tokens[$stackPtr]['nested_parenthesis']; + $lastParen = array_pop($parens); + if ($tokens[$lastParen]['line'] === $tokens[$stackPtr]['line']) { + return $stackPtr; + } + + foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) { + if (isset($tokens[$start]['parenthesis_owner']) === true) { + return $stackPtr; + } + } + } + $assignments = []; $prevAssign = null; $lastLine = $tokens[$stackPtr]['line']; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php index ca922381..136a1d4a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php @@ -30,6 +30,7 @@ public function register() T_UNSET, T_SELF, T_STATIC, + T_PARENT, T_VARIABLE, T_CLOSE_CURLY_BRACKET, T_CLOSE_PARENTHESIS, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php index be1464d7..ff19526a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php @@ -139,17 +139,31 @@ public function process(File $phpcsFile, $stackPtr) } else if ($lineDifference > 1) { $error = 'Opening brace should be on the line after the declaration; found %s blank line(s)'; $data = [($lineDifference - 1)]; - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); - if ($fix === true) { - for ($i = ($tokens[$stackPtr]['parenthesis_closer'] + 1); $i < $openingBrace; $i++) { - if ($tokens[$i]['line'] === $braceLine) { - $phpcsFile->fixer->addNewLineBefore($i); - break; + + $prevNonWs = $phpcsFile->findPrevious(T_WHITESPACE, ($openingBrace - 1), $closeBracket, true); + if ($prevNonWs !== $prev) { + // There must be a comment between the end of the function declaration and the open brace. + // Report, but don't fix. + $phpcsFile->addError($error, $openingBrace, 'BraceSpacing', $data); + } else { + $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceSpacing', $data); + if ($fix === true) { + $phpcsFile->fixer->beginChangeset(); + for ($i = $openingBrace; $i > $prev; $i--) { + if ($tokens[$i]['line'] === $tokens[$openingBrace]['line']) { + if ($tokens[$i]['column'] === 1) { + $phpcsFile->fixer->addNewLineBefore($i); + } + + continue; + } + + $phpcsFile->fixer->replaceToken($i, ''); } - $phpcsFile->fixer->replaceToken($i, ''); + $phpcsFile->fixer->endChangeset(); } - } + }//end if }//end if $ignore = Tokens::$phpcsCommentTokens; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php index df70df22..9bd0dff3 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php @@ -71,15 +71,19 @@ public function process(File $phpcsFile, $stackPtr) // Predicate nodes for PHP. $find = [ - T_CASE => true, - T_DEFAULT => true, - T_CATCH => true, - T_IF => true, - T_FOR => true, - T_FOREACH => true, - T_WHILE => true, - T_DO => true, - T_ELSEIF => true, + T_CASE => true, + T_DEFAULT => true, + T_CATCH => true, + T_IF => true, + T_FOR => true, + T_FOREACH => true, + T_WHILE => true, + T_ELSEIF => true, + T_INLINE_THEN => true, + T_COALESCE => true, + T_COALESCE_EQUAL => true, + T_MATCH_ARROW => true, + T_NULLSAFE_OBJECT_OPERATOR => true, ]; $complexity = 1; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php index b7f5427a..a4196063 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php @@ -66,7 +66,12 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop return; } - $className = strtolower($phpcsFile->getDeclarationName($currScope)); + $className = $phpcsFile->getDeclarationName($currScope); + if (empty($className) === false) { + // Not an anonymous class. + $className = strtolower($className); + } + if ($className !== $this->currentClass) { $this->loadFunctionNamesInScope($phpcsFile, $currScope); $this->currentClass = $className; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php index e59ed5ff..d03bf8ab 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php @@ -23,7 +23,10 @@ class ClosingPHPTagSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DisallowRequestSuperglobalSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DisallowRequestSuperglobalSniff.php index d5c7ddb7..1c2b1aee 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DisallowRequestSuperglobalSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DisallowRequestSuperglobalSniff.php @@ -31,8 +31,9 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack + * passed in $tokens. * * @return void */ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php index 8b8c76e9..4376daa9 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php @@ -11,6 +11,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; class LowerCaseConstantSniff implements Sniff { @@ -25,6 +26,17 @@ class LowerCaseConstantSniff implements Sniff 'JS', ]; + /** + * The tokens this sniff is targetting. + * + * @var array + */ + private $targets = [ + T_TRUE => T_TRUE, + T_FALSE => T_FALSE, + T_NULL => T_NULL, + ]; + /** * Returns an array of tokens this test wants to listen for. @@ -33,11 +45,14 @@ class LowerCaseConstantSniff implements Sniff */ public function register() { - return [ - T_TRUE, - T_FALSE, - T_NULL, - ]; + $targets = $this->targets; + + // Register function keywords to filter out type declarations. + $targets[] = T_FUNCTION; + $targets[] = T_CLOSURE; + $targets[] = T_FN; + + return $targets; }//end register() @@ -52,10 +67,89 @@ public function register() * @return void */ public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + // Handle function declarations separately as they may contain the keywords in type declarations. + if ($tokens[$stackPtr]['code'] === T_FUNCTION + || $tokens[$stackPtr]['code'] === T_CLOSURE + || $tokens[$stackPtr]['code'] === T_FN + ) { + if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) { + return; + } + + $end = $tokens[$stackPtr]['parenthesis_closer']; + if (isset($tokens[$stackPtr]['scope_opener']) === true) { + $end = $tokens[$stackPtr]['scope_opener']; + } + + // Do a quick check if any of the targets exist in the declaration. + $found = $phpcsFile->findNext($this->targets, $tokens[$stackPtr]['parenthesis_opener'], $end); + if ($found === false) { + // Skip forward, no need to examine these tokens again. + return $end; + } + + // Handle the whole function declaration in one go. + $params = $phpcsFile->getMethodParameters($stackPtr); + foreach ($params as $param) { + if (isset($param['default_token']) === false) { + continue; + } + + $paramEnd = $param['comma_token']; + if ($param['comma_token'] === false) { + $paramEnd = $tokens[$stackPtr]['parenthesis_closer']; + } + + for ($i = $param['default_token']; $i < $paramEnd; $i++) { + if (isset($this->targets[$tokens[$i]['code']]) === true) { + $this->processConstant($phpcsFile, $i); + } + } + } + + // Skip over return type declarations. + return $end; + }//end if + + // Handle property declarations separately as they may contain the keywords in type declarations. + if (isset($tokens[$stackPtr]['conditions']) === true) { + $conditions = $tokens[$stackPtr]['conditions']; + $lastCondition = end($conditions); + if (isset(Tokens::$ooScopeTokens[$lastCondition]) === true) { + // This can only be an OO constant or property declaration as methods are handled above. + $equals = $phpcsFile->findPrevious(T_EQUAL, ($stackPtr - 1), null, false, null, true); + if ($equals !== false) { + $this->processConstant($phpcsFile, $stackPtr); + } + + return; + } + } + + // Handle everything else. + $this->processConstant($phpcsFile, $stackPtr); + + }//end process() + + + /** + * Processes a non-type declaration constant. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. + * + * @return void + */ + protected function processConstant(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $keyword = $tokens[$stackPtr]['content']; $expected = strtolower($keyword); + if ($keyword !== $expected) { if ($keyword === strtoupper($keyword)) { $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); @@ -77,7 +171,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); } - }//end process() + }//end processConstant() }//end class diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php index e10047b6..e6b49178 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseKeywordSniff.php @@ -11,7 +11,8 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; -use PHP_CodeSniffer\Util; +use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Util\Tokens; class LowerCaseKeywordSniff implements Sniff { @@ -24,81 +25,21 @@ class LowerCaseKeywordSniff implements Sniff */ public function register() { - return [ - T_ABSTRACT, - T_ARRAY, - T_AS, - T_BREAK, - T_CALLABLE, - T_CASE, - T_CATCH, - T_CLASS, - T_CLONE, - T_CLOSURE, - T_CONST, - T_CONTINUE, - T_DECLARE, - T_DEFAULT, - T_DO, - T_ECHO, - T_ELSE, - T_ELSEIF, - T_EMPTY, - T_ENDDECLARE, - T_ENDFOR, - T_ENDFOREACH, - T_ENDIF, - T_ENDSWITCH, - T_ENDWHILE, - T_EVAL, - T_EXIT, - T_EXTENDS, - T_FINAL, - T_FINALLY, - T_FN, - T_FOR, - T_FOREACH, - T_FUNCTION, - T_GLOBAL, - T_GOTO, - T_IF, - T_IMPLEMENTS, - T_INCLUDE, - T_INCLUDE_ONCE, - T_INSTANCEOF, - T_INSTEADOF, - T_INTERFACE, - T_ISSET, - T_LIST, - T_LOGICAL_AND, - T_LOGICAL_OR, - T_LOGICAL_XOR, - T_MATCH, - T_MATCH_DEFAULT, - T_NAMESPACE, - T_NEW, - T_PARENT, - T_PRINT, - T_PRIVATE, - T_PROTECTED, - T_PUBLIC, - T_REQUIRE, - T_REQUIRE_ONCE, - T_RETURN, - T_SELF, - T_STATIC, - T_SWITCH, - T_THROW, - T_TRAIT, - T_TRY, - T_UNSET, - T_USE, - T_VAR, - T_WHILE, - T_YIELD, - T_YIELD_FROM, + $targets = Tokens::$contextSensitiveKeywords; + $targets += [ + T_CLOSURE => T_CLOSURE, + T_EMPTY => T_EMPTY, + T_ENUM_CASE => T_ENUM_CASE, + T_EVAL => T_EVAL, + T_ISSET => T_ISSET, + T_MATCH_DEFAULT => T_MATCH_DEFAULT, + T_PARENT => T_PARENT, + T_SELF => T_SELF, + T_UNSET => T_UNSET, ]; + return $targets; + }//end register() @@ -122,7 +63,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed'); } - $messageKeyword = Util\Common::prepareForOutput($keyword); + $messageKeyword = Common::prepareForOutput($keyword); $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"'; $data = [ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php index a738c30d..4d463f28 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php @@ -38,6 +38,7 @@ class LowerCaseTypeSniff implements Sniff 'static' => true, 'false' => true, 'null' => true, + 'never' => true, ]; @@ -51,6 +52,7 @@ public function register() $tokens = Tokens::$castTokens; $tokens[] = T_FUNCTION; $tokens[] = T_CLOSURE; + $tokens[] = T_FN; $tokens[] = T_VARIABLE; return $tokens; @@ -102,7 +104,9 @@ public function process(File $phpcsFile, $stackPtr) $error = 'PHP property type declarations must be lowercase; expected "%s" but found "%s"'; $errorCode = 'PropertyTypeFound'; - if (strpos($type, '|') !== false) { + if ($props['type_token'] === T_TYPE_INTERSECTION) { + // Intersection types don't support simple types. + } else if (strpos($type, '|') !== false) { $this->processUnionType( $phpcsFile, $props['type_token'], @@ -131,7 +135,9 @@ public function process(File $phpcsFile, $stackPtr) $error = 'PHP return type declarations must be lowercase; expected "%s" but found "%s"'; $errorCode = 'ReturnTypeFound'; - if (strpos($returnType, '|') !== false) { + if ($props['return_type_token'] === T_TYPE_INTERSECTION) { + // Intersection types don't support simple types. + } else if (strpos($returnType, '|') !== false) { $this->processUnionType( $phpcsFile, $props['return_type_token'], @@ -161,7 +167,9 @@ public function process(File $phpcsFile, $stackPtr) $error = 'PHP parameter type declarations must be lowercase; expected "%s" but found "%s"'; $errorCode = 'ParamTypeFound'; - if (strpos($typeHint, '|') !== false) { + if ($param['type_hint_token'] === T_TYPE_INTERSECTION) { + // Intersection types don't support simple types. + } else if (strpos($typeHint, '|') !== false) { $this->processUnionType( $phpcsFile, $param['type_hint_token'], diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php index 1519aa13..85e717bc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php @@ -33,7 +33,10 @@ class SyntaxSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php index 54aa07f2..2740884b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php @@ -10,30 +10,13 @@ namespace PHP_CodeSniffer\Standards\Generic\Sniffs\PHP; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; -class UpperCaseConstantSniff implements Sniff +class UpperCaseConstantSniff extends LowerCaseConstantSniff { /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() - { - return [ - T_TRUE, - T_FALSE, - T_NULL, - ]; - - }//end register() - - - /** - * Processes this sniff, when one of its tokens is encountered. + * Processes a non-type declaration constant. * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the @@ -41,11 +24,12 @@ public function register() * * @return void */ - public function process(File $phpcsFile, $stackPtr) + protected function processConstant(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $keyword = $tokens[$stackPtr]['content']; $expected = strtoupper($keyword); + if ($keyword !== $expected) { if ($keyword === strtolower($keyword)) { $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'lower'); @@ -67,7 +51,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'PHP constant case', 'upper'); } - }//end process() + }//end processConstant() }//end class diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/VersionControl/GitMergeConflictSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/VersionControl/GitMergeConflictSniff.php index e25d556b..83265b2e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/VersionControl/GitMergeConflictSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/VersionControl/GitMergeConflictSniff.php @@ -34,7 +34,10 @@ class GitMergeConflictSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php index 4fe89e76..bbdbfe0a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php @@ -41,7 +41,10 @@ class DisallowSpaceIndentSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php index a50e9f92..2140e55e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php @@ -41,7 +41,10 @@ class DisallowTabIndentSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() @@ -73,6 +76,8 @@ public function process(File $phpcsFile, $stackPtr) T_DOC_COMMENT_WHITESPACE => true, T_DOC_COMMENT_STRING => true, T_COMMENT => true, + T_END_HEREDOC => true, + T_END_NOWDOC => true, ]; for ($i = 0; $i < $phpcsFile->numTokens; $i++) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php index a0144919..7fd60484 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -142,12 +142,13 @@ public function process(File $phpcsFile, $stackPtr) } } - $lastOpenTag = $stackPtr; - $lastCloseTag = null; - $openScopes = []; - $adjustments = []; - $setIndents = []; - $disableExactEnd = 0; + $lastOpenTag = $stackPtr; + $lastCloseTag = null; + $openScopes = []; + $adjustments = []; + $setIndents = []; + $disableExactStack = []; + $disableExactEnd = 0; $tokens = $phpcsFile->getTokens(); $first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr); @@ -232,6 +233,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS && isset($tokens[$i]['parenthesis_closer']) === true ) { + $disableExactStack[$tokens[$i]['parenthesis_closer']] = $tokens[$i]['parenthesis_closer']; $disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']); if ($this->debug === true) { $line = $tokens[$i]['line']; @@ -616,11 +618,11 @@ public function process(File $phpcsFile, $stackPtr) // Scope closers reset the required indent to the same level as the opening condition. if (($checkToken !== null - && isset($openScopes[$checkToken]) === true + && (isset($openScopes[$checkToken]) === true || (isset($tokens[$checkToken]['scope_condition']) === true && isset($tokens[$checkToken]['scope_closer']) === true && $tokens[$checkToken]['scope_closer'] === $checkToken - && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line'])) + && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))) || ($checkToken === null && isset($openScopes[$i]) === true) ) { @@ -802,9 +804,17 @@ public function process(File $phpcsFile, $stackPtr) && isset($tokens[$checkToken]['scope_opener']) === true ) { $exact = true; + if ($disableExactEnd > $checkToken) { - if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactEnd]['conditions']) { - $exact = false; + foreach ($disableExactStack as $disableExactStackEnd) { + if ($disableExactStackEnd < $checkToken) { + continue; + } + + if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactStackEnd]['conditions']) { + $exact = false; + break; + } } } @@ -1035,6 +1045,7 @@ public function process(File $phpcsFile, $stackPtr) // Don't check indents exactly between arrays as they tend to have custom rules. if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) { + $disableExactStack[$tokens[$i]['bracket_closer']] = $tokens[$i]['bracket_closer']; $disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']); if ($this->debug === true) { $line = $tokens[$i]['line']; @@ -1056,7 +1067,6 @@ public function process(File $phpcsFile, $stackPtr) ) { if ($this->debug === true) { $line = $tokens[$i]['line']; - $type = $tokens[$disableExactEnd]['type']; echo "Here/nowdoc found on line $line".PHP_EOL; } @@ -1325,11 +1335,14 @@ public function process(File $phpcsFile, $stackPtr) continue; }//end if - // Closing an anon class or function. + // Closing an anon class, closure, or match. + // Each may be returned, which can confuse control structures that + // use return as a closer, like CASE statements. if (isset($tokens[$i]['scope_condition']) === true && $tokens[$i]['scope_closer'] === $i && ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE - || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS) + || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS + || $tokens[$tokens[$i]['scope_condition']]['code'] === T_MATCH) ) { if ($this->debug === true) { $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2))); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php index 3146717e..070bbcd1 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.php @@ -62,6 +62,11 @@ public function process(File $phpcsFile, $stackPtr) return; } + if ($tokens[$nextNonEmpty]['code'] === T_CLOSE_PARENTHESIS) { + // Ignore PHP 8.1 first class callable syntax. + return; + } + if ($this->ignoreNewlines === true && $tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line'] ) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc index af56fd49..075fc34c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc @@ -98,3 +98,16 @@ $array = [ match ($test) { 1 => 'a', 2 => 'b' } => 'dynamic keys, woho!', ]; + +// Ensure that PHP 8.0 named parameters don't affect the sniff. +$array = [ + functionCall( + name: $value + ), +]; + +$array = [ + functionCall( + name: $value + ), +]; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed index 49514595..505de5f7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed @@ -99,3 +99,16 @@ $array = [ match ($test) { 1 => 'a', 2 => 'b' } => 'dynamic keys, woho!', ]; + +// Ensure that PHP 8.0 named parameters don't affect the sniff. +$array = [ + functionCall( + name: $value + ), +]; + +$array = [ + functionCall( + name: $value + ), +]; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php index 0b99f2d6..4861041f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.php @@ -26,24 +26,25 @@ class ArrayIndentUnitTest extends AbstractSniffUnitTest public function getErrorList() { return [ - 14 => 1, - 15 => 1, - 17 => 1, - 30 => 1, - 31 => 1, - 33 => 1, - 41 => 1, - 62 => 1, - 63 => 1, - 69 => 1, - 77 => 1, - 78 => 1, - 79 => 1, - 85 => 1, - 86 => 1, - 87 => 1, - 88 => 1, - 98 => 1, + 14 => 1, + 15 => 1, + 17 => 1, + 30 => 1, + 31 => 1, + 33 => 1, + 41 => 1, + 62 => 1, + 63 => 1, + 69 => 1, + 77 => 1, + 78 => 1, + 79 => 1, + 85 => 1, + 86 => 1, + 87 => 1, + 88 => 1, + 98 => 1, + 110 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.php index 02976810..af1d9c9a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.php @@ -35,7 +35,6 @@ public function getErrorList($testFile='') 6 => 1, 7 => 1, 12 => 1, - 13 => 1, ]; case 'DisallowLongArraySyntaxUnitTest.2.inc': return [ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc index d0c136cb..91ab9d39 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc @@ -5,7 +5,10 @@ interface MyInterface {} interface YourInterface {} trait MyTrait {} trait YourTrait {} +enum MyEnum {} +enum YourEnum {} class MyClass {} interface MyInterface {} trait MyTrait {} -?> \ No newline at end of file +enum MyEnum {} +?> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc index e6f92eb1..6829748a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc @@ -2,4 +2,5 @@ class MyClass {} interface MyInterface {} trait MyTrait {} +enum MyEnum {} ?> \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php index b3b3edb5..68982f86 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php @@ -45,9 +45,10 @@ public function getWarningList($testFile='') switch ($testFile) { case 'DuplicateClassNameUnitTest.1.inc': return [ - 8 => 1, - 9 => 1, 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, ]; break; case 'DuplicateClassNameUnitTest.2.inc': @@ -55,6 +56,7 @@ public function getWarningList($testFile='') 2 => 1, 3 => 1, 4 => 1, + 5 => 1, ]; break; case 'DuplicateClassNameUnitTest.5.inc': diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc index 8147b4c7..fd3abc03 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc @@ -89,3 +89,7 @@ class Test_Class_Bad_G /*some comment*/ { } + +enum Test_Enum +{ +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed index 406eb230..a755ae47 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed @@ -89,3 +89,7 @@ class Test_Class_Bad_G /*some comment*/ { } + +enum Test_Enum { + +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php index 61cd4c9e..c357afc9 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php @@ -38,6 +38,7 @@ public function getErrorList() 70 => 1, 79 => 1, 90 => 1, + 94 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc index 1a6ab690..fb4a7380 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc @@ -253,3 +253,22 @@ for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++); if ($this->valid(fn(): bool => 2 > 1)) { } + +// Issue 3345. +function testMultiCatch() +{ + if (true) + try { + } catch (\LogicException $e) { + } catch (\Exception $e) { + } +} + +function testFinally() +{ + if (true) + try { + } catch (\LogicException $e) { + } finally { + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed index 4cd8ee4d..d80a3265 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed @@ -286,3 +286,24 @@ for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++); if ($this->valid(fn(): bool => 2 > 1)) { } + +// Issue 3345. +function testMultiCatch() +{ + if (true) { + try { + } catch (\LogicException $e) { + } catch (\Exception $e) { + } + } +} + +function testFinally() +{ + if (true) { + try { + } catch (\LogicException $e) { + } finally { + } + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php index 92888b85..a9c4f4f8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php @@ -71,6 +71,8 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.1.inc') 236 => 1, 238 => 1, 242 => 1, + 260 => 1, + 269 => 1, ]; case 'InlineControlStructureUnitTest.js': diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.6.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.6.inc new file mode 100644 index 00000000..4f2e47af --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.6.inc @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.7.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.7.inc.fixed new file mode 100644 index 00000000..d3c19fee --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.7.inc.fixed @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.8.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.8.inc new file mode 100644 index 00000000..d3c19fee --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.8.inc @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.php index b97e8ab2..f5ab9ffa 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNewlineUnitTest.php @@ -33,6 +33,9 @@ public function getErrorList($testFile='') case 'EndFileNewlineUnitTest.3.css': case 'EndFileNewlineUnitTest.4.inc': return [2 => 1]; + case 'EndFileNewlineUnitTest.6.inc': + case 'EndFileNewlineUnitTest.7.inc': + return [1 => 1]; default: return []; }//end switch diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.10.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.10.inc new file mode 100644 index 00000000..884aad1b --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.10.inc @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.8.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.8.inc new file mode 100644 index 00000000..1f876092 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.8.inc @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.9.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.9.inc.fixed new file mode 100644 index 00000000..884aad1b --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.9.inc.fixed @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.php index 23c9980b..88dc2f88 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/EndFileNoNewlineUnitTest.php @@ -37,6 +37,9 @@ public function getErrorList($testFile='') case 'EndFileNoNewlineUnitTest.2.js': case 'EndFileNoNewlineUnitTest.6.inc': return [2 => 1]; + case 'EndFileNoNewlineUnitTest.8.inc': + case 'EndFileNoNewlineUnitTest.9.inc': + return [1 => 1]; default: return []; }//end switch diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.3.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.3.inc new file mode 100644 index 00000000..ee44f511 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.3.inc @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.4.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.4.inc new file mode 100644 index 00000000..ee44f511 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.4.inc @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.php index f47fef6d..269102dd 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.php @@ -25,7 +25,7 @@ protected function shouldSkipTest() // PEAR doesn't preserve the executable flag, so skip // tests when running in a PEAR install. // Also skip on Windows which doesn't have the concept of executable files. - return ($GLOBALS['PHP_CODESNIFFER_PEAR'] || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')); + return ($GLOBALS['PHP_CODESNIFFER_PEAR'] || stripos(PHP_OS, 'WIN') === 0); }//end shouldSkipTest() @@ -44,6 +44,7 @@ public function getErrorList($testFile='') { switch ($testFile) { case 'ExecutableFileUnitTest.2.inc': + case 'ExecutableFileUnitTest.4.inc': return [1 => 1]; default: return []; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.1.inc similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc.fixed rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.1.inc diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.1.inc.fixed similarity index 88% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.1.inc.fixed index a2d3ed20..b143fb4c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.1.inc.fixed @@ -1,18 +1,18 @@ - - - - - -group('a.id, - uc.name, - ag.title, - ua.name' - ); -} + + + + + +group('a.id, + uc.name, + ag.title, + ua.name' + ); +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc new file mode 100644 index 00000000..260d7fd2 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc @@ -0,0 +1,5 @@ + + + +
...more HTML...
+ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc.fixed new file mode 100644 index 00000000..260d7fd2 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.2.inc.fixed @@ -0,0 +1,5 @@ + + + +
...more HTML...
+ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.css b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.css index a8c96255..c182ac4d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.css +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.css @@ -1,3 +1,3 @@ -#login-container { - margin-left: -225px; -} +#login-container { + margin-left: -225px; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.js b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.js index 49c58d8e..02600992 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.js +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LineEndingsUnitTest.js @@ -1,2 +1,2 @@ -alert('hi'); -alert('hi'); +alert('hi'); +alert('hi'); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.1.inc similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.inc rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.1.inc diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.2.inc new file mode 100644 index 00000000..708d19c6 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.2.inc @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php index 4b4bc974..f67a40a3 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/LowercasedFilenameUnitTest.php @@ -21,11 +21,19 @@ class LowercasedFilenameUnitTest extends AbstractSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * + * @param string $testFile The name of the file being tested. + * * @return array */ - public function getErrorList() + public function getErrorList($testFile='') { - return [1 => 1]; + switch ($testFile) { + case 'LowercasedFilenameUnitTest.1.inc': + case 'LowercasedFilenameUnitTest.2.inc': + return [1 => 1]; + default: + return []; + } }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.inc index 94cebb4e..9f76d5d8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.inc @@ -12,10 +12,15 @@ class baz { } trait barTrait { - + } interface barInterface { } -?> \ No newline at end of file + +enum barEnum { + +} + +?> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.php index f429f980..36a4bb93 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Files/OneObjectStructurePerFileUnitTest.php @@ -30,6 +30,7 @@ public function getErrorList() 10 => 1, 14 => 1, 18 => 1, + 22 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc index 286fdf1e..ec71d4b6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc @@ -468,3 +468,37 @@ $resource = new class() { $one <<= 8; $onetwothree = 3; + +// Issue 3326. +class Test +{ + public const DEFAULT = 'default'; + public const SOS = 'sos'; + public const HELP = 'help'; + + protected static $thisIsAReallyLongVariableName = []; +} + +// Issue #3460. +function issue3460_invalid() { + $a = static function ($variables = false) use ($foo) { + return $variables; + }; + $b = $a; +} + +function issue3460_valid() { + $a = static function ($variables = false) use ($foo) { + return $variables; + }; + $b = $a; +} + +function makeSureThatAssignmentWithinClosureAreStillHandled() { + $a = static function ($variables = []) use ($temp) { + $a = 'foo'; + $bar = 'bar'; + $longer = 'longer'; + return $variables; + }; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed index f08312dd..137a8ef9 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed @@ -468,3 +468,37 @@ $resource = new class() { $one <<= 8; $onetwothree = 3; + +// Issue 3326. +class Test +{ + public const DEFAULT = 'default'; + public const SOS = 'sos'; + public const HELP = 'help'; + + protected static $thisIsAReallyLongVariableName = []; +} + +// Issue #3460. +function issue3460_invalid() { + $a = static function ($variables = false) use ($foo) { + return $variables; + }; + $b = $a; +} + +function issue3460_valid() { + $a = static function ($variables = false) use ($foo) { + return $variables; + }; + $b = $a; +} + +function makeSureThatAssignmentWithinClosureAreStillHandled() { + $a = static function ($variables = []) use ($temp) { + $a = 'foo'; + $bar = 'bar'; + $longer = 'longer'; + return $variables; + }; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php index eef66a5d..23f2f9a7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php @@ -118,6 +118,9 @@ public function getWarningList($testFile='MultipleStatementAlignmentUnitTest.inc 442 => 1, 443 => 1, 454 => 1, + 487 => 1, + 499 => 1, + 500 => 1, ]; break; case 'MultipleStatementAlignmentUnitTest.js': diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc index c46517df..7c86a89f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc @@ -153,3 +153,12 @@ $foobar = functionCallAnonClassParam( $result = myFunction(param1: $arg1, param2: $arg2); $result = myFunction(param1: $arg1 , param2:$arg2); $result = myFunction(param1: $arg1, param2:$arg2, param3: $arg3,param4:$arg4, param5:$arg5); + +class Testing extends Bar +{ + public static function baz($foo, $bar) + { + $a = new parent($foo, $bar); + $a = new parent($foo ,$bar); + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed index 1b51933e..8c980072 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed @@ -153,3 +153,12 @@ $foobar = functionCallAnonClassParam( $result = myFunction(param1: $arg1, param2: $arg2); $result = myFunction(param1: $arg1, param2:$arg2); $result = myFunction(param1: $arg1, param2:$arg2, param3: $arg3, param4:$arg4, param5:$arg5); + +class Testing extends Bar +{ + public static function baz($foo, $bar) + { + $a = new parent($foo, $bar); + $a = new parent($foo, $bar); + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php index 9f83fc9b..789b60b3 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php @@ -54,6 +54,7 @@ public function getErrorList() 134 => 1, 154 => 2, 155 => 1, + 162 => 2, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc index 854c3888..3ae3b1ed 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc @@ -236,3 +236,28 @@ function myFunction($a, $lot, $of, $params) : array /* comment */ { return null; } + +class Issue3357 +{ + public function extraLine(string: $a): void + + { + // code here. + } +} + +function issue3357WithoutIndent(string: $a): void + + +{ + // code here. +} + +class Issue3357WithComment +{ + public function extraLine(string: $a): void + // Comment. + { + // code here. + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed index c1f904b2..f164c493 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc.fixed @@ -256,3 +256,25 @@ function myFunction($a, $lot, $of, $params) { return null; } + +class Issue3357 +{ + public function extraLine(string: $a): void + { + // code here. + } +} + +function issue3357WithoutIndent(string: $a): void +{ + // code here. +} + +class Issue3357WithComment +{ + public function extraLine(string: $a): void + // Comment. + { + // code here. + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php index 27eaa4fd..10af4fd5 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php @@ -58,6 +58,9 @@ public function getErrorList() 220 => 1, 231 => 1, 236 => 1, + 244 => 1, + 252 => 1, + 260 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc index 151ffed6..494dcc76 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc @@ -79,9 +79,11 @@ function complexityTwenty() switch ($condition) { case '1': - if ($condition) { - } else if ($cond) { - } + do { + if ($condition) { + } else if ($cond) { + } + } while ($cond); break; case '2': while ($cond) { @@ -116,9 +118,11 @@ function complexityTwenty() function complexityTwentyOne() { while ($condition === true) { - if ($condition) { - } else if ($cond) { - } + do { + if ($condition) { + } else if ($cond) { + } + } while ($cond); } switch ($condition) { @@ -157,4 +161,294 @@ function complexityTwentyOne() } } + +function complexityTenWithTernaries() +{ + $value1 = (empty($condition1)) ? $value1A : $value1B; + $value2 = (empty($condition2)) ? $value2A : $value2B; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityElevenWithTernaries() +{ + $value1 = (empty($condition1)) ? $value1A : $value1B; + $value2 = (empty($condition2)) ? $value2A : $value2B; + $value3 = (empty($condition3)) ? $value3A : $value3B; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityTenWithNestedTernaries() +{ + $value1 = true ? $value1A : false ? $value1B : $value1C; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityElevenWithNestedTernaries() +{ + $value1 = (empty($condition1)) ? $value1A : $value1B; + $value2 = true ? $value2A : false ? $value2B : $value2C; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityTenWithNullCoalescence() +{ + $value1 = $value1A ?? $value1B; + $value2 = $value2A ?? $value2B; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityElevenWithNullCoalescence() +{ + $value1 = $value1A ?? $value1B; + $value2 = $value2A ?? $value2B; + $value3 = $value3A ?? $value3B; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityTenWithNestedNullCoalescence() +{ + $value1 = $value1A ?? $value1B ?? $value1C; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityElevenWithNestedNullCoalescence() +{ + $value1 = $value1A ?? $value1B; + $value2 = $value2A ?? $value2B ?? $value2C; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityTenWithNullCoalescenceAssignment() +{ + $value1 ??= $default1; + $value2 ??= $default2; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityElevenWithNullCoalescenceAssignment() +{ + $value1 ??= $default1; + $value2 ??= $default2; + $value3 ??= $default3; + + switch ($condition) { + case '1': + if ($condition) { + } else if ($cond) { + } + break; + case '2': + while ($cond) { + echo 'hi'; + } + break; + case '3': + break; + default: + break; + } +} + + +function complexityFiveWithMatch() +{ + return match(strtolower(substr($monthName, 0, 3))){ + 'apr', 'jun', 'sep', 'nov' => 30, + 'jan', 'mar', 'may', 'jul', 'aug', 'oct', 'dec' => 31, + 'feb' => is_leap_year($year) ? 29 : 28, + default => throw new InvalidArgumentException("Invalid month"), + } +} + + +function complexityFourteenWithMatch() +{ + return match(strtolower(substr($monthName, 0, 3))) { + 'jan' => 31, + 'feb' => is_leap_year($year) ? 29 : 28, + 'mar' => 31, + 'apr' => 30, + 'may' => 31, + 'jun' => 30, + 'jul' => 31, + 'aug' => 31, + 'sep' => 30, + 'oct' => 31, + 'nov' => 30, + 'dec' => 31, + default => throw new InvalidArgumentException("Invalid month"), + }; +} + + +function complexitySevenWithNullSafeOperator() +{ + $foo = $object1->getX()?->getY()?->getZ(); + $bar = $object2->getX()?->getY()?->getZ(); + $baz = $object3->getX()?->getY()?->getZ(); +} + + +function complexityElevenWithNullSafeOperator() +{ + $foo = $object1->getX()?->getY()?->getZ(); + $bar = $object2->getX()?->getY()?->getZ(); + $baz = $object3->getX()?->getY()?->getZ(); + $bacon = $object4->getX()?->getY()?->getZ(); + $bits = $object5->getX()?->getY()?->getZ(); +} + ?> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php index e8099317..d3860dff 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php @@ -25,7 +25,7 @@ class CyclomaticComplexityUnitTest extends AbstractSniffUnitTest */ public function getErrorList() { - return [116 => 1]; + return [118 => 1]; }//end getErrorList() @@ -41,8 +41,15 @@ public function getErrorList() public function getWarningList() { return [ - 45 => 1, - 72 => 1, + 45 => 1, + 72 => 1, + 189 => 1, + 237 => 1, + 285 => 1, + 333 => 1, + 381 => 1, + 417 => 1, + 445 => 1, ]; }//end getWarningList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc index 9bda1147..8441060d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.inc @@ -165,3 +165,21 @@ abstract class My_Class { public function my_class() {} public function _MY_CLASS() {} } + +enum Suit: string implements Colorful, CardGame { + // Magic methods. + function __call($name, $args) {} + static function __callStatic($name, $args) {} + function __invoke() {} + + // Valid Method Name. + public function getSomeValue() {} + + // Double underscore non-magic methods not allowed. + function __myFunction() {} + function __my_function() {} + + // Non-camelcase. + public function parseMyDSN() {} + public function get_some_value() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php index 502498d8..3d0320c3 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.php @@ -63,6 +63,10 @@ public function getErrorList() 147 => 2, 158 => 1, 159 => 1, + 179 => 1, + 180 => 2, + 183 => 1, + 184 => 1, ]; return $errors; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/InterfaceNameSuffixUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/InterfaceNameSuffixUnitTest.php index b4d9696f..be23f7a6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/InterfaceNameSuffixUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/NamingConventions/InterfaceNameSuffixUnitTest.php @@ -10,7 +10,7 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -class InterfaceSuffixNameUnitTest extends AbstractSniffUnitTest +class InterfaceNameSuffixUnitTest extends AbstractSniffUnitTest { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.1.inc similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.inc rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.1.inc diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.2.inc new file mode 100644 index 00000000..fc896ed1 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.2.inc @@ -0,0 +1,5 @@ + +Bold text + +Italic text + */ - public function getErrorList() + public function getErrorList($testFile='') { - return [9 => 1]; + switch ($testFile) { + case 'ClosingPHPTagUnitTest.1.inc': + return [9 => 1]; + case 'ClosingPHPTagUnitTest.2.inc': + return [5 => 1]; + break; + default: + return []; + break; + } }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/DisallowRequestSuperglobalUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/DisallowRequestSuperglobalUnitTest.inc new file mode 100644 index 00000000..974e45c0 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/DisallowRequestSuperglobalUnitTest.inc @@ -0,0 +1,16 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc index 63aea518..0307a055 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc @@ -81,3 +81,20 @@ var_dump(MyClass::TRUE); function tRUE() {} $input->getFilterChain()->attachByName('Null', ['type' => Null::TYPE_STRING]); + +// Issue #3332 - ignore type declarations, but not default values. +class TypedThings { + const MYCONST = FALSE; + + public int|FALSE $int = FALSE; + public Type|NULL $int = new MyObj(NULL); + + private function typed(int|FALSE $param = NULL, Type|NULL $obj = new MyObj(FALSE)) : string|FALSE|NULL + { + if (TRUE === FALSE) { + return NULL; + } + } +} + +$cl = function (int|FALSE $param = NULL, Type|NULL $obj = new MyObj(FALSE)) : string|FALSE|NULL {}; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc.fixed index b3c3d8a1..3a6b094c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc.fixed @@ -81,3 +81,20 @@ var_dump(MyClass::TRUE); function tRUE() {} $input->getFilterChain()->attachByName('Null', ['type' => Null::TYPE_STRING]); + +// Issue #3332 - ignore type declarations, but not default values. +class TypedThings { + const MYCONST = false; + + public int|FALSE $int = false; + public Type|NULL $int = new MyObj(null); + + private function typed(int|FALSE $param = null, Type|NULL $obj = new MyObj(false)) : string|FALSE|NULL + { + if (true === false) { + return null; + } + } +} + +$cl = function (int|FALSE $param = null, Type|NULL $obj = new MyObj(false)) : string|FALSE|NULL {}; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php index 85e8f701..2fb2d6f6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php @@ -30,20 +30,27 @@ public function getErrorList($testFile='LowerCaseConstantUnitTest.inc') switch ($testFile) { case 'LowerCaseConstantUnitTest.inc': return [ - 7 => 1, - 10 => 1, - 15 => 1, - 16 => 1, - 23 => 1, - 26 => 1, - 31 => 1, - 32 => 1, - 39 => 1, - 42 => 1, - 47 => 1, - 48 => 1, - 70 => 1, - 71 => 1, + 7 => 1, + 10 => 1, + 15 => 1, + 16 => 1, + 23 => 1, + 26 => 1, + 31 => 1, + 32 => 1, + 39 => 1, + 42 => 1, + 47 => 1, + 48 => 1, + 70 => 1, + 71 => 1, + 87 => 1, + 89 => 1, + 90 => 1, + 92 => 2, + 94 => 2, + 95 => 1, + 100 => 2, ]; break; case 'LowerCaseConstantUnitTest.js': diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc index 8d003c3b..37579d32 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc @@ -35,5 +35,14 @@ $r = Match ($x) { DEFAULT, => 3, }; +class Reading { + Public READOnly int $var; +} + +EnuM ENUM: string +{ + Case HEARTS; +} + __HALT_COMPILER(); // An exception due to phar support. function diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc.fixed index bbe76b9e..7063327a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.inc.fixed @@ -35,5 +35,14 @@ $r = match ($x) { default, => 3, }; +class Reading { + public readonly int $var; +} + +enum ENUM: string +{ + case HEARTS; +} + __HALT_COMPILER(); // An exception due to phar support. function diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.php index b272196b..6d08e127 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseKeywordUnitTest.php @@ -40,6 +40,9 @@ public function getErrorList() 31 => 1, 32 => 1, 35 => 1, + 39 => 2, + 42 => 1, + 44 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc index 8e2dca17..011adcd5 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc @@ -81,3 +81,14 @@ class ConstructorPropertyPromotionWithTypes { class ConstructorPropertyPromotionAndNormalParams { public function __construct(public Int $promotedProp, ?Int $normalArg) {} } + +function (): NeVeR { + exit; +}; + +function intersectionParamTypes (\Package\ClassName&\Package\Other_Class $var) {} + +function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class {} + +$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; +$arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed index 6e03f7c2..d866101b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed @@ -81,3 +81,14 @@ class ConstructorPropertyPromotionWithTypes { class ConstructorPropertyPromotionAndNormalParams { public function __construct(public int $promotedProp, ?int $normalArg) {} } + +function (): never { + exit; +}; + +function intersectionParamTypes (\Package\ClassName&\Package\Other_Class $var) {} + +function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class {} + +$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; +$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php index d447e8f4..fa05aba6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php @@ -65,6 +65,8 @@ public function getErrorList() 74 => 3, 78 => 3, 82 => 2, + 85 => 1, + 94 => 5, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.1.inc similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.inc rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.1.inc diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.2.inc new file mode 100644 index 00000000..11f8a589 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.2.inc @@ -0,0 +1,3 @@ + +
text
+ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.php index d8cd7efa..98d205ce 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/SyntaxUnitTest.php @@ -22,11 +22,21 @@ class SyntaxUnitTest extends AbstractSniffUnitTest * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * + * @param string $testFile The name of the file being tested. + * * @return array */ - public function getErrorList() + public function getErrorList($testFile='') { - return [3 => 1]; + switch ($testFile) { + case 'SyntaxUnitTest.1.inc': + case 'SyntaxUnitTest.2.inc': + return [3 => 1]; + break; + default: + return []; + break; + } }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc index 965bf3b5..30c6d298 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc @@ -78,4 +78,21 @@ class MyClass var_dump(MyClass::true); -function true() {} \ No newline at end of file +function true() {} + +// Issue #3332 - ignore type declarations, but not default values. +class TypedThings { + const MYCONST = false; + + public int|false $int = false; + public Type|null $int = new MyObj(null); + + private function typed(int|false $param = null, Type|null $obj = new MyObj(false)) : string|false|null + { + if (true === false) { + return null; + } + } +} + +$cl = function (int|false $param = null, Type|null $obj = new MyObj(false)) : string|false|null {}; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc.fixed index ae83dc91..7705198c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc.fixed @@ -78,4 +78,21 @@ class MyClass var_dump(MyClass::true); -function true() {} \ No newline at end of file +function true() {} + +// Issue #3332 - ignore type declarations, but not default values. +class TypedThings { + const MYCONST = FALSE; + + public int|false $int = FALSE; + public Type|null $int = new MyObj(NULL); + + private function typed(int|false $param = NULL, Type|null $obj = new MyObj(FALSE)) : string|false|null + { + if (TRUE === FALSE) { + return NULL; + } + } +} + +$cl = function (int|false $param = NULL, Type|null $obj = new MyObj(FALSE)) : string|false|null {}; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php index 0bdafe6a..30e57763 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php @@ -40,6 +40,13 @@ public function getErrorList() 48 => 1, 70 => 1, 71 => 1, + 85 => 1, + 87 => 1, + 88 => 1, + 90 => 2, + 92 => 2, + 93 => 1, + 98 => 2, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.7.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.7.inc new file mode 100644 index 00000000..85cae1fd --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.7.inc @@ -0,0 +1,19 @@ + +
+<<<<<<< HEAD +

Testing a merge conflict.

+======= +

Another text string.

+>>>>>>> ref/heads/feature-branch +
+ + +
+<<<<<<< HEAD +

+======= +

+>>>>>>> ref/heads/feature-branch +
+ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.php index a36caafb..50986f48 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/VersionControl/GitMergeConflictUnitTest.php @@ -99,6 +99,16 @@ public function getErrorList($testFile='GitMergeConflictUnitTest.1.inc') 32 => 1, ]; + case 'GitMergeConflictUnitTest.7.inc': + return [ + 3 => 1, + 5 => 1, + 7 => 1, + 12 => 1, + 14 => 1, + 16 => 1, + ]; + case 'GitMergeConflictUnitTest.1.css': return [ 3 => 1, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc index bad3998f..2399a387 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc @@ -163,3 +163,15 @@ $a = ( if (true) {} ( 1+2) === 3 ? $a = 1 : $a = 2; class A {} ( 1+2) === 3 ? $a = 1 : $a = 2; function foo() {} ( 1+2) === 3 ? $a = 1 : $a = 2; + +// Issue #3618. +class NonArbitraryParenthesesWithKeywords { + public static function baz( $foo, $bar ) { + $a = new self(); + $b = new parent(); + $c = new static(); + + // self/static are already tested above, round line 45. + $d = new parent( $foo,$bar ); + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed index 08fcd624..9162728e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed @@ -151,3 +151,15 @@ $a = ( if (true) {} (1+2) === 3 ? $a = 1 : $a = 2; class A {} (1+2) === 3 ? $a = 1 : $a = 2; function foo() {} (1+2) === 3 ? $a = 1 : $a = 2; + +// Issue #3618. +class NonArbitraryParenthesesWithKeywords { + public static function baz( $foo, $bar ) { + $a = new self(); + $b = new parent(); + $c = new static(); + + // self/static are already tested above, round line 45. + $d = new parent( $foo,$bar ); + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.3.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.3.inc new file mode 100644 index 00000000..4df731a3 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowSpaceIndentUnitTest.3.inc @@ -0,0 +1,19 @@ + + + + Foo + + +
+
+
+
+
+
+ + + + + + + Foo + + +
+
+
+
+
+
+ + + + 1, ]; break; + case 'DisallowSpaceIndentUnitTest.3.inc': + return [ + 2 => 1, + 5 => 1, + 10 => 1, + 12 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + ]; + break; case 'DisallowSpaceIndentUnitTest.js': return [3 => 1]; break; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc.fixed similarity index 100% rename from vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc.fixed rename to vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.1.inc.fixed diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.2.inc new file mode 100644 index 00000000..4df731a3 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.2.inc @@ -0,0 +1,19 @@ + + + + Foo + + +
+
+
+
+
+
+ + + + + + + Foo + + +
+
+
+
+
+
+ + + + */ - public function getErrorList($testFile='DisallowTabIndentUnitTest.inc') + public function getErrorList($testFile='') { switch ($testFile) { - case 'DisallowTabIndentUnitTest.inc': + case 'DisallowTabIndentUnitTest.1.inc': return [ 5 => 2, 9 => 1, @@ -83,23 +83,46 @@ public function getErrorList($testFile='DisallowTabIndentUnitTest.inc') 92 => 1, 93 => 1, ]; - break; + + case 'DisallowTabIndentUnitTest.2.inc': + return [ + 6 => 1, + 7 => 1, + 8 => 1, + 9 => 1, + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 19 => 1, + ]; + + case 'DisallowTabIndentUnitTest.3.inc': + if (\PHP_VERSION_ID >= 70300) { + return [ + 7 => 1, + 13 => 1, + ]; + } + + // PHP 7.2 or lower: PHP version which doesn't support flexible heredocs/nowdocs yet. + return []; + case 'DisallowTabIndentUnitTest.js': return [ 3 => 1, 5 => 1, 6 => 1, ]; - break; + case 'DisallowTabIndentUnitTest.css': return [ 1 => 1, 2 => 1, ]; - break; + default: return []; - break; }//end switch }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc index 6d63a64a..4061aff5 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc @@ -1547,6 +1547,38 @@ $foo = match ($type) { ], }; +$a = [ + 'a' => [ + 'a' => fn () => foo() + ], + 'a' => [ + 'a' => 'a', + ] +]; + +switch ($foo) { + case 'a': + $foo = match ($foo) { + 'bar' => 'custom_1', + default => 'a' + }; + return $foo; + case 'b': + return match ($foo) { + 'bar' => 'custom_1', + default => 'b' + }; + default: + return 'default'; +} + +foo(function ($foo) { + return [ + match ($foo) { + } + ]; +}); + /* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */ ?> @@ -1555,7 +1587,7 @@ $foo = match ($type) { [ + 'a' => fn () => foo() + ], + 'a' => [ + 'a' => 'a', + ] +]; + +switch ($foo) { + case 'a': + $foo = match ($foo) { + 'bar' => 'custom_1', + default => 'a' + }; + return $foo; + case 'b': + return match ($foo) { + 'bar' => 'custom_1', + default => 'b' + }; + default: + return 'default'; +} + +foo(function ($foo) { + return [ + match ($foo) { + } + ]; +}); + /* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */ ?> @@ -1555,7 +1587,7 @@ $foo = match ($type) { [ + 'a' => fn () => foo() + ], + 'a' => [ + 'a' => 'a', + ] +]; + +switch ($foo) { + case 'a': + $foo = match ($foo) { + 'bar' => 'custom_1', + default => 'a' + }; + return $foo; + case 'b': + return match ($foo) { + 'bar' => 'custom_1', + default => 'b' + }; + default: + return 'default'; +} + +foo(function ($foo) { + return [ + match ($foo) { + } + ]; +}); + /* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */ ?> @@ -1555,7 +1587,7 @@ $foo = match ($type) { [ + 'a' => fn () => foo() + ], + 'a' => [ + 'a' => 'a', + ] +]; + +switch ($foo) { + case 'a': + $foo = match ($foo) { + 'bar' => 'custom_1', + default => 'a' + }; + return $foo; + case 'b': + return match ($foo) { + 'bar' => 'custom_1', + default => 'b' + }; + default: + return 'default'; +} + +foo(function ($foo) { + return [ + match ($foo) { + } + ]; +}); + /* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */ ?> @@ -1555,7 +1587,7 @@ $foo = match ($type) { 1, 1529 => 1, 1530 => 1, - 1558 => 1, - 1559 => 1, - 1560 => 1, - 1561 => 1, + 1590 => 1, + 1591 => 1, + 1592 => 1, + 1593 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc index edce4dcc..fb5c1814 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc @@ -67,7 +67,13 @@ function bar( & ... $spread ) { ); } +// Ignore PHP 8.1 first class callable declarations. +$map = array_map(strtolower(...), $map); + // phpcs:set Generic.WhiteSpace.SpreadOperatorSpacingAfter spacing 0 +// Ignore PHP 8.1 first class callable declarations. +$map = array_map(strtolower( ... ), $map); + // Intentional parse error. This has to be the last test in the file. function bar( ... diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc.fixed index efec7ac1..9388acfc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Tests/WhiteSpace/SpreadOperatorSpacingAfterUnitTest.inc.fixed @@ -62,7 +62,13 @@ function bar( & ... $spread ) { ); } +// Ignore PHP 8.1 first class callable declarations. +$map = array_map(strtolower(...), $map); + // phpcs:set Generic.WhiteSpace.SpreadOperatorSpacingAfter spacing 0 +// Ignore PHP 8.1 first class callable declarations. +$map = array_map(strtolower( ... ), $map); + // Intentional parse error. This has to be the last test in the file. function bar( ... diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/MySource/Tests/PHP/GetRequestDataUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/MySource/Tests/PHP/GetRequestDataUnitTest.inc new file mode 100644 index 00000000..7999763f --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/MySource/Tests/PHP/GetRequestDataUnitTest.inc @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php index a5b07a9e..dbd61f3d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php index ac3351e0..a01ea2cc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php index e0672ffe..6a445846 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php @@ -161,6 +161,7 @@ public function process(File $phpcsFile, $stackPtr) T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, T_FUNCTION, T_CLOSURE, T_PUBLIC, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php index 3c3dbfc4..408856fc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php @@ -68,11 +68,25 @@ public function process(File $phpcsFile, $stackPtr) return; } - $tokens = $phpcsFile->getTokens(); - $ignore = Tokens::$methodPrefixes; - $ignore[] = T_WHITESPACE; + $tokens = $phpcsFile->getTokens(); + $ignore = Tokens::$methodPrefixes; + $ignore[T_WHITESPACE] = T_WHITESPACE; + + for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) { + if (isset($ignore[$tokens[$commentEnd]['code']]) === true) { + continue; + } + + if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END + && isset($tokens[$commentEnd]['attribute_opener']) === true + ) { + $commentEnd = $tokens[$commentEnd]['attribute_opener']; + continue; + } + + break; + } - $commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); if ($tokens[$commentEnd]['code'] === T_COMMENT) { // Inline comments might just be closing comments for // control structures or functions instead of function comments @@ -106,8 +120,19 @@ public function process(File $phpcsFile, $stackPtr) } if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { - $error = 'There must be no blank lines after the function comment'; - $phpcsFile->addError($error, $commentEnd, 'SpacingAfter'); + for ($i = ($commentEnd + 1); $i < $stackPtr; $i++) { + if ($tokens[$i]['column'] !== 1) { + continue; + } + + if ($tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] !== $tokens[($i + 1)]['line'] + ) { + $error = 'There must be no blank lines after the function comment'; + $phpcsFile->addError($error, $commentEnd, 'SpacingAfter'); + break; + } + } } $commentStart = $tokens[$commentEnd]['comment_opener']; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php index 3a339abe..b5e8695c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php @@ -390,11 +390,14 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $ $padding = str_repeat(' ', $functionIndent); if ($foundFunctionIndent === 0) { $phpcsFile->fixer->addContentBefore($first, $padding); + } else if ($tokens[$first]['code'] === T_INLINE_HTML) { + $newContent = $padding.ltrim($tokens[$first]['content']); + $phpcsFile->fixer->replaceToken($first, $newContent); } else { $phpcsFile->fixer->replaceToken(($first - 1), $padding); } } - } + }//end if $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true); if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php index 98436294..bd59a7cd 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php @@ -456,19 +456,23 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct } // We changed lines, so this should be a whitespace indent token. - if ($tokens[$i]['code'] !== T_WHITESPACE) { - $foundIndent = 0; - } else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) { - // This is an empty line, so don't check the indent. - $foundIndent = $expectedIndent; - + $foundIndent = 0; + if ($tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] !== $tokens[($i + 1)]['line'] + ) { $error = 'Blank lines are not allowed in a multi-line '.$type.' declaration'; $fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine'); if ($fix === true) { $phpcsFile->fixer->replaceToken($i, ''); } - } else { + + // This is an empty line, so don't check the indent. + continue; + } else if ($tokens[$i]['code'] === T_WHITESPACE) { $foundIndent = $tokens[$i]['length']; + } else if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) { + $foundIndent = $tokens[$i]['length']; + ++$expectedIndent; } if ($expectedIndent !== $foundIndent) { @@ -503,6 +507,13 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct $lastLine = $tokens[$i]['line']; continue; } + + if ($tokens[$i]['code'] === T_ATTRIBUTE) { + // Skip attributes as they have their own indentation rules. + $i = $tokens[$i]['attribute_closer']; + $lastLine = $tokens[$i]['line']; + continue; + } }//end for }//end processArgumentList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php index 34ca2830..00e68bfe 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc index d97ef4d2..6942944b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc @@ -110,3 +110,5 @@ if (!class_exists('ClassOpeningBraceTooMuchIndentation')) { { } } + +enum IncorrectBracePlacement {} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc.fixed index 5b0a2f93..26688b15 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.1.inc.fixed @@ -119,3 +119,7 @@ if (!class_exists('ClassOpeningBraceTooMuchIndentation')) { { } } + +enum IncorrectBracePlacement +{ +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php index 1514a703..4c1d28e7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php @@ -61,6 +61,7 @@ public function getErrorList($testFile='') 99 => 1, 104 => 1, 110 => 1, + 114 => 1, ]; default: diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc index 8414efbe..da53b99e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc @@ -120,6 +120,16 @@ trait Empty_Trait_Doc }//end trait +/** + * + * + */ +enum Empty_Enum_Doc +{ + +}//end enum + + /** * Sample class comment * diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php index 9a4bcf7d..004a064b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php @@ -44,6 +44,7 @@ public function getErrorList() 96 => 5, 106 => 5, 116 => 5, + 126 => 5, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.3.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.3.inc new file mode 100644 index 00000000..c076fd45 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.3.inc @@ -0,0 +1,8 @@ + 1]; + case 'FileCommentUnitTest.3.inc': + return [1 => 1]; + default: return []; }//end switch diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc index 0e935ead..5c3295fd 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc @@ -429,3 +429,50 @@ public function ignored() { } // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] __construct,__destruct + +class Something implements JsonSerializable { + /** + * Single attribute. + * + * @return mixed + */ + #[ReturnTypeWillChange] + public function jsonSerialize() {} + + /** + * Multiple attributes. + * + * @return Something + */ + #[AttributeA] + #[AttributeB] + public function methodName() {} + + /** + * Blank line between docblock and attribute. + * + * @return mixed + */ + + #[ReturnTypeWillChange] + public function blankLineDetectionA() {} + + /** + * Blank line between attribute and function declaration. + * + * @return mixed + */ + #[ReturnTypeWillChange] + + public function blankLineDetectionB() {} + + /** + * Blank line between both docblock and attribute and attribute and function declaration. + * + * @return mixed + */ + + #[ReturnTypeWillChange] + + public function blankLineDetectionC() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index 29588134..751b09c6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -429,3 +429,50 @@ public function ignored() { } // phpcs:set PEAR.Commenting.FunctionComment specialMethods[] __construct,__destruct + +class Something implements JsonSerializable { + /** + * Single attribute. + * + * @return mixed + */ + #[ReturnTypeWillChange] + public function jsonSerialize() {} + + /** + * Multiple attributes. + * + * @return Something + */ + #[AttributeA] + #[AttributeB] + public function methodName() {} + + /** + * Blank line between docblock and attribute. + * + * @return mixed + */ + + #[ReturnTypeWillChange] + public function blankLineDetectionA() {} + + /** + * Blank line between attribute and function declaration. + * + * @return mixed + */ + #[ReturnTypeWillChange] + + public function blankLineDetectionB() {} + + /** + * Blank line between both docblock and attribute and attribute and function declaration. + * + * @return mixed + */ + + #[ReturnTypeWillChange] + + public function blankLineDetectionC() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php index a7b35e60..734ff73e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php @@ -70,6 +70,9 @@ public function getErrorList() 364 => 1, 406 => 1, 417 => 1, + 455 => 1, + 464 => 1, + 473 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc index ed3d2c43..612748fe 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc @@ -548,3 +548,22 @@ array_fill_keys( ), value: true, ); // phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true + +?> +
+

+
+
+

+
+ +content +

diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed index 8d02e746..00226de5 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed @@ -563,3 +563,22 @@ array_fill_keys( value: true, ); // phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true + +?> +
+

+
+
+

+
+ +content +

diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php index 1dd59188..4984de2b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php @@ -131,6 +131,9 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc') 546 => 1, 547 => 1, 548 => 1, + 559 => 1, + 567 => 1, + 568 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc index 7af72000..02e0a20d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc @@ -314,3 +314,107 @@ if(true) { ; } } + +class ConstructorPropertyPromotionSingleLineDocblockIndentOK +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIndentOK +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionSingleLineDocblockIncorrectIndent +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, +/** + * @var string + * @Assert\NotBlank() + */ +#[NotBlank] +private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineAttributesOK +{ + public function __construct( + #[ORM\ManyToOne( + Something: true, + SomethingElse: 'text', + )] + #[Groups([ + 'ArrayEntry', + 'Another.ArrayEntry', + ])] + #[MoreGroups( + [ + 'ArrayEntry', + 'Another.ArrayEntry', + ] + )] + private Type $property + ) { + // Do something. + } +} + +class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent +{ + public function __construct( + #[ORM\ManyToOne( + Something: true, + SomethingElse: 'text', + )] + #[Groups([ + 'ArrayEntry', + 'Another.ArrayEntry', + ])] + #[MoreGroups( + [ + 'ArrayEntry', + 'Another.ArrayEntry', + ] + )] + private Type $property + ) { + // Do something. + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed index b993e3f0..0d67e9f7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed @@ -312,3 +312,107 @@ if(true) { abstract function baz(); } } + +class ConstructorPropertyPromotionSingleLineDocblockIndentOK +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIndentOK +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionSingleLineDocblockIncorrectIndent +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineAttributesOK +{ + public function __construct( + #[ORM\ManyToOne( + Something: true, + SomethingElse: 'text', + )] + #[Groups([ + 'ArrayEntry', + 'Another.ArrayEntry', + ])] + #[MoreGroups( + [ + 'ArrayEntry', + 'Another.ArrayEntry', + ] + )] + private Type $property + ) { + // Do something. + } +} + +class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent +{ + public function __construct( + #[ORM\ManyToOne( + Something: true, + SomethingElse: 'text', + )] + #[Groups([ + 'ArrayEntry', + 'Another.ArrayEntry', + ])] + #[MoreGroups( + [ + 'ArrayEntry', + 'Another.ArrayEntry', + ] + )] + private Type $property + ) { + // Do something. + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php index 7a8a53a1..01ab3e84 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php @@ -82,6 +82,23 @@ public function getErrorList($testFile='FunctionDeclarationUnitTest.inc') 309 => 1, 313 => 1, 314 => 1, + 350 => 1, + 351 => 1, + 352 => 1, + 353 => 1, + 361 => 1, + 362 => 1, + 363 => 1, + 364 => 1, + 365 => 1, + 366 => 1, + 367 => 1, + 368 => 1, + 369 => 1, + 370 => 1, + 371 => 1, + 402 => 1, + 406 => 1, ]; } else { $errors = [ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc index c6d15df7..053a4fee 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc @@ -66,3 +66,25 @@ trait _Invalid_Name {} trait ___ {} trait Invalid__Name {} + +enum Valid_Name: string {} + +enum invalid_Name : String {} + +enum invalid_name {} + +enum Invalid_name: Int {} + +enum VALID_Name {} + +enum VALID_NAME {} + +enum VALID_Name : int {} + +enum ValidName {} + +enum _Invalid_Name {} + +enum ___ {} + +enum Invalid__Name {} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php index 8ff9c674..54ee74aa 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php @@ -44,6 +44,12 @@ public function getErrorList() 64 => 1, 66 => 2, 68 => 1, + 72 => 1, + 74 => 2, + 76 => 1, + 86 => 1, + 88 => 2, + 90 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index 78280cdd..18b1a481 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -220,3 +220,24 @@ abstract class My_Class { public function my_class() {} public function _MY_CLASS() {} } + +enum Suit: string implements Colorful, CardGame { + // Magic methods. + function __call($name, $args) {} + static function __callStatic($name, $args) {} + function __invoke() {} + + // Valid Method Name. + public function parseMyDSN() {} + private function _getAnotherValue() {} + + // Double underscore non-magic methods not allowed. + function __myFunction() {} + function __my_function() {} + + // Non-camelcase. + public function get_some_value() {} + + // Private without underscore prefix. + private function getMe() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php index 9bb6de0d..4639a1e2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -122,6 +122,10 @@ public function getErrorList() 212 => 1, 213 => 1, 214 => 1, + 235 => 1, + 236 => 2, + 239 => 1, + 242 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc index c5202378..3f900679 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc @@ -152,3 +152,13 @@ $match = match ($test) { 1 => 'a', 2 => 'b' }; + +enum Enum +{ +} + +enum Suits {} + +enum Cards +{ + } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc.fixed index 23156e41..f369c2b2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc.fixed @@ -157,3 +157,14 @@ $match = match ($test) { 1 => 'a', 2 => 'b' }; + +enum Enum +{ +} + +enum Suits { +} + +enum Cards +{ +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php index 1b01ee9d..26593254 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php @@ -42,6 +42,8 @@ public function getErrorList() 146 => 1, 149 => 1, 154 => 1, + 160 => 1, + 164 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php index ac6407d6..3db26f6f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Classes/ClassDeclarationSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() @@ -50,7 +51,7 @@ public function process(File $phpcsFile, $stackPtr) $errorData = [strtolower($tokens[$stackPtr]['content'])]; - $nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT], ($tokens[$stackPtr]['scope_closer'] + 1)); + $nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], ($tokens[$stackPtr]['scope_closer'] + 1)); if ($nextClass !== false) { $error = 'Each %s must be in a file by itself'; $phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData); @@ -59,7 +60,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes'); } - $namespace = $phpcsFile->findNext([T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT], 0); + $namespace = $phpcsFile->findNext([T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], 0); if ($tokens[$namespace]['code'] !== T_NAMESPACE) { $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)'; $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php index 27454cc1..3f8c5e0d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php @@ -82,6 +82,7 @@ private function searchForConflict($phpcsFile, $start, $end, $tokens) T_CLASS => T_CLASS, T_INTERFACE => T_INTERFACE, T_TRAIT => T_TRAIT, + T_ENUM => T_ENUM, T_FUNCTION => T_FUNCTION, ]; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Tests/Classes/ClassDeclarationUnitTest.3.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Tests/Classes/ClassDeclarationUnitTest.3.inc new file mode 100644 index 00000000..302908eb --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR1/Tests/Classes/ClassDeclarationUnitTest.3.inc @@ -0,0 +1,3 @@ + T_NS_SEPARATOR, T_SELF => T_SELF, T_STATIC => T_STATIC, + T_PARENT => T_PARENT, T_VARIABLE => T_VARIABLE, T_DOLLAR => T_DOLLAR, T_OBJECT_OPERATOR => T_OBJECT_OPERATOR, @@ -63,6 +64,14 @@ public function process(File $phpcsFile, $stackPtr) continue; } + // Skip over potential attributes for anonymous classes. + if ($tokens[$i]['code'] === T_ATTRIBUTE + && isset($tokens[$i]['attribute_closer']) === true + ) { + $i = $tokens[$i]['attribute_closer']; + continue; + } + if ($tokens[$i]['code'] === T_OPEN_SQUARE_BRACKET || $tokens[$i]['code'] === T_OPEN_CURLY_BRACKET ) { @@ -72,7 +81,7 @@ public function process(File $phpcsFile, $stackPtr) $classNameEnd = $i; break; - } + }//end for if ($classNameEnd === null) { return; @@ -88,6 +97,11 @@ public function process(File $phpcsFile, $stackPtr) return; } + if ($classNameEnd === $stackPtr) { + // Failed to find the class name. + return; + } + $error = 'Parentheses must be used when instantiating a new class'; $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MissingParentheses'); if ($fix === true) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/ClosingBraceSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/ClosingBraceSniff.php index 0f9752b1..fa1f8d60 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/ClosingBraceSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/ClosingBraceSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, T_FUNCTION, ]; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/OpeningBraceSpaceSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/OpeningBraceSpaceSniff.php new file mode 100644 index 00000000..83ffda4d --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Classes/OpeningBraceSpaceSniff.php @@ -0,0 +1,80 @@ + + * @copyright 2006-2019 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Standards\PSR12\Sniffs\Classes; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Tokens; + +class OpeningBraceSpaceSniff implements Sniff +{ + + + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() + { + return Tokens::$ooScopeTokens; + + }//end register() + + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. + * + * @return void + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + if (isset($tokens[$stackPtr]['scope_opener']) === false) { + return; + } + + $opener = $tokens[$stackPtr]['scope_opener']; + $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true); + if ($next === false + || $tokens[$next]['line'] <= ($tokens[$opener]['line'] + 1) + ) { + return; + } + + $error = 'Opening brace must not be followed by a blank line'; + $fix = $phpcsFile->addFixableError($error, $opener, 'Found'); + if ($fix === false) { + return; + } + + $phpcsFile->fixer->beginChangeset(); + for ($i = ($opener + 1); $i < $next; $i++) { + if ($tokens[$i]['line'] === $tokens[$opener]['line']) { + continue; + } + + if ($tokens[$i]['line'] === $tokens[$next]['line']) { + break; + } + + $phpcsFile->fixer->replaceToken($i, ''); + } + + $phpcsFile->fixer->endChangeset(); + + }//end process() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Properties/ConstantVisibilitySniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Properties/ConstantVisibilitySniff.php index 8a1000f7..7f63d1e8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Properties/ConstantVisibilitySniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Properties/ConstantVisibilitySniff.php @@ -47,7 +47,10 @@ public function process(File $phpcsFile, $stackPtr) return; } - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $ignore = Tokens::$emptyTokens; + $ignore[] = T_FINAL; + + $prev = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); if (isset(Tokens::$scopeModifiers[$tokens[$prev]['code']]) === true) { return; } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/AnonClassDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/AnonClassDeclarationUnitTest.php index 3f65602e..cc162b29 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/AnonClassDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/AnonClassDeclarationUnitTest.php @@ -32,7 +32,7 @@ public function getErrorList() 32 => 1, 33 => 1, 34 => 1, - 35 => 2, + 35 => 1, 36 => 1, 37 => 3, 39 => 1, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc index ca0dc361..9fd15480 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc @@ -36,3 +36,12 @@ $a = new ${$varHoldingClassName}; $class = new $obj?->classname(); $class = new $obj?->classname; $class = new ${$obj?->classname}; + +// Issue 3456. +// Anon classes should be skipped, even when there is an attribute between the new and the class keywords. +$anonWithAttribute = new #[SomeAttribute('summary')] class { + public const SOME_STUFF = 'foo'; +}; + +$foo = new parent(); +$foo = new parent; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc.fixed index a4d209cc..aa9d0c72 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.inc.fixed @@ -36,3 +36,12 @@ $a = new ${$varHoldingClassName}(); $class = new $obj?->classname(); $class = new $obj?->classname(); $class = new ${$obj?->classname}(); + +// Issue 3456. +// Anon classes should be skipped, even when there is an attribute between the new and the class keywords. +$anonWithAttribute = new #[SomeAttribute('summary')] class { + public const SOME_STUFF = 'foo'; +}; + +$foo = new parent(); +$foo = new parent(); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.php index 3fb1ab99..0a16af8f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClassInstantiationUnitTest.php @@ -43,6 +43,7 @@ public function getErrorList() 34 => 1, 37 => 1, 38 => 1, + 47 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.inc index 1d2e92c9..2562d26c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.inc @@ -45,3 +45,8 @@ $instance = new class extends \Foo implements \HandleableInterface { $app->get('/hello/{name}', function ($name) use ($app) { return 'Hello ' . $app->escape($name); }); + +enum Foo4 +{ + +}//end diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.php index 1deac1cd..d402f1bb 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/ClosingBraceUnitTest.php @@ -31,6 +31,7 @@ public function getErrorList() 19 => 1, 24 => 1, 31 => 1, + 52 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/OpeningBraceSpaceUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/OpeningBraceSpaceUnitTest.inc new file mode 100644 index 00000000..2c41bde9 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Classes/OpeningBraceSpaceUnitTest.inc @@ -0,0 +1,57 @@ + + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Standards\PSR12\Tests\Classes; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + +class OpeningBraceSpaceUnitTest extends AbstractSniffUnitTest +{ + + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array + */ + public function getErrorList() + { + return [ + 10 => 1, + 18 => 1, + 24 => 1, + 34 => 1, + 41 => 1, + 55 => 1, + ]; + + }//end getErrorList() + + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array + */ + public function getWarningList() + { + return []; + + }//end getWarningList() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc index 904e3f40..6d024eaa 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc @@ -17,3 +17,10 @@ class ClassName3 } $foo = function() use($bar) {}; + +enum SomeEnum +{ + use \FirstTrait; + use SecondTrait; + use ThirdTrait; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed index d5b3f67e..dfed46fc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed @@ -17,3 +17,10 @@ class ClassName3 } $foo = function() use($bar) {}; + +enum SomeEnum +{ + use \FirstTrait; + use SecondTrait; + use ThirdTrait; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc index 9ae94321..c067e6a2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc @@ -63,3 +63,15 @@ $fn = fn(array & $one) => 1; $fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp()); function issue3267(string|int ...$values) {} + +function setDefault(#[ImportValue( + constraints: [ + [ + Assert\Type::class, + ['type' => 'bool'], + ], + ] + )] ?bool $value = null): void + { + // Do something + } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc.fixed index 504ae43e..76764291 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Operators/OperatorSpacingUnitTest.inc.fixed @@ -63,3 +63,15 @@ $fn = fn(array & $one) => 1; $fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp()); function issue3267(string|int ...$values) {} + +function setDefault(#[ImportValue( + constraints: [ + [ + Assert\Type::class, + ['type' => 'bool'], + ], + ] + )] ?bool $value = null): void + { + // Do something + } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.inc index c07b1b91..84ea24b2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.inc @@ -5,3 +5,18 @@ class Foo { } const APPLICATION_ENV = 'development'; + +// Issue 3526, PHP 8.1 final constants. +class SampleEnum +{ + final const FOO = 'SAMPLE'; + + public final const BAR = 'SAMPLE'; + + final private const BAZ = 'SAMPLE'; +} + +enum SomeEnum { + public const BAR = 'bar'; + const BAZ = 'baz'; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.php index 3917eb68..b738706d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Properties/ConstantVisibilityUnitTest.php @@ -40,7 +40,11 @@ public function getErrorList() */ public function getWarningList() { - return [4 => 1]; + return [ + 4 => 1, + 12 => 1, + 21 => 1, + ]; }//end getWarningList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc index e62489fe..c8ad746a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc @@ -207,3 +207,15 @@ class Foo implements Bar */ use Baz; } + +enum SomeEnum1 +{ + use FirstTrait; +} + +enum SomeEnum2 +{ + + use FirstTrait; + +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc.fixed index 0090b4e9..1c5d8185 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc.fixed @@ -201,3 +201,13 @@ class Foo implements Bar */ use Baz; } + +enum SomeEnum1 +{ + use FirstTrait; +} + +enum SomeEnum2 +{ + use FirstTrait; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php index c406805a..797a2912 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.php @@ -47,6 +47,7 @@ public function getErrorList() 165 => 1, 170 => 1, 208 => 1, + 219 => 3, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml index 14670043..ce8b71a7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml @@ -123,6 +123,7 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php index 8a158d96..efdbb438 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php @@ -41,6 +41,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) $find = Tokens::$scopeModifiers; $find[] = T_VARIABLE; $find[] = T_VAR; + $find[] = T_READONLY; $find[] = T_SEMICOLON; $find[] = T_OPEN_CURLY_BRACKET; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php index faac9dcb..de81c530 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php @@ -107,13 +107,13 @@ public function process(File $phpcsFile, $stackPtr) } } - $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true); - if ($tokens[$next]['line'] === $tokens[$opener]['line'] - && ($tokens[$next]['code'] === T_COMMENT - || isset(Tokens::$phpcsCommentTokens[$tokens[$next]['code']]) === true) - ) { - // Skip comments on the same line. - $next = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); + for ($next = ($opener + 1); $next < $nextCloser; $next++) { + if (isset(Tokens::$emptyTokens[$tokens[$next]['code']]) === false + || (isset(Tokens::$commentTokens[$tokens[$next]['code']]) === true + && $tokens[$next]['line'] !== $tokens[$opener]['line']) + ) { + break; + } } if ($tokens[$next]['line'] !== ($tokens[$opener]['line'] + 1)) { @@ -126,6 +126,11 @@ public function process(File $phpcsFile, $stackPtr) } else { $phpcsFile->fixer->beginChangeset(); for ($i = ($opener + 1); $i < $next; $i++) { + if ($tokens[$i]['line'] === $tokens[$opener]['line']) { + // Ignore trailing comments. + continue; + } + if ($tokens[$i]['line'] === $tokens[$next]['line']) { break; } @@ -133,10 +138,9 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->fixer->replaceToken($i, ''); } - $phpcsFile->fixer->addNewLineBefore($i); $phpcsFile->fixer->endChangeset(); } - } + }//end if }//end if if ($tokens[$nextCloser]['scope_condition'] === $nextCase) { @@ -186,7 +190,7 @@ public function process(File $phpcsFile, $stackPtr) $nextCode = $this->findNextCase($phpcsFile, ($opener + 1), $nextCloser); if ($nextCode !== false) { $prevCode = $phpcsFile->findPrevious(T_WHITESPACE, ($nextCode - 1), $nextCase, true); - if ($tokens[$prevCode]['code'] !== T_COMMENT + if (isset(Tokens::$commentTokens[$tokens[$prevCode]['code']]) === false && $this->findNestedTerminator($phpcsFile, ($opener + 1), $nextCode) === false ) { $error = 'There must be a comment when fall-through is intentional in a non-empty case body'; @@ -243,29 +247,32 @@ private function findNestedTerminator($phpcsFile, $stackPtr, $end) { $tokens = $phpcsFile->getTokens(); - $lastToken = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), $stackPtr, true); + $lastToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($end - 1), $stackPtr, true); if ($lastToken === false) { return false; } if ($tokens[$lastToken]['code'] === T_CLOSE_CURLY_BRACKET) { // We found a closing curly bracket and want to check if its block - // belongs to a SWITCH, IF, ELSEIF or ELSE clause. If yes, we - // continue searching for a terminating statement within that + // belongs to a SWITCH, IF, ELSEIF or ELSE, TRY, CATCH OR FINALLY clause. + // If yes, we continue searching for a terminating statement within that // block. Note that we have to make sure that every block of // the entire if/else/switch statement has a terminating statement. + // For a try/catch/finally statement, either the finally block has + // to have a terminating statement or every try/catch block has to have one. $currentCloser = $lastToken; $hasElseBlock = false; + $hasCatchWithoutTerminator = false; do { $scopeOpener = $tokens[$currentCloser]['scope_opener']; $scopeCloser = $tokens[$currentCloser]['scope_closer']; - $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($scopeOpener - 1), $stackPtr, true); + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($scopeOpener - 1), $stackPtr, true); if ($prevToken === false) { return false; } - // SWITCH, IF and ELSEIF clauses possess a condition we have to account for. + // SWITCH, IF, ELSEIF, CATCH clauses possess a condition we have to account for. if ($tokens[$prevToken]['code'] === T_CLOSE_PARENTHESIS) { $prevToken = $tokens[$prevToken]['parenthesis_owner']; } @@ -288,10 +295,39 @@ private function findNestedTerminator($phpcsFile, $stackPtr, $end) return false; } - $currentCloser = $phpcsFile->findPrevious(T_WHITESPACE, ($prevToken - 1), $stackPtr, true); + $currentCloser = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), $stackPtr, true); if ($tokens[$prevToken]['code'] === T_ELSE) { $hasElseBlock = true; } + } else if ($tokens[$prevToken]['code'] === T_FINALLY) { + // If we find a terminating statement within this block, + // the whole try/catch/finally statement is covered. + $hasTerminator = $this->findNestedTerminator($phpcsFile, ($scopeOpener + 1), $scopeCloser); + if ($hasTerminator !== false) { + return $hasTerminator; + } + + // Otherwise, we continue with the previous TRY or CATCH clause. + $currentCloser = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), $stackPtr, true); + } else if ($tokens[$prevToken]['code'] === T_TRY) { + // If we've seen CATCH blocks without terminator statement and + // have not seen a FINALLY *with* a terminator statement, we + // don't even need to bother checking the TRY. + if ($hasCatchWithoutTerminator === true) { + return false; + } + + return $this->findNestedTerminator($phpcsFile, ($scopeOpener + 1), $scopeCloser); + } else if ($tokens[$prevToken]['code'] === T_CATCH) { + // Keep track of seen catch statements without terminating statement, + // but don't bow out yet as there may still be a FINALLY clause + // with a terminating statement before the CATCH. + $hasTerminator = $this->findNestedTerminator($phpcsFile, ($scopeOpener + 1), $scopeCloser); + if ($hasTerminator === false) { + $hasCatchWithoutTerminator = true; + } + + $currentCloser = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), $stackPtr, true); } else if ($tokens[$prevToken]['code'] === T_SWITCH) { $hasDefaultBlock = false; $endOfSwitch = $tokens[$prevToken]['scope_closer']; @@ -305,7 +341,7 @@ private function findNestedTerminator($phpcsFile, $stackPtr, $end) $opener = $tokens[$nextCase]['scope_opener']; - $nextCode = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), $endOfSwitch, true); + $nextCode = $phpcsFile->findNext(Tokens::$emptyTokens, ($opener + 1), $endOfSwitch, true); if ($tokens[$nextCode]['code'] === T_CASE || $tokens[$nextCode]['code'] === T_DEFAULT) { // This case statement has no content, so skip it. continue; @@ -339,15 +375,15 @@ private function findNestedTerminator($phpcsFile, $stackPtr, $end) // We found the last statement of the CASE. Now we want to // check whether it is a terminating one. $terminators = [ - T_RETURN, - T_BREAK, - T_CONTINUE, - T_THROW, - T_EXIT, + T_RETURN => T_RETURN, + T_BREAK => T_BREAK, + T_CONTINUE => T_CONTINUE, + T_THROW => T_THROW, + T_EXIT => T_EXIT, ]; $terminator = $phpcsFile->findStartOfStatement(($lastToken - 1)); - if (in_array($tokens[$terminator]['code'], $terminators, true) === true) { + if (isset($terminators[$tokens[$terminator]['code']]) === true) { return $terminator; } }//end if diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php index 241fa5a8..aed461f8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php @@ -23,7 +23,10 @@ class EndFileNewlineSniff implements Sniff */ public function register() { - return [T_OPEN_TAG]; + return [ + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php index 21a9dbe9..aba9caa7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php @@ -285,7 +285,7 @@ private function shouldIgnoreUse($phpcsFile, $stackPtr) } // Ignore USE keywords for traits. - if ($phpcsFile->hasCondition($stackPtr, [T_CLASS, T_TRAIT]) === true) { + if ($phpcsFile->hasCondition($stackPtr, [T_CLASS, T_TRAIT, T_ENUM]) === true) { return true; } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc index 031d2a83..33bec44e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc @@ -71,3 +71,13 @@ class MyClass public int $var = null; public static int/*comment*/$var = null; } + +class ReadOnlyProp { + public readonly int $foo, + $bar, + $var = null; + + protected readonly ?string $foo; + + readonly array $foo; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc.fixed index aca7c2fc..df83112a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.inc.fixed @@ -68,3 +68,13 @@ class MyClass public int $var = null; public static int /*comment*/$var = null; } + +class ReadOnlyProp { + public readonly int $foo, + $bar, + $var = null; + + protected readonly ?string $foo; + + readonly array $foo; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php index 20da24d9..f1dd0194 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Classes/PropertyDeclarationUnitTest.php @@ -46,6 +46,9 @@ public function getErrorList() 69 => 1, 71 => 1, 72 => 1, + 76 => 1, + 80 => 1, + 82 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc index 8050b636..2ca60a93 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc @@ -331,3 +331,268 @@ switch ($foo) { case 2: return 2; } + +switch ($foo) { + case 1: + // phpcs:ignore + case 2: + return 1; + case 3: + return 2; +} + +// Issue 3352. +switch ( $test ) { + case 2: // comment followed by empty line + + break; + + case 3: /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments. */ + + + + break; + + case 4: /** inline docblock */ + + + + break; + + case 5: /* checking how it handles */ /* two trailing comments */ + + break; + + case 6: + // Comment as first content of the body. + + break; + + case 7: + /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments at start of body. */ + + break; + + case 8: + /** inline docblock */ + + break; +} + +// Handle comments correctly. +switch ($foo) { + case 1: + if ($bar > 0) { + doSomething(); + } + // Comment + else { + return 1; + } + case 2: + return 2; +} + +switch ($foo) { + case 1: + if ($bar > 0) /*comment*/ { + return doSomething(); + } + else { + return 1; + } + case 2: + return 2; +} + +// Issue #3297. +// Okay - finally will always be executed, so all branches are covered by the `return` in finally. +switch ( $a ) { + case 1: + try { + doSomething(); + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + doSomething(); + } finally { + return true; + } + default: + $other = $code; + break; +} + +// Okay - all - non-finally - branches have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) /*comment*/ { + return true; + } + // Comment + catch (AnotherException $e) { + return true; + } finally { + doSomething(); + } + default: + $other = $code; + break; +} + +// Okay - finally will always be executed, so all branches are covered by the `return` in finally. +// Non-standard structure order. +switch ( $a ) { + case 1: + try { + doSomething(); + } catch (Exception $e) { + doSomething(); + } finally { + return true; + } catch (AnotherException $e) { + doSomething(); + } + default: + $other = $code; + break; +} + +// Okay - all - non-finally - branches have a terminating statement. +// Non-standard structure order. +switch ( $a ) { + case 1: + try { + return false; + } finally { + doSomething(); + } catch (MyException $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// All okay, no finally. Any exception still uncaught will terminate the case anyhow, so we're good. +switch ( $a ) { + case 1: + try { + return false; + } catch (MyException $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// All okay, no catch +switch ( $a ) { + case 1: + try { + return true; + } finally { + doSomething(); + } + case 2: + $other = $code; + break; +} + +// All okay, try-catch nested in if. +switch ( $a ) { + case 1: + if ($a) { + try { + return true; // Comment. + } catch (MyException $e) { + throw new Exception($e->getMessage()); + } + } else { + return true; + } + case 2: + $other = $code; + break; +} + +// Missing fall-through comment. +switch ( $a ) { + case 1: + try { + doSomething(); + } finally { + doSomething(); + } + case 2: + $other = $code; + break; +} + +// Missing fall-through comment. One of the catches does not have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + return true; + } finally { + doSomething(); + } + default: + $other = $code; + break; +} + +// Missing fall-through comment. Try does not have a terminating statement. +switch ( $a ) { + case 1: + try { + doSomething(); + } finally { + doSomething(); + } catch (Exception $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// Missing fall-through comment. One of the catches does not have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// Issue 3550 - comment after terminating statement. +switch (rand()) { + case 1: + if (rand() === 1) { + break; + } else { + break; // comment + } + default: + break; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed index bebc6661..bbc8b7c4 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.inc.fixed @@ -334,3 +334,260 @@ switch ($foo) { case 2: return 2; } + +switch ($foo) { + case 1: + // phpcs:ignore + case 2: + return 1; + case 3: + return 2; +} + +// Issue 3352. +switch ( $test ) { + case 2: // comment followed by empty line + break; + + case 3: /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments. */ + break; + + case 4: /** inline docblock */ + break; + + case 5: /* checking how it handles */ /* two trailing comments */ + break; + + case 6: + // Comment as first content of the body. + + break; + + case 7: + /* phpcs:ignore Stnd.Cat.SniffName -- Verify correct handling of ignore comments at start of body. */ + + break; + + case 8: + /** inline docblock */ + + break; +} + +// Handle comments correctly. +switch ($foo) { + case 1: + if ($bar > 0) { + doSomething(); + } + // Comment + else { + return 1; + } + case 2: + return 2; +} + +switch ($foo) { + case 1: + if ($bar > 0) /*comment*/ { + return doSomething(); + } + else { + return 1; + } + case 2: + return 2; +} + +// Issue #3297. +// Okay - finally will always be executed, so all branches are covered by the `return` in finally. +switch ( $a ) { + case 1: + try { + doSomething(); + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + doSomething(); + } finally { + return true; + } + default: + $other = $code; + break; +} + +// Okay - all - non-finally - branches have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) /*comment*/ { + return true; + } + // Comment + catch (AnotherException $e) { + return true; + } finally { + doSomething(); + } + default: + $other = $code; + break; +} + +// Okay - finally will always be executed, so all branches are covered by the `return` in finally. +// Non-standard structure order. +switch ( $a ) { + case 1: + try { + doSomething(); + } catch (Exception $e) { + doSomething(); + } finally { + return true; + } catch (AnotherException $e) { + doSomething(); + } + default: + $other = $code; + break; +} + +// Okay - all - non-finally - branches have a terminating statement. +// Non-standard structure order. +switch ( $a ) { + case 1: + try { + return false; + } finally { + doSomething(); + } catch (MyException $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// All okay, no finally. Any exception still uncaught will terminate the case anyhow, so we're good. +switch ( $a ) { + case 1: + try { + return false; + } catch (MyException $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// All okay, no catch +switch ( $a ) { + case 1: + try { + return true; + } finally { + doSomething(); + } + case 2: + $other = $code; + break; +} + +// All okay, try-catch nested in if. +switch ( $a ) { + case 1: + if ($a) { + try { + return true; // Comment. + } catch (MyException $e) { + throw new Exception($e->getMessage()); + } + } else { + return true; + } + case 2: + $other = $code; + break; +} + +// Missing fall-through comment. +switch ( $a ) { + case 1: + try { + doSomething(); + } finally { + doSomething(); + } + case 2: + $other = $code; + break; +} + +// Missing fall-through comment. One of the catches does not have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + return true; + } finally { + doSomething(); + } + default: + $other = $code; + break; +} + +// Missing fall-through comment. Try does not have a terminating statement. +switch ( $a ) { + case 1: + try { + doSomething(); + } finally { + doSomething(); + } catch (Exception $e) { + return true; + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// Missing fall-through comment. One of the catches does not have a terminating statement. +switch ( $a ) { + case 1: + try { + return false; + } catch (Exception $e) { + doSomething(); + } catch (AnotherException $e) { + return true; + } + default: + $other = $code; + break; +} + +// Issue 3550 - comment after terminating statement. +switch (rand()) { + case 1: + if (rand() === 1) { + break; + } else { + break; // comment + } + default: + break; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.php index 97a68704..0cd946d8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/ControlStructures/SwitchDeclarationUnitTest.php @@ -49,6 +49,15 @@ public function getErrorList() 260 => 1, 300 => 1, 311 => 1, + 346 => 1, + 350 => 1, + 356 => 1, + 362 => 1, + 384 => 1, + 528 => 1, + 541 => 1, + 558 => 1, + 575 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.11.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.11.inc new file mode 100644 index 00000000..4f2e47af --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.11.inc @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.12.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.12.inc.fixed new file mode 100644 index 00000000..d3c19fee --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.12.inc.fixed @@ -0,0 +1 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.13.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.13.inc new file mode 100644 index 00000000..fa2f476a --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.13.inc @@ -0,0 +1,5 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.php index a80c16db..456106fe 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.php @@ -35,6 +35,10 @@ public function getErrorList($testFile='') case 'EndFileNewlineUnitTest.9.inc': case 'EndFileNewlineUnitTest.10.inc': return [2 => 1]; + case 'EndFileNewlineUnitTest.11.inc': + case 'EndFileNewlineUnitTest.12.inc': + case 'EndFileNewlineUnitTest.13.inc': + return [1 => 1]; default: return []; }//end switch diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc index 21c03119..096b44bc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc @@ -64,3 +64,12 @@ class Nested_Function { }; } } + +enum MyEnum +{ + function _myFunction() {} + function __myFunction() {} + public static function myFunction() {} + static public function myFunction() {} + public function _() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc.fixed index 5fb88613..eae8d28f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.inc.fixed @@ -64,3 +64,12 @@ class Nested_Function { }; } } + +enum MyEnum +{ + function _myFunction() {} + function __myFunction() {} + public static function myFunction() {} + public static function myFunction() {} + public function _() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.php index 2d508d4c..a8dcdfea 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Methods/MethodDeclarationUnitTest.php @@ -40,6 +40,7 @@ public function getErrorList() 54 => 1, 56 => 3, 63 => 2, + 73 => 1, ]; }//end getErrorList() @@ -61,6 +62,7 @@ public function getWarningList() 30 => 1, 46 => 1, 63 => 1, + 70 => 1, ]; }//end getWarningList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.1.inc index c4e83da4..61befc9e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.1.inc @@ -30,9 +30,14 @@ trait HelloWorld use Hello, World; } +enum SomeEnum +{ + use Hello, World; +} + $x = $foo ? function ($foo) use /* comment */ ($bar): int { return 1; } : $bar; // Testcase must be on last line in the file. -use \ No newline at end of file +use diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php index 17991bd7..b45a4709 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -374,6 +374,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array || $tokens[$nextToken]['code'] === T_OPEN_SHORT_ARRAY || $tokens[$nextToken]['code'] === T_CLOSURE || $tokens[$nextToken]['code'] === T_FN + || $tokens[$nextToken]['code'] === T_MATCH ) { // Let subsequent calls of this test handle nested arrays. if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php index afbec4fa..88a7e0da 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php @@ -27,6 +27,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php index 10de719d..ffddd2cd 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php @@ -28,6 +28,7 @@ public function register() T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, ]; }//end register() @@ -58,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr) // starting with the number will be multiple tokens. $opener = $tokens[$stackPtr]['scope_opener']; $nameStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $opener, true); - $nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener); + $nameEnd = $phpcsFile->findNext([T_WHITESPACE, T_COLON], $nameStart, $opener); if ($nameEnd === false) { $name = $tokens[$nameStart]['content']; } else { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php index ae9db794..eb647f5f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php @@ -69,11 +69,22 @@ public function process(File $phpcsFile, $stackPtr) // If this is a function/class/interface doc block comment, skip it. // We are only interested in inline doc block comments. if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) { - $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); - $ignore = [ + $nextToken = $stackPtr; + do { + $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextToken + 1), null, true); + if ($tokens[$nextToken]['code'] === T_ATTRIBUTE) { + $nextToken = $tokens[$nextToken]['attribute_closer']; + continue; + } + + break; + } while (true); + + $ignore = [ T_CLASS => true, T_INTERFACE => true, T_TRAIT => true, + T_ENUM => true, T_FUNCTION => true, T_PUBLIC => true, T_PRIVATE => true, @@ -83,6 +94,7 @@ public function process(File $phpcsFile, $stackPtr) T_ABSTRACT => true, T_CONST => true, T_VAR => true, + T_READONLY => true, ]; if (isset($ignore[$tokens[$nextToken]['code']]) === true) { return; @@ -363,6 +375,7 @@ public function process(File $phpcsFile, $stackPtr) if ((isset($tokens[$contentBefore]['scope_closer']) === true && $tokens[$contentBefore]['scope_opener'] === $contentBefore) || $tokens[$contentBefore]['code'] === T_OPEN_TAG + || $tokens[$contentBefore]['code'] === T_OPEN_TAG_WITH_ECHO ) { if (($tokens[$stackPtr]['line'] - $tokens[$contentBefore]['line']) !== 1) { $error = 'Empty line not required before block comment'; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php index 6ab6280f..cd509d0c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/ClosingDeclarationCommentSniff.php @@ -27,6 +27,7 @@ public function register() T_FUNCTION, T_CLASS, T_INTERFACE, + T_ENUM, ]; }//end register() @@ -69,8 +70,10 @@ public function process(File $phpcsFile, $stackPtr) $comment = '//end '.$decName.'()'; } else if ($tokens[$stackPtr]['code'] === T_CLASS) { $comment = '//end class'; - } else { + } else if ($tokens[$stackPtr]['code'] === T_INTERFACE) { $comment = '//end interface'; + } else { + $comment = '//end enum'; }//end if if (isset($tokens[$stackPtr]['scope_closer']) === false) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php index 2624bc22..1f49d2c0 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php @@ -64,6 +64,8 @@ public function process(File $phpcsFile, $stackPtr) $ignore = [ T_CLASS => true, T_INTERFACE => true, + T_ENUM => true, + T_ENUM_CASE => true, T_FUNCTION => true, T_PUBLIC => true, T_PRIVATE => true, @@ -74,6 +76,7 @@ public function process(File $phpcsFile, $stackPtr) T_OBJECT => true, T_PROTOTYPE => true, T_VAR => true, + T_READONLY => true, ]; if ($nextToken === false || isset($ignore[$tokens[$nextToken]['code']]) === false) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php index 73eb31b7..08aaae29 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php @@ -95,6 +95,7 @@ public function process(File $phpcsFile, $stackPtr) T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, T_FUNCTION, T_CLOSURE, T_PUBLIC, @@ -127,7 +128,7 @@ public function process(File $phpcsFile, $stackPtr) // Exactly one blank line after the file comment. $next = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), null, true); - if ($tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) { + if ($next !== false && $tokens[$next]['line'] !== ($tokens[$commentEnd]['line'] + 2)) { $error = 'There must be exactly one blank line after the file comment'; $phpcsFile->addError($error, $commentEnd, 'SpacingAfterComment'); } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index eeed3829..ba3e1710 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -245,6 +245,8 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart) } } + $comment = trim($comment); + // Starts with a capital letter and ends with a fullstop. $firstChar = $comment[0]; if (strtoupper($firstChar) !== $firstChar) { @@ -758,6 +760,8 @@ protected function checkInheritdoc(File $phpcsFile, $stackPtr, $commentStart) } } + return false; + }//end checkInheritdoc() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php index 09b4ee25..8ce95041 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php @@ -59,17 +59,22 @@ public function process(File $phpcsFile, $stackPtr) // We are only interested in inline doc block comments, which are // not allowed. if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) { - $nextToken = $phpcsFile->findNext( - Tokens::$emptyTokens, - ($stackPtr + 1), - null, - true - ); + $nextToken = $stackPtr; + do { + $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextToken + 1), null, true); + if ($tokens[$nextToken]['code'] === T_ATTRIBUTE) { + $nextToken = $tokens[$nextToken]['attribute_closer']; + continue; + } + + break; + } while (true); $ignore = [ T_CLASS, T_INTERFACE, T_TRAIT, + T_ENUM, T_FUNCTION, T_CLOSURE, T_PUBLIC, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php index 7b9fc933..32e89789 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php @@ -30,18 +30,33 @@ public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $ignore = [ - T_PUBLIC, - T_PRIVATE, - T_PROTECTED, - T_VAR, - T_STATIC, - T_WHITESPACE, - T_STRING, - T_NS_SEPARATOR, - T_NULLABLE, + T_PUBLIC => T_PUBLIC, + T_PRIVATE => T_PRIVATE, + T_PROTECTED => T_PROTECTED, + T_VAR => T_VAR, + T_STATIC => T_STATIC, + T_READONLY => T_READONLY, + T_WHITESPACE => T_WHITESPACE, + T_STRING => T_STRING, + T_NS_SEPARATOR => T_NS_SEPARATOR, + T_NULLABLE => T_NULLABLE, ]; - $commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); + for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) { + if (isset($ignore[$tokens[$commentEnd]['code']]) === true) { + continue; + } + + if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END + && isset($tokens[$commentEnd]['attribute_opener']) === true + ) { + $commentEnd = $tokens[$commentEnd]['attribute_opener']; + continue; + } + + break; + } + if ($commentEnd === false || ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php index 6803f9ab..370eab18 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/ControlStructures/ForLoopDeclarationSniff.php @@ -222,7 +222,7 @@ public function process(File $phpcsFile, $stackPtr) $semicolon = $openingBracket; $targetNestinglevel = 0; if (isset($tokens[$openingBracket]['conditions']) === true) { - $targetNestinglevel += count($tokens[$openingBracket]['conditions']); + $targetNestinglevel = count($tokens[$openingBracket]['conditions']); } do { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php index bae88214..6277b809 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Files/FileExtensionSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $fileName = $phpcsFile->getFilename(); $extension = substr($fileName, strrpos($fileName, '.')); - $nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT], $stackPtr); + $nextClass = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], $stackPtr); if ($nextClass !== false) { $phpcsFile->recordMetric($stackPtr, 'File extension for class files', $extension); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php index 60b113d3..8becb74a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php @@ -109,6 +109,7 @@ public function process(File $phpcsFile, $stackPtr) T_OPEN_SHORT_ARRAY => true, T_CASE => true, T_EXIT => true, + T_MATCH_ARROW => true, ]; if (isset($invalidTokens[$tokens[$previousToken]['code']]) === true) { @@ -141,6 +142,7 @@ public function process(File $phpcsFile, $stackPtr) T_THIS, T_SELF, T_STATIC, + T_PARENT, T_OBJECT_OPERATOR, T_NULLSAFE_OBJECT_OPERATOR, T_DOUBLE_COLON, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php index a4ea79cf..c12bd0c4 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php @@ -200,7 +200,7 @@ public function processBracket($phpcsFile, $openBracket, $tokens, $type='functio // The open bracket should be the last thing on the line. if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) { $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true); - if ($tokens[$next]['line'] !== ($tokens[$openBracket]['line'] + 1)) { + if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) { $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket'; $fix = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing'); if ($fix === true) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php index ea4970db..84facf05 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php @@ -48,21 +48,37 @@ public function process(File $phpcsFile, $stackPtr) $prev = $phpcsFile->findPrevious($allowedTokens, ($stackPtr - 1), null, true); $allowedTokens = [ - T_EQUAL => true, - T_DOUBLE_ARROW => true, - T_FN_ARROW => true, - T_MATCH_ARROW => true, - T_THROW => true, - T_RETURN => true, - T_INLINE_THEN => true, - T_INLINE_ELSE => true, + T_EQUAL => T_EQUAL, + T_COALESCE_EQUAL => T_COALESCE_EQUAL, + T_DOUBLE_ARROW => T_DOUBLE_ARROW, + T_FN_ARROW => T_FN_ARROW, + T_MATCH_ARROW => T_MATCH_ARROW, + T_THROW => T_THROW, + T_RETURN => T_RETURN, ]; - if (isset($allowedTokens[$tokens[$prev]['code']]) === false) { - $error = 'New objects must be assigned to a variable'; - $phpcsFile->addError($error, $stackPtr, 'NotAssigned'); + if (isset($allowedTokens[$tokens[$prev]['code']]) === true) { + return; } + $ternaryLikeTokens = [ + T_COALESCE => true, + T_INLINE_THEN => true, + T_INLINE_ELSE => true, + ]; + + // For ternary like tokens, walk a little further back to see if it is preceded by + // one of the allowed tokens (within the same statement). + if (isset($ternaryLikeTokens[$tokens[$prev]['code']]) === true) { + $hasAllowedBefore = $phpcsFile->findPrevious($allowedTokens, ($prev - 1), null, false, null, true); + if ($hasAllowedBefore !== false) { + return; + } + } + + $error = 'New objects must be assigned to a variable'; + $phpcsFile->addError($error, $stackPtr, 'NotAssigned'); + }//end process() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php index 7c7e2246..9eb21242 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php @@ -52,17 +52,18 @@ public function process(File $phpcsFile, $stackPtr) } } - // Ignore values in array definitions. - $array = $phpcsFile->findNext( - T_ARRAY, + // Ignore values in array definitions or match structures. + $nextNonEmpty = $phpcsFile->findNext( + Tokens::$emptyTokens, ($stackPtr + 1), null, - false, - null, true ); - if ($array !== false) { + if ($nextNonEmpty !== false + && ($tokens[$nextNonEmpty]['code'] === T_ARRAY + || $tokens[$nextNonEmpty]['code'] === T_MATCH) + ) { return; } diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php index 8c60208c..8a34a4f2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php @@ -54,17 +54,8 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop return; } - $modifier = null; - for ($i = ($stackPtr - 1); $i > 0; $i--) { - if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) { - break; - } else if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) { - $modifier = $i; - break; - } - } - - if ($modifier === null) { + $properties = $phpcsFile->getMethodProperties($stackPtr); + if ($properties['scope_specified'] === false) { $error = 'Visibility must be declared on method "%s"'; $data = [$methodName]; $phpcsFile->addError($error, $stackPtr, 'Missing', $data); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php index 0bafbf4d..f3b5495d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php @@ -22,7 +22,7 @@ class StaticThisUsageSniff extends AbstractScopeSniff */ public function __construct() { - parent::__construct([T_CLASS, T_TRAIT, T_ANON_CLASS], [T_FUNCTION]); + parent::__construct([T_CLASS, T_TRAIT, T_ENUM, T_ANON_CLASS], [T_FUNCTION]); }//end __construct() @@ -76,9 +76,9 @@ public function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) /** * Check for $this variable usage between $next and $end tokens. * - * @param File $phpcsFile The current file being scanned. - * @param int $next The position of the next token to check. - * @param int $end The position of the last token to check. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being scanned. + * @param int $next The position of the next token to check. + * @param int $end The position of the last token to check. * * @return void */ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index f38fd0e8..808888f4 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -145,6 +145,7 @@ public function process(File $phpcsFile, $stackPtr) T_CLASS => true, T_INTERFACE => true, T_TRAIT => true, + T_ENUM => true, T_DOC_COMMENT_OPEN_TAG => true, ]; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php index f0c84fb8..0ece1aca 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php @@ -55,11 +55,26 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) $endOfStatement = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1), null, false, null, true); - $ignore = $validPrefixes; - $ignore[] = T_WHITESPACE; + $ignore = $validPrefixes; + $ignore[T_WHITESPACE] = T_WHITESPACE; $start = $startOfStatement; - $prev = $phpcsFile->findPrevious($ignore, ($startOfStatement - 1), null, true); + for ($prev = ($startOfStatement - 1); $prev >= 0; $prev--) { + if (isset($ignore[$tokens[$prev]['code']]) === true) { + continue; + } + + if ($tokens[$prev]['code'] === T_ATTRIBUTE_END + && isset($tokens[$prev]['attribute_opener']) === true + ) { + $prev = $tokens[$prev]['attribute_opener']; + $start = $prev; + continue; + } + + break; + } + if (isset(Tokens::$commentTokens[$tokens[$prev]['code']]) === true) { // Assume the comment belongs to the member var if it is on a line by itself. $prevContent = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); @@ -67,28 +82,48 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) // Check the spacing, but then skip it. $foundLines = ($tokens[$startOfStatement]['line'] - $tokens[$prev]['line'] - 1); if ($foundLines > 0) { - $error = 'Expected 0 blank lines after member var comment; %s found'; - $data = [$foundLines]; - $fix = $phpcsFile->addFixableError($error, $prev, 'AfterComment', $data); - if ($fix === true) { - $phpcsFile->fixer->beginChangeset(); - // Inline comments have the newline included in the content but - // docblock do not. - if ($tokens[$prev]['code'] === T_COMMENT) { - $phpcsFile->fixer->replaceToken($prev, rtrim($tokens[$prev]['content'])); + for ($i = ($prev + 1); $i < $startOfStatement; $i++) { + if ($tokens[$i]['column'] !== 1) { + continue; } - for ($i = ($prev + 1); $i <= $startOfStatement; $i++) { - if ($tokens[$i]['line'] === $tokens[$startOfStatement]['line']) { - break; - } - - $phpcsFile->fixer->replaceToken($i, ''); - } - - $phpcsFile->fixer->addNewline($prev); - $phpcsFile->fixer->endChangeset(); - } + if ($tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] !== $tokens[($i + 1)]['line'] + ) { + $error = 'Expected 0 blank lines after member var comment; %s found'; + $data = [$foundLines]; + $fix = $phpcsFile->addFixableError($error, $prev, 'AfterComment', $data); + if ($fix === true) { + $phpcsFile->fixer->beginChangeset(); + // Inline comments have the newline included in the content but + // docblocks do not. + if ($tokens[$prev]['code'] === T_COMMENT) { + $phpcsFile->fixer->replaceToken($prev, rtrim($tokens[$prev]['content'])); + } + + for ($i = ($prev + 1); $i <= $startOfStatement; $i++) { + if ($tokens[$i]['line'] === $tokens[$startOfStatement]['line']) { + break; + } + + // Remove the newline after the docblock, and any entirely + // empty lines before the member var. + if ($tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] === $tokens[$prev]['line'] + || ($tokens[$i]['column'] === 1 + && $tokens[$i]['line'] !== $tokens[($i + 1)]['line']) + ) { + $phpcsFile->fixer->replaceToken($i, ''); + } + } + + $phpcsFile->fixer->addNewline($prev); + $phpcsFile->fixer->endChangeset(); + }//end if + + break; + }//end if + }//end for }//end if $start = $prev; @@ -106,7 +141,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr) $first = $tokens[$start]['comment_opener']; } else { $first = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($start - 1), null, true); - $first = $phpcsFile->findNext(Tokens::$commentTokens, ($first + 1)); + $first = $phpcsFile->findNext(array_merge(Tokens::$commentTokens, [T_ATTRIBUTE]), ($first + 1)); } // Determine if this is the first member var. diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 2627d10d..f1e2fce6 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -77,12 +77,13 @@ public function register() // Returning/printing a negative value; eg. (return -1). $this->nonOperandTokens += [ - T_RETURN => T_RETURN, - T_ECHO => T_ECHO, - T_EXIT => T_EXIT, - T_PRINT => T_PRINT, - T_YIELD => T_YIELD, - T_FN_ARROW => T_FN_ARROW, + T_RETURN => T_RETURN, + T_ECHO => T_ECHO, + T_EXIT => T_EXIT, + T_PRINT => T_PRINT, + T_YIELD => T_YIELD, + T_FN_ARROW => T_FN_ARROW, + T_MATCH_ARROW => T_MATCH_ARROW, ]; // Trying to use a negative value; eg. myFunction($var, -2). diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php index f6861393..fd038753 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php @@ -65,11 +65,20 @@ public function process(File $phpcsFile, $stackPtr) // Check that the closing brace is on it's own line. $lastContent = $phpcsFile->findPrevious([T_INLINE_HTML, T_WHITESPACE, T_OPEN_TAG], ($scopeEnd - 1), $scopeStart, true); - if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { + for ($lineStart = $scopeEnd; $tokens[$lineStart]['column'] > 1; $lineStart--); + + if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line'] + || ($tokens[$lineStart]['code'] === T_INLINE_HTML + && trim($tokens[$lineStart]['content']) !== '') + ) { $error = 'Closing brace must be on a line by itself'; $fix = $phpcsFile->addFixableError($error, $scopeEnd, 'ContentBefore'); if ($fix === true) { - $phpcsFile->fixer->addNewlineBefore($scopeEnd); + if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) { + $phpcsFile->fixer->addNewlineBefore($scopeEnd); + } else { + $phpcsFile->fixer->addNewlineBefore(($lineStart + 1)); + } } return; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php index ad995dc4..2d800f05 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php @@ -26,6 +26,7 @@ public function register() { $register = Tokens::$scopeModifiers; $register[] = T_STATIC; + $register[] = T_READONLY; return $register; }//end register() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php index 831e8327..e99d829b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php @@ -49,6 +49,7 @@ public function register() { return [ T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, T_CLOSE_TAG, T_WHITESPACE, T_COMMENT, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc index 750aaebc..2774660c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc @@ -475,6 +475,13 @@ yield array( static fn () : string => '', ); +$foo = [ + 'foo' => match ($anything) { + 'foo' => 'bar', + default => null, + }, + ]; + // Intentional syntax error. $a = array( 'a' => diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc.fixed index 3ecc091d..b4520064 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc.fixed @@ -511,6 +511,13 @@ yield array( static fn () : string => '', ); +$foo = [ + 'foo' => match ($anything) { + 'foo' => 'bar', + default => null, + }, + ]; + // Intentional syntax error. $a = array( 'a' => diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc index a346a00f..8b5a5aa7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.inc @@ -5,7 +5,8 @@ class ClassFileNameUnitTest {} interface ClassFileNameUnitTest {} trait ClassFileNameUnitTest {} - +enum ClassFileNameUnitTest {} +enum ClassFileNameUnitTest: int {} // Invalid filename matching class name (case sensitive). class classFileNameUnitTest {} @@ -17,6 +18,9 @@ interface CLASSFILENAMEUNITTEST {} trait classFileNameUnitTest {} trait classfilenameunittest {} trait CLASSFILENAMEUNITTEST {} +enum classFileNameUnitTest {} +enum classfilenameunittest {} +enum CLASSFILENAMEUNITTEST {} // Invalid non-filename matching class names. @@ -32,6 +36,10 @@ trait CompletelyWrongClassName {} trait ClassFileNameUnitTestExtra {} trait ClassFileNameUnitTestInc {} trait ExtraClassFileNameUnitTest {} +enum CompletelyWrongClassName {} +enum ClassFileNameUnitTestExtra {} +enum ClassFileNameUnitTestInc {} +enum ExtraClassFileNameUnitTest {} -?> \ No newline at end of file +?> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.php index b229a2fc..5964d2b1 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ClassFileNameUnitTest.php @@ -26,7 +26,6 @@ class ClassFileNameUnitTest extends AbstractSniffUnitTest public function getErrorList() { return [ - 11 => 1, 12 => 1, 13 => 1, 14 => 1, @@ -35,10 +34,10 @@ public function getErrorList() 17 => 1, 18 => 1, 19 => 1, + 20 => 1, + 21 => 1, + 22 => 1, 23 => 1, - 24 => 1, - 25 => 1, - 26 => 1, 27 => 1, 28 => 1, 29 => 1, @@ -47,6 +46,14 @@ public function getErrorList() 32 => 1, 33 => 1, 34 => 1, + 35 => 1, + 36 => 1, + 37 => 1, + 38 => 1, + 39 => 1, + 40 => 1, + 41 => 1, + 42 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc index 511bbe47..ea8cd89e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc @@ -3,6 +3,7 @@ Abstract Class MyClass Extends MyClass {} Final Class MyClass Implements MyInterface {} Interface MyInterface {} Trait MyTrait {} +Enum MyEnum IMPLEMENTS Colorful {} class MyClass { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed index 859d0d2d..f5739052 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.inc.fixed @@ -3,6 +3,7 @@ abstract class MyClass extends MyClass {} final class MyClass implements MyInterface {} interface MyInterface {} trait MyTrait {} +enum MyEnum implements Colorful {} class MyClass { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php index f2fc20b4..8c4d10c7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/LowercaseClassKeywordsUnitTest.php @@ -30,9 +30,10 @@ public function getErrorList() 3 => 3, 4 => 1, 5 => 1, - 9 => 1, + 6 => 2, 10 => 1, - 13 => 1, + 11 => 1, + 14 => 1, ]; return $errors; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc index aadbab5b..3fe39435 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc @@ -137,6 +137,50 @@ trait Base } } +// Valid enum name. +enum ValidCamelCaseClass: string {} + + +// Incorrect usage of camel case. +enum invalidCamelCaseClass {} +enum Invalid_Camel_Case_Class_With_Underscores {} + + +// All lowercase. +enum invalidlowercaseclass: INT {} +enum invalid_lowercase_class_with_underscores {} + + +// All uppercase. +enum VALIDUPPERCASECLASS: int {} +enum INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES {} + + +// Mix camel case with uppercase. +enum ValidCamelCaseClassWithUPPERCASE : string {} + + +// Usage of numeric characters. +enum ValidCamelCaseClassWith1Number {} +enum ValidCamelCaseClassWith12345Numbers : string {} +enum ValidCamelCaseClassEndingWithNumber5 {} + +enum Testing{} + +enum Base +{ + public function __construct() + { + $this->anonymous = new class extends ArrayObject + { + public function __construct() + { + parent::__construct(['a' => 1, 'b' => 2]); + } + }; + } +} + if ( class_exists( Test :: class ) ) {} if ( class_exists( Test2 ::class ) ) {} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php index 70777c54..b7de260b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php @@ -47,6 +47,11 @@ public function getErrorList() 108 => 1, 118 => 1, 120 => 1, + 145 => 1, + 146 => 1, + 150 => 1, + 151 => 1, + 156 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc index 877bca64..7cd04a21 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc @@ -256,3 +256,54 @@ $y = 10 + /* test */ -2; /* * No blank line allowed above the comment if it's the first non-empty token after a PHP open tag. */ + +?> + + + + 1, 233 => 1, 256 => 1, + 271 => 1, + 273 => 1, ]; return $errors; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.inc index 9c3255cf..1a57149b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.inc @@ -79,4 +79,8 @@ class TestClass } //end class -?> \ No newline at end of file +enum MissingClosingComment { +} + +enum HasClosingComment { +}//end enum diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php index cdc89ba6..6f5166ec 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.php @@ -34,6 +34,7 @@ public function getErrorList() 63 => 1, 67 => 1, 79 => 1, + 83 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc index e7d880d6..e42cf8ab 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc @@ -77,6 +77,26 @@ class MyClass2 var $x; } +abstract class MyClass +{ + /** +* Property comment + */ + readonly public string $prop; +} + +/** + * Some info about the enum here + * +*/ +enum Suits: string +{ + /** + * Some info about the case here. + */ + case HEARTS; +} + /** ************************************************************************ * Example with no errors. **************************************************************************/ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed index 4d8cb392..6182b539 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed @@ -77,6 +77,26 @@ class MyClass2 var $x; } +abstract class MyClass +{ + /** + * Property comment + */ + readonly public string $prop; +} + +/** + * Some info about the enum here + * + */ +enum Suits: string +{ + /** + * Some info about the case here. + */ + case HEARTS; +} + /** ************************************************************************ * Example with no errors. **************************************************************************/ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php index 974951ce..acbf13e8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php @@ -45,6 +45,12 @@ public function getErrorList($testFile='DocCommentAlignmentUnitTest.inc') if ($testFile === 'DocCommentAlignmentUnitTest.inc') { $errors[75] = 1; + $errors[83] = 1; + $errors[84] = 1; + $errors[90] = 1; + $errors[91] = 1; + $errors[95] = 1; + $errors[96] = 1; } return $errors; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.inc.fixed index 5cc47642..3bcd9453 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.inc.fixed @@ -25,7 +25,7 @@ * @author * @copyright 1997 Squiz Pty Ltd (ABN 77 084 670 600) * @copyright 1994-1997 Squiz Pty Ltd (ABN 77 084 670 600) -* @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) +* @copyright 2023 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://www.php.net/license/3_0.txt * @summary An unknown summary tag * diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.js.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.js.fixed index b2b071f4..56a392d9 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.js.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.1.js.fixed @@ -25,7 +25,7 @@ * @author * @copyright 1997 Squiz Pty Ltd (ABN 77 084 670 600) * @copyright 1994-1997 Squiz Pty Ltd (ABN 77 084 670 600) -* @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) +* @copyright 2023 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://www.php.net/license/3_0.txt * @summary An unknown summary tag * diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc new file mode 100644 index 00000000..5ef90f2a --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.8.inc @@ -0,0 +1,9 @@ + + * @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600) + */ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.9.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.9.inc new file mode 100644 index 00000000..f6c9d996 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.9.inc @@ -0,0 +1,12 @@ + + * @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600) + */ + +enum Foo { +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php index 080df3aa..ee81369a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php @@ -45,6 +45,7 @@ public function getErrorList($testFile='FileCommentUnitTest.inc') case 'FileCommentUnitTest.4.inc': case 'FileCommentUnitTest.6.inc': case 'FileCommentUnitTest.7.inc': + case 'FileCommentUnitTest.9.inc': return [1 => 1]; case 'FileCommentUnitTest.5.inc': diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc index deaa966e..4f59f60b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -1041,3 +1041,8 @@ public function ignored() { } // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct + +/** + * @return void + * @throws Exception If any other error occurs. */ +function throwCommentOneLine() {} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index b46df26b..21a4103e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -1041,3 +1041,8 @@ public function ignored() { } // phpcs:set Squiz.Commenting.FunctionComment specialMethods[] __construct,__destruct + +/** + * @return void + * @throws Exception If any other error occurs. */ +function throwCommentOneLine() {} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc index 377db023..10a0b4b4 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc @@ -149,6 +149,30 @@ if ($foo) { // another comment here. $foo++; +/** + * Comment should be ignored, even though there is an attribute between the docblock and the class declaration. + */ + +#[AttributeA] + +final class MyClass +{ + /** + * Comment should be ignored, even though there is an attribute between the docblock and the function declaration + */ + #[AttributeA] + #[AttributeB] + final public function test() {} +} + +/** + * Comment should be ignored. + * + */ +enum MyEnum { + +} + /* * N.B.: The below test line must be the last test in the file. * Testing that a new line after an inline comment when it's the last non-whitespace diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed index 975143f2..97ae0149 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/InlineCommentUnitTest.inc.fixed @@ -142,6 +142,30 @@ if ($foo) { // another comment here. $foo++; +/** + * Comment should be ignored, even though there is an attribute between the docblock and the class declaration. + */ + +#[AttributeA] + +final class MyClass +{ + /** + * Comment should be ignored, even though there is an attribute between the docblock and the function declaration + */ + #[AttributeA] + #[AttributeB] + final public function test() {} +} + +/** + * Comment should be ignored. + * + */ +enum MyEnum { + +} + /* * N.B.: The below test line must be the last test in the file. * Testing that a new line after an inline comment when it's the last non-whitespace diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc index 65f4389b..36efc443 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc @@ -363,3 +363,42 @@ class Foo var int $noComment = 1; } + +class HasAttributes +{ + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\Id]#[ORM\Column("integer")] + private $id; + + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\GeneratedValue] + #[ORM\Column(ORM\Column::T_INTEGER)] + protected $height; +} + +class ReadOnlyProps +{ + /** + * Short description of the member variable. + * + * @var array + */ + public readonly array $variableName = array(); + + /** + * Short description of the member variable. + * + * @var + */ + readonly protected ?int $variableName = 10; + + private readonly string $variable; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed index ca0b052e..5c652f54 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc.fixed @@ -363,3 +363,42 @@ class Foo var int $noComment = 1; } + +class HasAttributes +{ + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\Id]#[ORM\Column("integer")] + private $id; + + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\GeneratedValue] + #[ORM\Column(ORM\Column::T_INTEGER)] + protected $height; +} + +class ReadOnlyProps +{ + /** + * Short description of the member variable. + * + * @var array + */ + public readonly array $variableName = array(); + + /** + * Short description of the member variable. + * + * @var + */ + readonly protected ?int $variableName = 10; + + private readonly string $variable; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php index f3ee3c76..1af5e148 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.php @@ -58,6 +58,8 @@ public function getErrorList() 336 => 1, 361 => 1, 364 => 1, + 399 => 1, + 403 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Files/FileExtensionUnitTest.5.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Files/FileExtensionUnitTest.5.inc new file mode 100644 index 00000000..d777aff6 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Files/FileExtensionUnitTest.5.inc @@ -0,0 +1,3 @@ + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc index 2a480bb9..8e628963 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc @@ -193,3 +193,11 @@ $expr = match (true) { if ($pos === count(value: $this->tokens) - 1) { $file = '...'.substr(string: $file, offset: $padding * -1 + 3); } + +match ($a) { + 'a' => -1, + 'b', 'c', 'd' => -2, + default => -3, +}; + +$cntPages = ceil(count($items) / parent::ON_PAGE); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc.fixed index 669b16b2..9fa0216c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc.fixed @@ -193,3 +193,11 @@ $expr = match (true) { if ($pos === (count(value: $this->tokens) - 1)) { $file = '...'.substr(string: $file, offset: ($padding * -1 + 3)); } + +match ($a) { + 'a' => -1, + 'b', 'c', 'd' => -2, + default => -3, +}; + +$cntPages = ceil(count($items) / parent::ON_PAGE); diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc index 3076104a..fce0b237 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc @@ -197,3 +197,61 @@ function foo( $bar ) { } + +class ConstructorPropertyPromotionSingleLineDocblockIndentOK +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIndentOK +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionSingleLineDocblockIncorrectIndent +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, +/** + * @var string + * @Assert\NotBlank() + */ +#[NotBlank] +private string $private, + ) { + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc.fixed index 4965f237..b927a001 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc.fixed @@ -209,3 +209,61 @@ function foo( $bar ) { } + +class ConstructorPropertyPromotionSingleLineDocblockIndentOK +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIndentOK +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionSingleLineDocblockIncorrectIndent +{ + public function __construct( + /** @var string */ + public string $public, + /** @var string */ + private string $private, + ) { + } +} + +class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent +{ + public function __construct( + /** + * @var string + * @Assert\NotBlank() + */ + public string $public, + /** + * @var string + * @Assert\NotBlank() + */ + #[NotBlank] + private string $private, + ) { + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php index caf14d1d..5208ad0c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php @@ -55,7 +55,21 @@ public function getErrorList($testFile='MultiLineFunctionDeclarationUnitTest.inc 190 => 2, 194 => 1, 195 => 1, - 196 => 1, + 233 => 1, + 234 => 1, + 235 => 1, + 236 => 1, + 244 => 1, + 245 => 1, + 246 => 1, + 247 => 1, + 248 => 1, + 249 => 1, + 250 => 1, + 251 => 1, + 252 => 1, + 253 => 1, + 254 => 1, ]; } else { $errors = [ diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc new file mode 100644 index 00000000..87c3bdf2 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -0,0 +1,157 @@ +varName2; +echo $this->var_name2; +echo $this->varname2; +echo $this->_varName2; +echo $object->varName2; +echo $object->var_name2; +echo $object_name->varname2; +echo $object_name->_varName2; + +echo $this->myFunction($one, $two); +echo $object->myFunction($one_two); + +$error = "format is \$GLOBALS['$varName']"; + +echo $_SESSION['var_name']; +echo $_FILES['var_name']; +echo $_ENV['var_name']; +echo $_COOKIE['var_name']; + +$XML = 'hello'; +$myXML = 'hello'; +$XMLParser = 'hello'; +$xmlParser = 'hello'; + +echo "{$_SERVER['HOSTNAME']} $var_name"; + +// Need to be the last thing in this test file. +$obj->$classVar = $prefix.'-'.$type; + +class foo +{ + const bar = <<varName; +echo $obj?->var_name; +echo $obj?->varname; +echo $obj?->_varName; + +enum SomeEnum +{ + public function foo($foo, $_foo, $foo_bar) { + $bar = 1; + $_bar = 2; + $bar_foo = 3; + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php index aaa9d099..9acbe241 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -61,6 +61,8 @@ public function getErrorList() 138 => 1, 141 => 1, 146 => 1, + 152 => 1, + 155 => 1, ]; return $errors; diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.inc index f58af275..41c88128 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.inc @@ -23,6 +23,24 @@ function returnMatch() { } } +// Issue 3333. +$time2 ??= new \DateTime(); +$time3 = $time1 ?? new \DateTime(); +$time3 = $time1 ?? $time2 ?? new \DateTime(); + +function_call($time1 ?? new \DateTime()); +$return = function_call($time1 ?? new \DateTime()); // False negative depending on interpretation of the sniff. + +function returnViaTernary() { + return ($y == false ) ? ($x === true ? new Foo : new Bar) : new FooBar; +} + +function nonAssignmentTernary() { + if (($x ? new Foo() : new Bar) instanceof FooBar) { + // Do something. + } +} + // Intentional parse error. This must be the last test in the file. function new ?> diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.php index fa32521c..f9979fa2 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.php @@ -26,8 +26,10 @@ class ObjectInstantiationUnitTest extends AbstractSniffUnitTest public function getErrorList() { return [ - 5 => 1, - 8 => 1, + 5 => 1, + 8 => 1, + 31 => 1, + 39 => 2, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/CommentedOutCodeUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/CommentedOutCodeUnitTest.php index d51f23ca..36c556d8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/CommentedOutCodeUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/CommentedOutCodeUnitTest.php @@ -49,7 +49,6 @@ public function getWarningList($testFile='CommentedOutCodeUnitTest.inc') 8 => 1, 15 => 1, 19 => 1, - 35 => 1, 87 => 1, 91 => 1, 97 => 1, diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc index 022aca73..a07047b1 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc @@ -71,3 +71,13 @@ $callback = function ($value) { return false; } }; + +function issue3616() { + $food = 'cake'; + + $returnValue = match (true) { + $food === 'apple' => 'This food is an apple', + $food === 'bar' => 'This food is a bar', + $food === 'cake' => 'This food is a cake', + }; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc index 407c4740..c9bf052f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.2.inc @@ -45,6 +45,12 @@ trait Something { } } +enum Something { + function getReturnType() { + echo 'no error'; + } +} + $a = new class { public function log($msg) { diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.php index f66eb3f7..f5f90c0b 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.php @@ -83,7 +83,7 @@ public function getWarningList($testFile='') 9 => 1, 10 => 2, 14 => 1, - 48 => 2, + 54 => 2, ]; break; default: diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc index cec0355c..3cc617d7 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.inc @@ -40,3 +40,18 @@ class Nested { }; } } + +enum SomeEnum +{ + function func1() {} + public function func1() {} + private function func1() {} + protected function func1() {} +} + +class UnconventionalSpacing { + public + static + function + myFunction() {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.php index 7fdab23b..4dc71779 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/MethodScopeUnitTest.php @@ -29,6 +29,7 @@ public function getErrorList() 6 => 1, 30 => 1, 39 => 1, + 46 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc index 38b443f2..dd6530e8 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc @@ -115,3 +115,13 @@ $b = new class() return $This; } } + +enum MyEnum { + private function notStatic () { + $this->doSomething(); + } + + public static function myFunc() { + $this->doSomething(); + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php index 2935241b..b1a5dd6a 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.php @@ -26,18 +26,19 @@ class StaticThisUsageUnitTest extends AbstractSniffUnitTest public function getErrorList() { return [ - 7 => 1, - 8 => 1, - 9 => 1, - 14 => 1, - 20 => 1, - 41 => 1, - 61 => 1, - 69 => 1, - 76 => 1, - 80 => 1, - 84 => 1, - 99 => 1, + 7 => 1, + 8 => 1, + 9 => 1, + 14 => 1, + 20 => 1, + 41 => 1, + 61 => 1, + 69 => 1, + 76 => 1, + 80 => 1, + 84 => 1, + 99 => 1, + 125 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc index 0371ce49..70abae43 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc @@ -261,3 +261,9 @@ $expr = match( $foo ){ }; echo $expr; + +if($true) { + + enum SomeEnum {} + +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed index ad4505c3..c64de25e 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed @@ -253,3 +253,9 @@ $expr = match($foo){ }; echo $expr; + +if($true) { + + enum SomeEnum {} + +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc index fd7c6e34..12b55176 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc @@ -332,3 +332,43 @@ class CommentedOutCodeAtStartOfClassNoBlankLine { */ public $property = true; } + +class HasAttributes +{ + /** + * Short description of the member variable. + * + * @var array + */ + + #[ORM\Id]#[ORM\Column("integer")] + + private $id; + + + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\GeneratedValue] + + #[ORM\Column(ORM\Column::T_INTEGER)] + protected $height; + + #[SingleAttribute] + protected $propertySingle; + + #[FirstAttribute] + #[SecondAttribute] + protected $propertyDouble; + #[ThirdAttribute] + protected $propertyWithoutSpacing; +} + +enum SomeEnum +{ + // Enum cannot have properties + + case ONE = 'one'; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc.fixed index b6ebcc9a..d683eaad 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc.fixed @@ -319,3 +319,41 @@ class CommentedOutCodeAtStartOfClassNoBlankLine { */ public $property = true; } + +class HasAttributes +{ + + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\Id]#[ORM\Column("integer")] + private $id; + + /** + * Short description of the member variable. + * + * @var array + */ + #[ORM\GeneratedValue] + #[ORM\Column(ORM\Column::T_INTEGER)] + protected $height; + + #[SingleAttribute] + protected $propertySingle; + + #[FirstAttribute] + #[SecondAttribute] + protected $propertyDouble; + + #[ThirdAttribute] + protected $propertyWithoutSpacing; +} + +enum SomeEnum +{ + // Enum cannot have properties + + case ONE = 'one'; +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php index 08a11bca..9b406681 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php @@ -57,6 +57,11 @@ public function getErrorList() 288 => 1, 292 => 1, 333 => 1, + 342 => 1, + 346 => 1, + 353 => 1, + 357 => 1, + 366 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc index f89cf08d..06462acc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc @@ -477,5 +477,11 @@ $a = 'a '.-$b; $a = 'a '.- MY_CONSTANT; $a = 'a '.- $b; +match ($a) { + 'a' => -1, + 'b', 'c', 'd' => -2, + default => -3, +}; + /* Intentional parse error. This has to be the last test in the file. */ $a = 10 + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed index 138616e7..8b92a487 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed @@ -471,5 +471,11 @@ $a = 'a '.-$b; $a = 'a '.- MY_CONSTANT; $a = 'a '.- $b; +match ($a) { + 'a' => -1, + 'b', 'c', 'd' => -2, + default => -3, +}; + /* Intentional parse error. This has to be the last test in the file. */ $a = 10 + diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc index b71c0be7..ecae5c6d 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc @@ -114,3 +114,21 @@ $match = match ($test) { 1 => 'a', 2 => 'b' }; + +?> + +
+ +
+ + 'a', 2 => 'b' }; + +?> + +
+ +
+ + + 1, 111 => 1, 116 => 1, + 122 => 1, + 130 => 1, + 134 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc index 22138171..12685dc9 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc @@ -126,3 +126,16 @@ class ConstructorPropertyPromotionTest { class ConstructorPropertyPromotionWithTypesTest { public function __construct(protected float|int $x, public?string &$y = 'test', private mixed $z) {} } + +// PHP 8.1 readonly keywords. +class ReadonlyTest { + public readonly int $publicReadonlyProperty; + + protected readonly int $protectedReadonlyProperty; + + readonly protected int $protectedReadonlyProperty; + + readonly private int $privateReadonlyProperty; + + public function __construct(readonly protected float|int $x, public readonly?string &$y = 'test') {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed index e642f0c7..d3b682ed 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed @@ -120,3 +120,16 @@ class ConstructorPropertyPromotionTest { class ConstructorPropertyPromotionWithTypesTest { public function __construct(protected float|int $x, public ?string &$y = 'test', private mixed $z) {} } + +// PHP 8.1 readonly keywords. +class ReadonlyTest { + public readonly int $publicReadonlyProperty; + + protected readonly int $protectedReadonlyProperty; + + readonly protected int $protectedReadonlyProperty; + + readonly private int $privateReadonlyProperty; + + public function __construct(readonly protected float|int $x, public readonly ?string &$y = 'test') {} +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.php index de4697c0..30b66215 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.php @@ -44,6 +44,9 @@ public function getErrorList() 119 => 1, 121 => 1, 127 => 2, + 134 => 2, + 138 => 2, + 140 => 3, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.inc new file mode 100644 index 00000000..3325e115 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -0,0 +1,131 @@ +varName; +echo $this->var_name; +echo $this->varname; +echo $this->_varName; +echo $this->varName2; +echo $object->varName; +echo $object->var_name; +echo $object->varName2; +echo $object_name->varname; +echo $object_name->_varName; +echo $object_name->varName2; + +echo $this->myFunction($one, $two); +echo $object->myFunction($one_two, $var2); + +$error = "format is \$GLOBALS['$varName']"; +$error = "format is \$GLOBALS['$varName2']"; + +echo $_SESSION['var_name']; +echo $_FILES['var_name']; +echo $_ENV['var_name']; +echo $_COOKIE['var_name']; +echo $_COOKIE['var_name2']; + +$XML = 'hello'; +$myXML = 'hello'; +$XMLParser = 'hello'; +$xmlParser = 'hello'; +$xmlParser2 = 'hello'; + +echo "{$_SERVER['HOSTNAME']} $var_name"; + +$someObject->{$name}; +$someObject->my_function($var_name); + +var_dump($http_response_header); +var_dump($HTTP_RAW_POST_DATA); +var_dump($php_errormsg); + +interface Base +{ + protected $anonymous; + + public function __construct(); +} + +$anonClass = new class() { + public function foo($foo, $_foo, $foo_bar) { + $bar = 1; + $_bar = 2; + $bar_foo = 3; + } +}; + +echo $obj?->varName; +echo $obj?->var_name; +echo $obj?->varName; + +enum SomeEnum +{ + public function foo($foo, $_foo, $foo_bar) { + $bar = 1; + $_bar = 2; + $bar_foo = 3; + } +} diff --git a/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.php b/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.php index 916b334f..e57c7356 100644 --- a/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/vendor/squizlabs/php_codesniffer/src/Standards/Zend/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -54,6 +54,8 @@ public function getErrorList() 113 => 1, 116 => 1, 121 => 1, + 126 => 1, + 129 => 1, ]; }//end getErrorList() diff --git a/vendor/squizlabs/php_codesniffer/src/Tokenizers/PHP.php b/vendor/squizlabs/php_codesniffer/src/Tokenizers/PHP.php index 1924cf07..3fc67b0c 100644 --- a/vendor/squizlabs/php_codesniffer/src/Tokenizers/PHP.php +++ b/vendor/squizlabs/php_codesniffer/src/Tokenizers/PHP.php @@ -152,6 +152,13 @@ class PHP extends Tokenizer 'shared' => false, 'with' => [], ], + T_ENUM => [ + 'start' => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET], + 'end' => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET], + 'strict' => true, + 'shared' => false, + 'with' => [], + ], T_USE => [ 'start' => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET], 'end' => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET], @@ -339,6 +346,8 @@ class PHP extends Tokenizer T_ENDIF => 5, T_ENDSWITCH => 9, T_ENDWHILE => 8, + T_ENUM => 4, + T_ENUM_CASE => 4, T_EVAL => 4, T_EXTENDS => 7, T_FILE => 8, @@ -393,6 +402,7 @@ class PHP extends Tokenizer T_PRIVATE => 7, T_PUBLIC => 6, T_PROTECTED => 9, + T_READONLY => 8, T_REQUIRE => 7, T_REQUIRE_ONCE => 12, T_RETURN => 6, @@ -452,6 +462,32 @@ class PHP extends Tokenizer T_OPEN_SHORT_ARRAY => 1, T_CLOSE_SHORT_ARRAY => 1, T_TYPE_UNION => 1, + T_TYPE_INTERSECTION => 1, + ]; + + /** + * Contexts in which keywords should always be tokenized as T_STRING. + * + * @var array + */ + protected $tstringContexts = [ + T_OBJECT_OPERATOR => true, + T_NULLSAFE_OBJECT_OPERATOR => true, + T_FUNCTION => true, + T_CLASS => true, + T_INTERFACE => true, + T_TRAIT => true, + T_ENUM => true, + T_ENUM_CASE => true, + T_EXTENDS => true, + T_IMPLEMENTS => true, + T_ATTRIBUTE => true, + T_NEW => true, + T_CONST => true, + T_NS_SEPARATOR => true, + T_USE => true, + T_NAMESPACE => true, + T_PAAMAYIM_NEKUDOTAYIM => true, ]; /** @@ -478,7 +514,7 @@ protected function tokenize($string) if (PHP_CODESNIFFER_VERBOSITY > 1) { echo "\t*** START PHP TOKENIZING ***".PHP_EOL; $isWin = false; - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + if (stripos(PHP_OS, 'WIN') === 0) { $isWin = true; } } @@ -565,6 +601,86 @@ protected function tokenize($string) echo PHP_EOL; } + /* + Tokenize context sensitive keyword as string when it should be string. + */ + + if ($tokenIsArray === true + && isset(Util\Tokens::$contextSensitiveKeywords[$token[0]]) === true + && (isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === true + || $finalTokens[$lastNotEmptyToken]['content'] === '&') + ) { + if (isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === true) { + $preserveKeyword = false; + + // `new class`, and `new static` should be preserved. + if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW + && ($token[0] === T_CLASS + || $token[0] === T_STATIC) + ) { + $preserveKeyword = true; + } + + // `new class extends` `new class implements` should be preserved + if (($token[0] === T_EXTENDS || $token[0] === T_IMPLEMENTS) + && $finalTokens[$lastNotEmptyToken]['code'] === T_CLASS + ) { + $preserveKeyword = true; + } + + // `namespace\` should be preserved + if ($token[0] === T_NAMESPACE) { + for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { + if (is_array($tokens[$i]) === false) { + break; + } + + if (isset(Util\Tokens::$emptyTokens[$tokens[$i][0]]) === true) { + continue; + } + + if ($tokens[$i][0] === T_NS_SEPARATOR) { + $preserveKeyword = true; + } + + break; + } + } + }//end if + + if ($finalTokens[$lastNotEmptyToken]['content'] === '&') { + $preserveKeyword = true; + + for ($i = ($lastNotEmptyToken - 1); $i >= 0; $i--) { + if (isset(Util\Tokens::$emptyTokens[$finalTokens[$i]['code']]) === true) { + continue; + } + + if ($finalTokens[$i]['code'] === T_FUNCTION) { + $preserveKeyword = false; + } + + break; + } + } + + if ($preserveKeyword === false) { + if (PHP_CODESNIFFER_VERBOSITY > 1) { + $type = Util\Tokens::tokenName($token[0]); + echo "\t\t* token $stackPtr changed from $type to T_STRING".PHP_EOL; + } + + $finalTokens[$newStackPtr] = [ + 'code' => T_STRING, + 'type' => 'T_STRING', + 'content' => $token[1], + ]; + + $newStackPtr++; + continue; + } + }//end if + /* Parse doc blocks into something that can be easily iterated over. */ @@ -623,6 +739,65 @@ protected function tokenize($string) }//end if }//end if + /* + For Explicit Octal Notation prior to PHP 8.1 we need to combine the + T_LNUMBER and T_STRING token values into a single token value, and + then ignore the T_STRING token. + */ + + if (PHP_VERSION_ID < 80100 + && $tokenIsArray === true && $token[1] === '0' + && (isset($tokens[($stackPtr + 1)]) === true + && is_array($tokens[($stackPtr + 1)]) === true + && $tokens[($stackPtr + 1)][0] === T_STRING + && strtolower($tokens[($stackPtr + 1)][1][0]) === 'o' + && $tokens[($stackPtr + 1)][1][1] !== '_') + && preg_match('`^(o[0-7]+(?:_[0-7]+)?)([0-9_]*)$`i', $tokens[($stackPtr + 1)][1], $matches) === 1 + ) { + $finalTokens[$newStackPtr] = [ + 'code' => T_LNUMBER, + 'type' => 'T_LNUMBER', + 'content' => $token[1] .= $matches[1], + ]; + $newStackPtr++; + + if (isset($matches[2]) === true && $matches[2] !== '') { + $type = 'T_LNUMBER'; + if ($matches[2][0] === '_') { + $type = 'T_STRING'; + } + + $finalTokens[$newStackPtr] = [ + 'code' => constant($type), + 'type' => $type, + 'content' => $matches[2], + ]; + $newStackPtr++; + } + + $stackPtr++; + continue; + }//end if + + /* + PHP 8.1 introduced two dedicated tokens for the & character. + Retokenizing both of these to T_BITWISE_AND, which is the + token PHPCS already tokenized them as. + */ + + if ($tokenIsArray === true + && ($token[0] === T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG + || $token[0] === T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG) + ) { + $finalTokens[$newStackPtr] = [ + 'code' => T_BITWISE_AND, + 'type' => 'T_BITWISE_AND', + 'content' => $token[1], + ]; + $newStackPtr++; + continue; + } + /* If this is a double quoted string, PHP will tokenize the whole thing which causes problems with the scope map when braces are @@ -649,7 +824,8 @@ protected function tokenize($string) if ($subTokenIsArray === true) { $tokenContent .= $subToken[1]; - if ($subToken[1] === '{' + if (($subToken[1] === '{' + || $subToken[1] === '${') && $subToken[0] !== T_ENCAPSED_AND_WHITESPACE ) { $nestedVars[] = $i; @@ -828,6 +1004,104 @@ protected function tokenize($string) continue; }//end if + /* + Enum keyword for PHP < 8.1 + */ + + if ($tokenIsArray === true + && $token[0] === T_STRING + && strtolower($token[1]) === 'enum' + ) { + // Get the next non-empty token. + for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { + if (is_array($tokens[$i]) === false + || isset(Util\Tokens::$emptyTokens[$tokens[$i][0]]) === false + ) { + break; + } + } + + if (isset($tokens[$i]) === true + && is_array($tokens[$i]) === true + && $tokens[$i][0] === T_STRING + ) { + // Modify $tokens directly so we can use it later when converting enum "case". + $tokens[$stackPtr][0] = T_ENUM; + + $newToken = []; + $newToken['code'] = T_ENUM; + $newToken['type'] = 'T_ENUM'; + $newToken['content'] = $token[1]; + $finalTokens[$newStackPtr] = $newToken; + + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t\t* token $stackPtr changed from T_STRING to T_ENUM".PHP_EOL; + } + + $newStackPtr++; + continue; + } + }//end if + + /* + Convert enum "case" to T_ENUM_CASE + */ + + if ($tokenIsArray === true + && $token[0] === T_CASE + && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === false + ) { + $isEnumCase = false; + $scope = 1; + + for ($i = ($stackPtr - 1); $i > 0; $i--) { + if ($tokens[$i] === '}') { + $scope++; + continue; + } + + if ($tokens[$i] === '{') { + $scope--; + continue; + } + + if (is_array($tokens[$i]) === false) { + continue; + } + + if ($scope !== 0) { + continue; + } + + if ($tokens[$i][0] === T_SWITCH) { + break; + } + + if ($tokens[$i][0] === T_ENUM || $tokens[$i][0] === T_ENUM_CASE) { + $isEnumCase = true; + break; + } + }//end for + + if ($isEnumCase === true) { + // Modify $tokens directly so we can use it as optimisation for other enum "case". + $tokens[$stackPtr][0] = T_ENUM_CASE; + + $newToken = []; + $newToken['code'] = T_ENUM_CASE; + $newToken['type'] = 'T_ENUM_CASE'; + $newToken['content'] = $token[1]; + $finalTokens[$newStackPtr] = $newToken; + + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t\t* token $stackPtr changed from T_CASE to T_ENUM_CASE".PHP_EOL; + } + + $newStackPtr++; + continue; + } + }//end if + /* As of PHP 8.0 fully qualified, partially qualified and namespace relative identifier names are tokenized differently. @@ -949,7 +1223,7 @@ protected function tokenize($string) /* Tokenize the parameter labels for PHP 8.0 named parameters as a special T_PARAM_NAME - token and ensure that the colon after it is always T_COLON. + token and ensures that the colon after it is always T_COLON. */ if ($tokenIsArray === true @@ -1004,6 +1278,38 @@ protected function tokenize($string) }//end if }//end if + /* + "readonly" keyword for PHP < 8.1 + */ + + if (PHP_VERSION_ID < 80100 + && $tokenIsArray === true + && strtolower($token[1]) === 'readonly' + && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === false + ) { + // Get the next non-whitespace token. + for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { + if (is_array($tokens[$i]) === false + || $tokens[$i][0] !== T_WHITESPACE + ) { + break; + } + } + + if (isset($tokens[$i]) === false + || $tokens[$i] !== '(' + ) { + $finalTokens[$newStackPtr] = [ + 'code' => T_READONLY, + 'type' => 'T_READONLY', + 'content' => $token[1], + ]; + $newStackPtr++; + + continue; + } + }//end if + /* Before PHP 7.0, the "yield from" was tokenized as T_YIELD, T_WHITESPACE and T_STRING. So look for @@ -1047,6 +1353,7 @@ protected function tokenize($string) && $tokenIsArray === true && $token[0] === T_STRING && strtolower($token[1]) === 'yield' + && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === false ) { if (isset($tokens[($stackPtr + 1)]) === true && isset($tokens[($stackPtr + 2)]) === true @@ -1288,6 +1595,7 @@ protected function tokenize($string) if ($newType === T_LNUMBER && ((stripos($newContent, '0x') === 0 && hexdec(str_replace('_', '', $newContent)) > PHP_INT_MAX) || (stripos($newContent, '0b') === 0 && bindec(str_replace('_', '', $newContent)) > PHP_INT_MAX) + || (stripos($newContent, '0o') === 0 && octdec(str_replace('_', '', $newContent)) > PHP_INT_MAX) || (stripos($newContent, '0x') !== 0 && stripos($newContent, 'e') !== false || strpos($newContent, '.') !== false) || (strpos($newContent, '0') === 0 && stripos($newContent, '0x') !== 0 @@ -1332,16 +1640,7 @@ protected function tokenize($string) break; } - $notMatchContext = [ - T_PAAMAYIM_NEKUDOTAYIM => true, - T_OBJECT_OPERATOR => true, - T_NULLSAFE_OBJECT_OPERATOR => true, - T_NS_SEPARATOR => true, - T_NEW => true, - T_FUNCTION => true, - ]; - - if (isset($notMatchContext[$finalTokens[$lastNotEmptyToken]['code']]) === true) { + if (isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === true) { // Also not a match expression. break; } @@ -1388,64 +1687,42 @@ protected function tokenize($string) if ($tokenIsArray === true && $token[0] === T_DEFAULT + && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === false ) { - $ignoreContext = [ - T_OBJECT_OPERATOR => true, - T_NULLSAFE_OBJECT_OPERATOR => true, - T_NS_SEPARATOR => true, - T_PAAMAYIM_NEKUDOTAYIM => true, - ]; - - if (isset($ignoreContext[$finalTokens[$lastNotEmptyToken]['code']]) === false) { - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { - if ($tokens[$x] === ',') { - // Skip over potential trailing comma (supported in PHP). - continue; - } - - if (is_array($tokens[$x]) === false - || isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]) === false - ) { - // Non-empty, non-comma content. - break; - } + for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { + if ($tokens[$x] === ',') { + // Skip over potential trailing comma (supported in PHP). + continue; } - if (isset($tokens[$x]) === true - && is_array($tokens[$x]) === true - && $tokens[$x][0] === T_DOUBLE_ARROW + if (is_array($tokens[$x]) === false + || isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]) === false ) { - // Modify the original token stack for the double arrow so that - // future checks can disregard the double arrow token more easily. - // For match expression "case" statements, this is handled - // in PHP::processAdditional(). - $tokens[$x][0] = T_MATCH_ARROW; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $x changed from T_DOUBLE_ARROW to T_MATCH_ARROW".PHP_EOL; - } - - $newToken = []; - $newToken['code'] = T_MATCH_DEFAULT; - $newToken['type'] = 'T_MATCH_DEFAULT'; - $newToken['content'] = $token[1]; + // Non-empty, non-comma content. + break; + } + } - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_DEFAULT to T_MATCH_DEFAULT".PHP_EOL; - } + if (isset($tokens[$x]) === true + && is_array($tokens[$x]) === true + && $tokens[$x][0] === T_DOUBLE_ARROW + ) { + // Modify the original token stack for the double arrow so that + // future checks can disregard the double arrow token more easily. + // For match expression "case" statements, this is handled + // in PHP::processAdditional(). + $tokens[$x][0] = T_MATCH_ARROW; + if (PHP_CODESNIFFER_VERBOSITY > 1) { + echo "\t\t* token $x changed from T_DOUBLE_ARROW to T_MATCH_ARROW".PHP_EOL; + } - $finalTokens[$newStackPtr] = $newToken; - $newStackPtr++; - continue; - }//end if - } else { - // Definitely not the "default" keyword. $newToken = []; - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; + $newToken['code'] = T_MATCH_DEFAULT; + $newToken['type'] = 'T_MATCH_DEFAULT'; $newToken['content'] = $token[1]; if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_DEFAULT to T_STRING".PHP_EOL; + echo "\t\t* token $stackPtr changed from T_DEFAULT to T_MATCH_DEFAULT".PHP_EOL; } $finalTokens[$newStackPtr] = $newToken; @@ -1550,7 +1827,7 @@ protected function tokenize($string) && isset(Util\Tokens::$emptyTokens[$tokenType]) === false ) { // Found the previous non-empty token. - if ($tokenType === ':' || $tokenType === ',') { + if ($tokenType === ':' || $tokenType === ',' || $tokenType === T_ATTRIBUTE_END) { $newToken['code'] = T_NULLABLE; $newToken['type'] = 'T_NULLABLE'; @@ -1642,14 +1919,9 @@ protected function tokenize($string) } /* - The string-like token after a function keyword should always be - tokenized as T_STRING even if it appears to be a different token, - such as when writing code like: function default(): foo - so go forward and change the token type before it is processed. - - Note: this should not be done for `function Level\Name` within a - group use statement for the PHP 8 identifier name tokens as it - would interfere with the re-tokenization of those. + This is a special condition for T_ARRAY tokens used for + function return types. We want to keep the parenthesis map clean, + so let's tag these tokens as T_STRING. */ if ($tokenIsArray === true @@ -1657,36 +1929,6 @@ protected function tokenize($string) || $token[0] === T_FN) && $finalTokens[$lastNotEmptyToken]['code'] !== T_USE ) { - if ($token[0] === T_FUNCTION) { - for ($x = ($stackPtr + 1); $x < $numTokens; $x++) { - if (is_array($tokens[$x]) === false - || isset(Util\Tokens::$emptyTokens[$tokens[$x][0]]) === false - ) { - // Non-empty content. - break; - } - } - - if ($x < $numTokens - && is_array($tokens[$x]) === true - && $tokens[$x][0] !== T_STRING - && $tokens[$x][0] !== T_NAME_QUALIFIED - ) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $oldType = Util\Tokens::tokenName($tokens[$x][0]); - echo "\t\t* token $x changed from $oldType to T_STRING".PHP_EOL; - } - - $tokens[$x][0] = T_STRING; - } - }//end if - - /* - This is a special condition for T_ARRAY tokens used for - function return types. We want to keep the parenthesis map clean, - so let's tag these tokens as T_STRING. - */ - // Go looking for the colon to start the return type hint. // Start by finding the closing parenthesis of the function. $parenthesisStack = []; @@ -1726,22 +1968,6 @@ function return types. We want to keep the parenthesis map clean, && is_array($tokens[$x]) === false && $tokens[$x] === ':' ) { - $allowed = [ - T_STRING => T_STRING, - T_NAME_FULLY_QUALIFIED => T_NAME_FULLY_QUALIFIED, - T_NAME_RELATIVE => T_NAME_RELATIVE, - T_NAME_QUALIFIED => T_NAME_QUALIFIED, - T_ARRAY => T_ARRAY, - T_CALLABLE => T_CALLABLE, - T_SELF => T_SELF, - T_PARENT => T_PARENT, - T_NAMESPACE => T_NAMESPACE, - T_STATIC => T_STATIC, - T_NS_SEPARATOR => T_NS_SEPARATOR, - ]; - - $allowed += Util\Tokens::$emptyTokens; - // Find the start of the return type. for ($x += 1; $x < $numTokens; $x++) { if (is_array($tokens[$x]) === true @@ -1769,23 +1995,6 @@ function return types. We want to keep the parenthesis map clean, break; }//end for - - // Any T_ARRAY tokens we find between here and the next - // token that can't be part of the return type, need to be - // converted to T_STRING tokens. - for ($x; $x < $numTokens; $x++) { - if ((is_array($tokens[$x]) === false && $tokens[$x] !== '|') - || (is_array($tokens[$x]) === true && isset($allowed[$tokens[$x][0]]) === false) - ) { - break; - } else if (is_array($tokens[$x]) === true && $tokens[$x][0] === T_ARRAY) { - $tokens[$x][0] = T_STRING; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $x changed from T_ARRAY to T_STRING".PHP_EOL; - } - } - } }//end if }//end if }//end if @@ -1833,6 +2042,7 @@ function return types. We want to keep the parenthesis map clean, T_OPEN_TAG => true, T_OPEN_CURLY_BRACKET => true, T_INLINE_THEN => true, + T_ENUM => true, ]; for ($x = ($newStackPtr - 1); $x > 0; $x--) { @@ -1843,6 +2053,7 @@ function return types. We want to keep the parenthesis map clean, if ($finalTokens[$x]['code'] !== T_CASE && $finalTokens[$x]['code'] !== T_INLINE_THEN + && $finalTokens[$x]['code'] !== T_ENUM ) { $finalTokens[$newStackPtr] = [ 'content' => $token[1].':', @@ -1891,47 +2102,39 @@ function return types. We want to keep the parenthesis map clean, $newStackPtr++; } } else { - if ($tokenIsArray === true && $token[0] === T_STRING) { - // Some T_STRING tokens should remain that way - // due to their context. - $context = [ - T_OBJECT_OPERATOR => true, - T_NULLSAFE_OBJECT_OPERATOR => true, - T_FUNCTION => true, - T_CLASS => true, - T_EXTENDS => true, - T_IMPLEMENTS => true, - T_ATTRIBUTE => true, - T_NEW => true, - T_CONST => true, - T_NS_SEPARATOR => true, - T_USE => true, - T_NAMESPACE => true, - T_PAAMAYIM_NEKUDOTAYIM => true, - ]; + // Some T_STRING tokens should remain that way due to their context. + if ($tokenIsArray === true + && $token[0] === T_STRING + && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === true + ) { + // Special case for syntax like: return new self/new parent + // where self/parent should not be a string. + $tokenContentLower = strtolower($token[1]); + if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW + && ($tokenContentLower === 'self' || $tokenContentLower === 'parent') + ) { + $finalTokens[$newStackPtr] = [ + 'content' => $token[1], + ]; + if ($tokenContentLower === 'self') { + $finalTokens[$newStackPtr]['code'] = T_SELF; + $finalTokens[$newStackPtr]['type'] = 'T_SELF'; + } - if (isset($context[$finalTokens[$lastNotEmptyToken]['code']]) === true) { - // Special case for syntax like: return new self - // where self should not be a string. - if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW - && strtolower($token[1]) === 'self' - ) { - $finalTokens[$newStackPtr] = [ - 'content' => $token[1], - 'code' => T_SELF, - 'type' => 'T_SELF', - ]; - } else { - $finalTokens[$newStackPtr] = [ - 'content' => $token[1], - 'code' => T_STRING, - 'type' => 'T_STRING', - ]; + if ($tokenContentLower === 'parent') { + $finalTokens[$newStackPtr]['code'] = T_PARENT; + $finalTokens[$newStackPtr]['type'] = 'T_PARENT'; } + } else { + $finalTokens[$newStackPtr] = [ + 'content' => $token[1], + 'code' => T_STRING, + 'type' => 'T_STRING', + ]; + } - $newStackPtr++; - continue; - }//end if + $newStackPtr++; + continue; }//end if $newToken = null; @@ -2064,41 +2267,37 @@ function return types. We want to keep the parenthesis map clean, } }//end if - // This is a special condition for T_ARRAY tokens used for - // type hinting function arguments as being arrays. We want to keep - // the parenthesis map clean, so let's tag these tokens as + // This is a special condition for T_ARRAY tokens used for anything else + // but array declarations, like type hinting function arguments as + // being arrays. + // We want to keep the parenthesis map clean, so let's tag these tokens as // T_STRING. if ($newToken['code'] === T_ARRAY) { - for ($i = $stackPtr; $i < $numTokens; $i++) { - if ($tokens[$i] === '(') { - break; - } else if ($tokens[$i][0] === T_VARIABLE) { - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; + for ($i = ($stackPtr + 1); $i < $numTokens; $i++) { + if (is_array($tokens[$i]) === false + || isset(Util\Tokens::$emptyTokens[$tokens[$i][0]]) === false + ) { + // Non-empty content. break; } } + + if ($i !== $numTokens && $tokens[$i] !== '(') { + $newToken['code'] = T_STRING; + $newToken['type'] = 'T_STRING'; + } } // This is a special case when checking PHP 5.5+ code in PHP < 5.5 // where "finally" should be T_FINALLY instead of T_STRING. if ($newToken['code'] === T_STRING && strtolower($newToken['content']) === 'finally' + && $finalTokens[$lastNotEmptyToken]['code'] === T_CLOSE_CURLY_BRACKET ) { $newToken['code'] = T_FINALLY; $newToken['type'] = 'T_FINALLY'; } - // This is a special case for the PHP 5.5 classname::class syntax - // where "class" should be T_STRING instead of T_CLASS. - if (($newToken['code'] === T_CLASS - || $newToken['code'] === T_FUNCTION) - && $finalTokens[$lastNotEmptyToken]['code'] === T_DOUBLE_COLON - ) { - $newToken['code'] = T_STRING; - $newToken['type'] = 'T_STRING'; - } - // This is a special case for PHP 5.6 use function and use const // where "function" and "const" should be T_STRING instead of T_FUNCTION // and T_CONST. @@ -2276,17 +2475,19 @@ protected function processAdditional() if (isset($this->tokens[$x]) === true && $this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) { $ignore = Util\Tokens::$emptyTokens; $ignore += [ - T_STRING => T_STRING, - T_ARRAY => T_ARRAY, - T_COLON => T_COLON, - T_NAMESPACE => T_NAMESPACE, - T_NS_SEPARATOR => T_NS_SEPARATOR, - T_NULLABLE => T_NULLABLE, - T_CALLABLE => T_CALLABLE, - T_PARENT => T_PARENT, - T_SELF => T_SELF, - T_STATIC => T_STATIC, - T_TYPE_UNION => T_TYPE_UNION, + T_ARRAY => T_ARRAY, + T_CALLABLE => T_CALLABLE, + T_COLON => T_COLON, + T_NAMESPACE => T_NAMESPACE, + T_NS_SEPARATOR => T_NS_SEPARATOR, + T_NULL => T_NULL, + T_NULLABLE => T_NULLABLE, + T_PARENT => T_PARENT, + T_SELF => T_SELF, + T_STATIC => T_STATIC, + T_STRING => T_STRING, + T_TYPE_UNION => T_TYPE_UNION, + T_TYPE_INTERSECTION => T_TYPE_INTERSECTION, ]; $closer = $this->tokens[$x]['parenthesis_closer']; @@ -2340,8 +2541,10 @@ protected function processAdditional() if (isset($endTokens[$this->tokens[$scopeCloser]['code']]) === true) { if ($lastEndToken !== null - && $this->tokens[$scopeCloser]['code'] === T_CLOSE_PARENTHESIS - && $this->tokens[$scopeCloser]['parenthesis_opener'] < $arrow + && ((isset($this->tokens[$scopeCloser]['parenthesis_opener']) === true + && $this->tokens[$scopeCloser]['parenthesis_opener'] < $arrow) + || (isset($this->tokens[$scopeCloser]['bracket_opener']) === true + && $this->tokens[$scopeCloser]['bracket_opener'] < $arrow)) ) { for ($lastNonEmpty = ($scopeCloser - 1); $lastNonEmpty > $arrow; $lastNonEmpty--) { if (isset(Util\Tokens::$emptyTokens[$this->tokens[$lastNonEmpty]['code']]) === false) { @@ -2354,6 +2557,16 @@ protected function processAdditional() break; } + if ($inTernary === false + && isset($this->tokens[$scopeCloser]['scope_closer'], $this->tokens[$scopeCloser]['scope_condition']) === true + && $scopeCloser === $this->tokens[$scopeCloser]['scope_closer'] + && $this->tokens[$this->tokens[$scopeCloser]['scope_condition']]['code'] === T_FN + ) { + // Found a nested arrow function that already has the closer set and is in + // the same scope as us, so we can use its closer. + break; + } + if (isset($this->tokens[$scopeCloser]['scope_closer']) === true && $this->tokens[$scopeCloser]['code'] !== T_INLINE_ELSE && $this->tokens[$scopeCloser]['code'] !== T_END_HEREDOC @@ -2475,13 +2688,18 @@ protected function processAdditional() } if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) { - if (isset($allowed[$this->tokens[$x]['code']]) === false) { + // Allow for control structures without braces. + if (($this->tokens[$x]['code'] === T_CLOSE_PARENTHESIS + && isset($this->tokens[$x]['parenthesis_owner']) === true + && isset(Util\Tokens::$scopeOpeners[$this->tokens[$this->tokens[$x]['parenthesis_owner']]['code']]) === true) + || isset($allowed[$this->tokens[$x]['code']]) === false + ) { $isShortArray = true; } break; } - } + }//end for if ($isShortArray === true) { $this->tokens[$i]['code'] = T_OPEN_SHORT_ARRAY; @@ -2570,9 +2788,12 @@ protected function processAdditional() }//end if continue; - } else if ($this->tokens[$i]['code'] === T_BITWISE_OR) { + } else if ($this->tokens[$i]['code'] === T_BITWISE_OR + || $this->tokens[$i]['code'] === T_BITWISE_AND + ) { /* Convert "|" to T_TYPE_UNION or leave as T_BITWISE_OR. + Convert "&" to T_TYPE_INTERSECTION or leave as T_BITWISE_AND. */ $allowed = [ @@ -2583,6 +2804,7 @@ protected function processAdditional() T_STATIC => T_STATIC, T_FALSE => T_FALSE, T_NULL => T_NULL, + T_NAMESPACE => T_NAMESPACE, T_NS_SEPARATOR => T_NS_SEPARATOR, ]; @@ -2636,12 +2858,12 @@ protected function processAdditional() }//end for if ($typeTokenCount === 0 || isset($suspectedType) === false) { - // Definitely not a union type, move on. + // Definitely not a union or intersection type, move on. continue; } $typeTokenCount = 0; - $unionOperators = [$i]; + $typeOperators = [$i]; $confirmed = false; for ($x = ($i - 1); $x >= 0; $x--) { @@ -2654,13 +2876,13 @@ protected function processAdditional() continue; } - // Union types can't use the nullable operator, but be tolerant to parse errors. + // Union and intersection types can't use the nullable operator, but be tolerant to parse errors. if ($typeTokenCount > 0 && $this->tokens[$x]['code'] === T_NULLABLE) { continue; } - if ($this->tokens[$x]['code'] === T_BITWISE_OR) { - $unionOperators[] = $x; + if ($this->tokens[$x]['code'] === T_BITWISE_OR || $this->tokens[$x]['code'] === T_BITWISE_AND) { + $typeOperators[] = $x; continue; } @@ -2671,7 +2893,8 @@ protected function processAdditional() if ($suspectedType === 'property or parameter' && (isset(Util\Tokens::$scopeModifiers[$this->tokens[$x]['code']]) === true - || $this->tokens[$x]['code'] === T_VAR) + || $this->tokens[$x]['code'] === T_VAR + || $this->tokens[$x]['code'] === T_READONLY) ) { // This will also confirm constructor property promotion parameters, but that's fine. $confirmed = true; @@ -2725,17 +2948,27 @@ protected function processAdditional() }//end if if ($confirmed === false) { - // Not a union type after all, move on. + // Not a union or intersection type after all, move on. continue; } - foreach ($unionOperators as $x) { - $this->tokens[$x]['code'] = T_TYPE_UNION; - $this->tokens[$x]['type'] = 'T_TYPE_UNION'; + foreach ($typeOperators as $x) { + if ($this->tokens[$x]['code'] === T_BITWISE_OR) { + $this->tokens[$x]['code'] = T_TYPE_UNION; + $this->tokens[$x]['type'] = 'T_TYPE_UNION'; - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $this->tokens[$x]['line']; - echo "\t* token $x on line $line changed from T_BITWISE_OR to T_TYPE_UNION".PHP_EOL; + if (PHP_CODESNIFFER_VERBOSITY > 1) { + $line = $this->tokens[$x]['line']; + echo "\t* token $x on line $line changed from T_BITWISE_OR to T_TYPE_UNION".PHP_EOL; + } + } else { + $this->tokens[$x]['code'] = T_TYPE_INTERSECTION; + $this->tokens[$x]['type'] = 'T_TYPE_INTERSECTION'; + + if (PHP_CODESNIFFER_VERBOSITY > 1) { + $line = $this->tokens[$x]['line']; + echo "\t* token $x on line $line changed from T_BITWISE_AND to T_TYPE_INTERSECTION".PHP_EOL; + } } } @@ -2769,13 +3002,7 @@ protected function processAdditional() } } - $context = [ - T_OBJECT_OPERATOR => true, - T_NULLSAFE_OBJECT_OPERATOR => true, - T_NS_SEPARATOR => true, - T_PAAMAYIM_NEKUDOTAYIM => true, - ]; - if (isset($context[$this->tokens[$x]['code']]) === true) { + if (isset($this->tstringContexts[$this->tokens[$x]['code']]) === true) { if (PHP_CODESNIFFER_VERBOSITY > 1) { $line = $this->tokens[$i]['line']; $type = $this->tokens[$i]['type']; @@ -2785,25 +3012,6 @@ protected function processAdditional() $this->tokens[$i]['code'] = T_STRING; $this->tokens[$i]['type'] = 'T_STRING'; } - } else if ($this->tokens[$i]['code'] === T_CONST) { - // Context sensitive keywords support. - for ($x = ($i + 1); $i < $numTokens; $x++) { - if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) { - // Non-whitespace content. - break; - } - } - - if ($this->tokens[$x]['code'] !== T_STRING) { - if (PHP_CODESNIFFER_VERBOSITY > 1) { - $line = $this->tokens[$x]['line']; - $type = $this->tokens[$x]['type']; - echo "\t* token $x on line $line changed from $type to T_STRING".PHP_EOL; - } - - $this->tokens[$x]['code'] = T_STRING; - $this->tokens[$x]['type'] = 'T_STRING'; - } }//end if if (($this->tokens[$i]['code'] !== T_CASE @@ -3213,14 +3421,27 @@ private function parsePhpAttribute(array &$tokens, $stackPtr) // Go looking for the close bracket. $bracketCloser = $this->findCloser($subTokens, 1, '[', ']'); - if ($bracketCloser === null) { - $bracketCloser = $this->findCloser($tokens, $stackPtr, '[', ']'); - if ($bracketCloser === null) { - return null; + if (PHP_VERSION_ID < 80000 && $bracketCloser === null) { + foreach (array_slice($tokens, ($stackPtr + 1)) as $token) { + if (is_array($token) === true) { + $commentBody .= $token[1]; + } else { + $commentBody .= $token; + } } - $subTokens = array_merge($subTokens, array_slice($tokens, ($stackPtr + 1), ($bracketCloser - $stackPtr))); - array_splice($tokens, ($stackPtr + 1), ($bracketCloser - $stackPtr)); + $subTokens = @token_get_all('findCloser($subTokens, 1, '[', ']'); + if ($bracketCloser !== null) { + array_splice($tokens, ($stackPtr + 1), count($tokens), array_slice($subTokens, ($bracketCloser + 1))); + $subTokens = array_slice($subTokens, 0, ($bracketCloser + 1)); + } + } + + if ($bracketCloser === null) { + return null; } return $subTokens; diff --git a/vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php b/vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php index a229d697..0e00bf7f 100644 --- a/vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php +++ b/vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php @@ -194,6 +194,8 @@ private function createPositionMap() T_DOUBLE_QUOTED_STRING => true, T_HEREDOC => true, T_NOWDOC => true, + T_END_HEREDOC => true, + T_END_NOWDOC => true, T_INLINE_HTML => true, ]; @@ -250,7 +252,7 @@ private function createPositionMap() || $this->tokens[$i]['code'] === T_DOC_COMMENT_TAG || ($inTests === true && $this->tokens[$i]['code'] === T_INLINE_HTML) ) { - $commentText = ltrim($this->tokens[$i]['content'], " \t/*"); + $commentText = ltrim($this->tokens[$i]['content'], " \t/*#"); $commentText = rtrim($commentText, " */\t\r\n"); $commentTextLower = strtolower($commentText); if (strpos($commentText, '@codingStandards') !== false) { @@ -638,25 +640,13 @@ public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth } // Process the tab that comes after the content. - $lastCurrColumn = $currColumn; $tabNum++; // Move the pointer to the next tab stop. - if (($currColumn % $tabWidth) === 0) { - // This is the first tab, and we are already at a - // tab stop, so this tab counts as a single space. - $currColumn++; - } else { - $currColumn++; - while (($currColumn % $tabWidth) !== 0) { - $currColumn++; - } - - $currColumn++; - } - - $length += ($currColumn - $lastCurrColumn); - $newContent .= $prefix.str_repeat($padding, ($currColumn - $lastCurrColumn - 1)); + $pad = ($tabWidth - ($currColumn + $tabWidth - 1) % $tabWidth); + $currColumn += $pad; + $length += $pad; + $newContent .= $prefix.str_repeat($padding, ($pad - 1)); }//end foreach }//end if diff --git a/vendor/squizlabs/php_codesniffer/src/Util/Common.php b/vendor/squizlabs/php_codesniffer/src/Util/Common.php index e60eec1d..ce7967cc 100644 --- a/vendor/squizlabs/php_codesniffer/src/Util/Common.php +++ b/vendor/squizlabs/php_codesniffer/src/Util/Common.php @@ -60,11 +60,11 @@ public static function isPharFile($path) */ public static function isReadable($path) { - if (is_readable($path) === true) { + if (@is_readable($path) === true) { return true; } - if (file_exists($path) === true && is_file($path) === true) { + if (@file_exists($path) === true && @is_file($path) === true) { $f = @fopen($path, 'rb'); if (fclose($f) === true) { return true; @@ -250,7 +250,7 @@ public static function escapeshellcmd($cmd) { $cmd = escapeshellcmd($cmd); - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + if (stripos(PHP_OS, 'WIN') === 0) { // Spaces are not escaped by escapeshellcmd on Windows, but need to be // for the command to be able to execute. $cmd = preg_replace('`(?= 48 && $ascii <= 57) { - // The character is a number, so it cant be a capital. + // The character is a number, so it can't be a capital. $isCaps = false; } else { if (strtoupper($string[$i]) === $string[$i]) { diff --git a/vendor/squizlabs/php_codesniffer/src/Util/Standards.php b/vendor/squizlabs/php_codesniffer/src/Util/Standards.php index 50f58f02..65e5d6cb 100644 --- a/vendor/squizlabs/php_codesniffer/src/Util/Standards.php +++ b/vendor/squizlabs/php_codesniffer/src/Util/Standards.php @@ -180,7 +180,8 @@ public static function getInstalledStandards( // Check if the installed dir is actually a standard itself. $csFile = $standardsDir.'/ruleset.xml'; if (is_file($csFile) === true) { - $installedStandards[] = basename($standardsDir); + $basename = basename($standardsDir); + $installedStandards[$basename] = $basename; continue; } @@ -190,6 +191,7 @@ public static function getInstalledStandards( } $di = new \DirectoryIterator($standardsDir); + $standardsInDir = []; foreach ($di as $file) { if ($file->isDir() === true && $file->isDot() === false) { $filename = $file->getFilename(); @@ -202,10 +204,13 @@ public static function getInstalledStandards( // Valid coding standard dirs include a ruleset. $csFile = $file->getPathname().'/ruleset.xml'; if (is_file($csFile) === true) { - $installedStandards[] = $filename; + $standardsInDir[$filename] = $filename; } } } + + natsort($standardsInDir); + $installedStandards += $standardsInDir; }//end foreach return $installedStandards; diff --git a/vendor/squizlabs/php_codesniffer/src/Util/Timing.php b/vendor/squizlabs/php_codesniffer/src/Util/Timing.php index cf27dcfe..95ee8521 100644 --- a/vendor/squizlabs/php_codesniffer/src/Util/Timing.php +++ b/vendor/squizlabs/php_codesniffer/src/Util/Timing.php @@ -64,7 +64,7 @@ public static function printRunTime($force=false) if ($time > 60000) { $mins = floor($time / 60000); - $secs = round((($time % 60000) / 1000), 2); + $secs = round((fmod($time, 60000) / 1000), 2); $time = $mins.' mins'; if ($secs !== 0) { $time .= ", $secs secs"; diff --git a/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php b/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php index 56afd279..bb1fb2ca 100644 --- a/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php +++ b/vendor/squizlabs/php_codesniffer/src/Util/Tokens.php @@ -80,6 +80,8 @@ define('T_MATCH_ARROW', 'PHPCS_T_MATCH_ARROW'); define('T_MATCH_DEFAULT', 'PHPCS_T_MATCH_DEFAULT'); define('T_ATTRIBUTE_END', 'PHPCS_T_ATTRIBUTE_END'); +define('T_ENUM_CASE', 'PHPCS_T_ENUM_CASE'); +define('T_TYPE_INTERSECTION', 'PHPCS_T_TYPE_INTERSECTION'); // Some PHP 5.5 tokens, replicated for lower versions. if (defined('T_FINALLY') === false) { @@ -154,6 +156,23 @@ define('T_ATTRIBUTE', 'PHPCS_T_ATTRIBUTE'); } +// Some PHP 8.1 tokens, replicated for lower versions. +if (defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') === false) { + define('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', 'PHPCS_T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG'); +} + +if (defined('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') === false) { + define('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', 'PHPCS_T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG'); +} + +if (defined('T_READONLY') === false) { + define('T_READONLY', 'PHPCS_T_READONLY'); +} + +if (defined('T_ENUM') === false) { + define('T_ENUM', 'PHPCS_T_ENUM'); +} + // Tokens used for parsing doc blocks. define('T_DOC_COMMENT_STAR', 'PHPCS_T_DOC_COMMENT_STAR'); define('T_DOC_COMMENT_WHITESPACE', 'PHPCS_T_DOC_COMMENT_WHITESPACE'); @@ -181,6 +200,7 @@ final class Tokens T_CLASS => 1000, T_INTERFACE => 1000, T_TRAIT => 1000, + T_ENUM => 1000, T_NAMESPACE => 1000, T_FUNCTION => 100, T_CLOSURE => 100, @@ -406,6 +426,7 @@ final class Tokens T_ANON_CLASS => T_ANON_CLASS, T_INTERFACE => T_INTERFACE, T_TRAIT => T_TRAIT, + T_ENUM => T_ENUM, T_NAMESPACE => T_NAMESPACE, T_FUNCTION => T_FUNCTION, T_CLOSURE => T_CLOSURE, @@ -607,6 +628,7 @@ final class Tokens T_UNSET => T_UNSET, T_EMPTY => T_EMPTY, T_SELF => T_SELF, + T_PARENT => T_PARENT, T_STATIC => T_STATIC, ]; @@ -620,6 +642,7 @@ final class Tokens T_ANON_CLASS => T_ANON_CLASS, T_INTERFACE => T_INTERFACE, T_TRAIT => T_TRAIT, + T_ENUM => T_ENUM, ]; /** @@ -640,6 +663,86 @@ final class Tokens T_TRAIT_C => T_TRAIT_C, ]; + /** + * Tokens representing context sensitive keywords in PHP. + * + * @var array + * + * https://wiki.php.net/rfc/context_sensitive_lexer + */ + public static $contextSensitiveKeywords = [ + T_ABSTRACT => T_ABSTRACT, + T_ARRAY => T_ARRAY, + T_AS => T_AS, + T_BREAK => T_BREAK, + T_CALLABLE => T_CALLABLE, + T_CASE => T_CASE, + T_CATCH => T_CATCH, + T_CLASS => T_CLASS, + T_CLONE => T_CLONE, + T_CONST => T_CONST, + T_CONTINUE => T_CONTINUE, + T_DECLARE => T_DECLARE, + T_DEFAULT => T_DEFAULT, + T_DO => T_DO, + T_ECHO => T_ECHO, + T_ELSE => T_ELSE, + T_ELSEIF => T_ELSEIF, + T_EMPTY => T_EMPTY, + T_ENDDECLARE => T_ENDDECLARE, + T_ENDFOR => T_ENDFOR, + T_ENDFOREACH => T_ENDFOREACH, + T_ENDIF => T_ENDIF, + T_ENDSWITCH => T_ENDSWITCH, + T_ENDWHILE => T_ENDWHILE, + T_ENUM => T_ENUM, + T_EVAL => T_EVAL, + T_EXIT => T_EXIT, + T_EXTENDS => T_EXTENDS, + T_FINAL => T_FINAL, + T_FINALLY => T_FINALLY, + T_FN => T_FN, + T_FOR => T_FOR, + T_FOREACH => T_FOREACH, + T_FUNCTION => T_FUNCTION, + T_GLOBAL => T_GLOBAL, + T_GOTO => T_GOTO, + T_IF => T_IF, + T_IMPLEMENTS => T_IMPLEMENTS, + T_INCLUDE => T_INCLUDE, + T_INCLUDE_ONCE => T_INCLUDE_ONCE, + T_INSTANCEOF => T_INSTANCEOF, + T_INSTEADOF => T_INSTEADOF, + T_INTERFACE => T_INTERFACE, + T_ISSET => T_ISSET, + T_LIST => T_LIST, + T_LOGICAL_AND => T_LOGICAL_AND, + T_LOGICAL_OR => T_LOGICAL_OR, + T_LOGICAL_XOR => T_LOGICAL_XOR, + T_MATCH => T_MATCH, + T_NAMESPACE => T_NAMESPACE, + T_NEW => T_NEW, + T_PRINT => T_PRINT, + T_PRIVATE => T_PRIVATE, + T_PROTECTED => T_PROTECTED, + T_PUBLIC => T_PUBLIC, + T_READONLY => T_READONLY, + T_REQUIRE => T_REQUIRE, + T_REQUIRE_ONCE => T_REQUIRE_ONCE, + T_RETURN => T_RETURN, + T_STATIC => T_STATIC, + T_SWITCH => T_SWITCH, + T_THROW => T_THROW, + T_TRAIT => T_TRAIT, + T_TRY => T_TRY, + T_UNSET => T_UNSET, + T_USE => T_USE, + T_VAR => T_VAR, + T_WHILE => T_WHILE, + T_YIELD => T_YIELD, + T_YIELD_FROM => T_YIELD_FROM, + ]; + /** * Given a token, returns the name of the token. diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Autoloader/DetermineLoadedClassTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Autoloader/DetermineLoadedClassTest.php index 65542b67..c0f38fa6 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Autoloader/DetermineLoadedClassTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Autoloader/DetermineLoadedClassTest.php @@ -1,6 +1,6 @@ * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) @@ -9,6 +9,7 @@ namespace PHP_CodeSniffer\Tests\Core\Autoloader; +use PHP_CodeSniffer\Autoload; use PHPUnit\Framework\TestCase; class DetermineLoadedClassTest extends TestCase @@ -51,7 +52,7 @@ public function testOrdered() 'traits' => [], ]; - $className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); + $className = Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); $this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); }//end testOrdered() @@ -81,7 +82,7 @@ public function testUnordered() 'traits' => [], ]; - $className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); + $className = Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); $this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); $classesAfterLoad = [ @@ -95,7 +96,7 @@ public function testUnordered() 'traits' => [], ]; - $className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); + $className = Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); $this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); $classesAfterLoad = [ @@ -109,7 +110,7 @@ public function testUnordered() 'traits' => [], ]; - $className = \PHP_CodeSniffer\Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); + $className = Autoload::determineLoadedClass($classesBeforeLoad, $classesAfterLoad); $this->assertEquals('PHP_CodeSniffer\Tests\Core\Autoloader\Sub\C', $className); }//end testUnordered() diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/ErrorSuppressionTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/ErrorSuppressionTest.php index f031b334..7181613c 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/ErrorSuppressionTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/ErrorSuppressionTest.php @@ -21,1245 +21,1227 @@ class ErrorSuppressionTest extends TestCase /** * Test suppressing a single error. * + * @param string $before Annotation to place before the code. + * @param string $after Annotation to place after the code. + * @param int $expectedErrors Optional. Number of errors expected. + * Defaults to 0. + * + * @dataProvider dataSuppressError + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testSuppressError() + public function testSuppressError($before, $after, $expectedErrors=0) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; + static $config, $ruleset; - $ruleset = new Ruleset($config); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; - // Process without suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + $ruleset = new Ruleset($config); + } - // Process with inline comment suppression. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - // Process with multi-line inline comment suppression, tab-indented. - $content = 'process(); + }//end testSuppressError() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - // Process with inline @ comment suppression. - $content = 'process(); + /** + * Data provider. + * + * @see testSuppressError() + * + * @return array + */ + public function dataSuppressError() + { + return [ + 'no suppression' => [ + 'before' => '', + 'after' => '', + 'expectedErrors' => 1, + ], + + // Inline slash comments. + 'disable/enable: slash comment' => [ + 'before' => '// phpcs:disable'.PHP_EOL, + 'after' => '// phpcs:enable', + ], + 'disable/enable: multi-line slash comment, tab indented' => [ + 'before' => "\t".'// For reasons'.PHP_EOL."\t".'// phpcs:disable'.PHP_EOL."\t", + 'after' => "\t".'// phpcs:enable', + ], + 'disable/enable: slash comment, with @' => [ + 'before' => '// @phpcs:disable'.PHP_EOL, + 'after' => '// @phpcs:enable', + ], + 'disable/enable: slash comment, mixed case' => [ + 'before' => '// PHPCS:Disable'.PHP_EOL, + 'after' => '// pHPcs:enabLE', + ], + + // Inline hash comments. + 'disable/enable: hash comment' => [ + 'before' => '# phpcs:disable'.PHP_EOL, + 'after' => '# phpcs:enable', + ], + 'disable/enable: multi-line hash comment, tab indented' => [ + 'before' => "\t".'# For reasons'.PHP_EOL."\t".'# phpcs:disable'.PHP_EOL."\t", + 'after' => "\t".'# phpcs:enable', + ], + 'disable/enable: hash comment, with @' => [ + 'before' => '# @phpcs:disable'.PHP_EOL, + 'after' => '# @phpcs:enable', + ], + 'disable/enable: hash comment, mixed case' => [ + 'before' => '# PHPCS:Disable'.PHP_EOL, + 'after' => '# pHPcs:enabLE', + ], + + // Inline star (block) comments. + 'disable/enable: star comment' => [ + 'before' => '/* phpcs:disable */'.PHP_EOL, + 'after' => '/* phpcs:enable */', + ], + 'disable/enable: multi-line star comment' => [ + 'before' => '/*'.PHP_EOL.' phpcs:disable'.PHP_EOL.' */'.PHP_EOL, + 'after' => '/*'.PHP_EOL.' phpcs:enable'.PHP_EOL.' */', + ], + 'disable/enable: multi-line star comment, each line starred' => [ + 'before' => '/*'.PHP_EOL.' * phpcs:disable'.PHP_EOL.' */'.PHP_EOL, + 'after' => '/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */', + ], + 'disable/enable: multi-line star comment, each line starred, tab indented' => [ + 'before' => "\t".'/*'.PHP_EOL."\t".' * phpcs:disable'.PHP_EOL."\t".' */'.PHP_EOL."\t", + 'after' => "\t".'/*'.PHP_EOL.' * phpcs:enable'.PHP_EOL.' */', + ], + + // Docblock comments. + 'disable/enable: single line docblock comment' => [ + 'before' => '/** phpcs:disable */'.PHP_EOL, + 'after' => '/** phpcs:enable */', + ], + + // Deprecated syntax. + 'old style: slash comment' => [ + 'before' => '// @codingStandardsIgnoreStart'.PHP_EOL, + 'after' => '// @codingStandardsIgnoreEnd', + ], + 'old style: star comment' => [ + 'before' => '/* @codingStandardsIgnoreStart */'.PHP_EOL, + 'after' => '/* @codingStandardsIgnoreEnd */', + ], + 'old style: multi-line star comment' => [ + 'before' => '/*'.PHP_EOL.' @codingStandardsIgnoreStart'.PHP_EOL.' */'.PHP_EOL, + 'after' => '/*'.PHP_EOL.' @codingStandardsIgnoreEnd'.PHP_EOL.' */', + ], + 'old style: single line docblock comment' => [ + 'before' => '/** @codingStandardsIgnoreStart */'.PHP_EOL, + 'after' => '/** @codingStandardsIgnoreEnd */', + ], + ]; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + }//end dataSuppressError() - // Process with inline comment suppression mixed case. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + /** + * Test suppressing 1 out of 2 errors. + * + * @param string $before Annotation to place before the code. + * @param string $between Annotation to place between the code. + * @param int $expectedErrors Optional. Number of errors expected. + * Defaults to 1. + * + * @dataProvider dataSuppressSomeErrors + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * + * @return void + */ + public function testSuppressSomeErrors($before, $between, $expectedErrors=1) + { + static $config, $ruleset; - // Process with inline comment suppression (deprecated syntax). - $content = 'process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $ruleset = new Ruleset($config); + } - // Process with block comment suppression. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - // Process with multi-line block comment suppression. - $content = 'process(); + }//end testSuppressSomeErrors() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - // Process with multi-line block comment suppression, each line starred. - $content = 'process(); + /** + * Data provider. + * + * @see testSuppressSomeErrors() + * + * @return array + */ + public function dataSuppressSomeErrors() + { + return [ + 'no suppression' => [ + 'before' => '', + 'between' => '', + 'expectedErrors' => 2, + ], + + // With suppression. + 'disable/enable: slash comment' => [ + 'before' => '// phpcs:disable', + 'between' => '// phpcs:enable', + ], + 'disable/enable: slash comment, with @' => [ + 'before' => '// @phpcs:disable', + 'between' => '// @phpcs:enable', + ], + 'disable/enable: hash comment' => [ + 'before' => '# phpcs:disable', + 'between' => '# phpcs:enable', + ], + 'disable/enable: hash comment, with @' => [ + 'before' => '# @phpcs:disable', + 'between' => '# @phpcs:enable', + ], + 'disable/enable: single line docblock comment' => [ + 'before' => '/** phpcs:disable */', + 'between' => '/** phpcs:enable */', + ], + + // Deprecated syntax. + 'old style: slash comment' => [ + 'before' => '// @codingStandardsIgnoreStart', + 'between' => '// @codingStandardsIgnoreEnd', + ], + 'old style: single line docblock comment' => [ + 'before' => '/** @codingStandardsIgnoreStart */', + 'between' => '/** @codingStandardsIgnoreEnd */', + ], + ]; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + }//end dataSuppressSomeErrors() - // Process with multi-line block comment suppression, tab-indented. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + /** + * Test suppressing a single warning. + * + * @param string $before Annotation to place before the code. + * @param string $after Annotation to place after the code. + * @param int $expectedWarnings Optional. Number of warnings expected. + * Defaults to 0. + * + * @dataProvider dataSuppressWarning + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * + * @return void + */ + public function testSuppressWarning($before, $after, $expectedWarnings=0) + { + static $config, $ruleset; - // Process with block comment suppression (deprecated syntax). - $content = 'process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.Commenting.Todo']; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $ruleset = new Ruleset($config); + } - // Process with multi-line block comment suppression (deprecated syntax). - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); - // Process with a docblock suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + }//end testSuppressWarning() - // Process with a docblock suppression (deprecated syntax). - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + /** + * Data provider. + * + * @see testSuppressWarning() + * + * @return array + */ + public function dataSuppressWarning() + { + return [ + 'no suppression' => [ + 'before' => '', + 'after' => '', + 'expectedWarnings' => 1, + ], + + // With suppression. + 'disable/enable: slash comment' => [ + 'before' => '// phpcs:disable', + 'after' => '// phpcs:enable', + ], + 'disable/enable: slash comment, with @' => [ + 'before' => '// @phpcs:disable', + 'after' => '// @phpcs:enable', + ], + 'disable/enable: single line docblock comment' => [ + 'before' => '/** phpcs:disable */', + 'after' => '/** phpcs:enable */', + ], + + // Deprecated syntax. + 'old style: slash comment' => [ + 'before' => '// @codingStandardsIgnoreStart', + 'after' => '// @codingStandardsIgnoreEnd', + ], + 'old style: single line docblock comment' => [ + 'before' => '/** @codingStandardsIgnoreStart */', + 'after' => '/** @codingStandardsIgnoreEnd */', + ], + ]; - }//end testSuppressError() + }//end dataSuppressWarning() /** - * Test suppressing 1 out of 2 errors. + * Test suppressing a single error using a single line ignore. + * + * @param string $before Annotation to place before the code. + * @param string $after Optional. Annotation to place after the code. + * Defaults to an empty string. + * @param int $expectedErrors Optional. Number of errors expected. + * Defaults to 1. + * + * @dataProvider dataSuppressLine + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap * * @return void */ - public function testSuppressSomeErrors() + public function testSuppressLine($before, $after='', $expectedErrors=1) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; + static $config, $ruleset; - $ruleset = new Ruleset($config); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; - // Process without suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - - // Process with suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + $ruleset = new Ruleset($config); + } - // Process with @ suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with suppression (deprecated syntax). - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - // Process with a PHPDoc block suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + }//end testSuppressLine() - // Process with a PHPDoc block suppression (deprecated syntax). - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + /** + * Data provider. + * + * @see testSuppressLine() + * + * @return array + */ + public function dataSuppressLine() + { + return [ + 'no suppression' => [ + 'before' => '', + 'after' => '', + 'expectedErrors' => 2, + ], + + // With suppression on line before. + 'ignore: line before, slash comment' => ['before' => '// phpcs:ignore'], + 'ignore: line before, slash comment, with @' => ['before' => '// @phpcs:ignore'], + 'ignore: line before, hash comment' => ['before' => '# phpcs:ignore'], + 'ignore: line before, hash comment, with @' => ['before' => '# @phpcs:ignore'], + 'ignore: line before, star comment' => ['before' => '/* phpcs:ignore */'], + 'ignore: line before, star comment, with @' => ['before' => '/* @phpcs:ignore */'], + + // With suppression as trailing comment on code line. + 'ignore: end of line, slash comment' => [ + 'before' => '', + 'after' => ' // phpcs:ignore', + ], + 'ignore: end of line, slash comment, with @' => [ + 'before' => '', + 'after' => ' // @phpcs:ignore', + ], + 'ignore: end of line, hash comment' => [ + 'before' => '', + 'after' => ' # phpcs:ignore', + ], + 'ignore: end of line, hash comment, with @' => [ + 'before' => '', + 'after' => ' # @phpcs:ignore', + ], + + // Deprecated syntax. + 'old style: line before, slash comment' => ['before' => '// @codingStandardsIgnoreLine'], + 'old style: end of line, slash comment' => [ + 'before' => '', + 'after' => ' // @codingStandardsIgnoreLine', + ], + ]; - }//end testSuppressSomeErrors() + }//end dataSuppressLine() /** - * Test suppressing a single warning. + * Test suppressing a single error using a single line ignore in the middle of a line. + * + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap * * @return void */ - public function testSuppressWarning() + public function testSuppressLineMidLine() { $config = new Config(); $config->standards = ['Generic']; - $config->sniffs = ['Generic.Commenting.Todo']; + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; $ruleset = new Ruleset($config); - // Process without suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Process with suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with @ suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with suppression (deprecated syntax). - $content = 'process(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); + $this->assertSame(0, $file->getErrorCount()); + $this->assertCount(0, $file->getErrors()); - // Process with a docblock suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with a docblock suppression (deprecated syntax). - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - }//end testSuppressWarning() + }//end testSuppressLineMidLine() /** - * Test suppressing a single error using a single line ignore. + * Test suppressing a single error using a single line ignore within a docblock. + * + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap * * @return void */ - public function testSuppressLine() + public function testSuppressLineWithinDocblock() { $config = new Config(); $config->standards = ['Generic']; - $config->sniffs = [ - 'Generic.PHP.LowerCaseConstant', - 'Generic.Files.LineLength', - ]; + $config->sniffs = ['Generic.Files.LineLength']; $ruleset = new Ruleset($config); - // Process without suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - - // Process with suppression on line before. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with @ suppression on line before. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with suppression on line before. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with @ suppression on line before. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with suppression on line before (deprecated syntax). - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - // Process with @ suppression on line before inside docblock. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with suppression on same line. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with @ suppression on same line. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - - // Process with suppression on same line (deprecated syntax). - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); + $this->assertSame(0, $file->getErrorCount()); + $this->assertCount(0, $file->getErrors()); - }//end testSuppressLine() + }//end testSuppressLineWithinDocblock() /** * Test that using a single line ignore does not interfere with other suppressions. * + * @param string $before Annotation to place before the code. + * @param string $after Annotation to place after the code. + * + * @dataProvider dataNestedSuppressLine + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testNestedSuppressLine() + public function testNestedSuppressLine($before, $after) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = ['Generic.PHP.LowerCaseConstant']; - - $ruleset = new Ruleset($config); + static $config, $ruleset; - // Process with disable/enable suppression and no single line suppression. - $content = 'process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.PHP.LowerCaseConstant']; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $ruleset = new Ruleset($config); + } - // Process with disable/enable @ suppression and no single line suppression. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with disable/enable suppression and no single line suppression (deprecated syntax). - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with line suppression nested within disable/enable suppression. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $this->assertSame(0, $file->getErrorCount()); + $this->assertCount(0, $file->getErrors()); - // Process with line @ suppression nested within disable/enable @ suppression. - $content = 'process(); + }//end testNestedSuppressLine() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - // Process with line suppression nested within disable/enable suppression (deprecated syntax). - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + /** + * Data provider. + * + * @see testNestedSuppressLine() + * + * @return array + */ + public function dataNestedSuppressLine() + { + return [ + // Process with disable/enable suppression and no single line suppression. + 'disable/enable: slash comment, no single line suppression' => [ + 'before' => '// phpcs:disable', + 'after' => '// phpcs:enable', + ], + 'disable/enable: slash comment, with @, no single line suppression' => [ + 'before' => '// @phpcs:disable', + 'after' => '// @phpcs:enable', + ], + 'disable/enable: hash comment, no single line suppression' => [ + 'before' => '# phpcs:disable', + 'after' => '# phpcs:enable', + ], + 'old style: slash comment, no single line suppression' => [ + 'before' => '// @codingStandardsIgnoreStart', + 'after' => '// @codingStandardsIgnoreEnd', + ], + + // Process with line suppression nested within disable/enable suppression. + 'disable/enable: slash comment, next line nested single line suppression' => [ + 'before' => '// phpcs:disable'.PHP_EOL.'// phpcs:ignore', + 'after' => '// phpcs:enable', + ], + 'disable/enable: slash comment, with @, next line nested single line suppression' => [ + 'before' => '// @phpcs:disable'.PHP_EOL.'// @phpcs:ignore', + 'after' => '// @phpcs:enable', + ], + 'disable/enable: hash comment, next line nested single line suppression' => [ + 'before' => '# @phpcs:disable'.PHP_EOL.'# @phpcs:ignore', + 'after' => '# @phpcs:enable', + ], + 'old style: slash comment, next line nested single line suppression' => [ + 'before' => '// @codingStandardsIgnoreStart'.PHP_EOL.'// @codingStandardsIgnoreLine', + 'after' => '// @codingStandardsIgnoreEnd', + ], + ]; - }//end testNestedSuppressLine() + }//end dataNestedSuppressLine() /** * Test suppressing a scope opener. * + * @param string $before Annotation to place before the scope opener. + * @param string $after Annotation to place after the scope opener. + * @param int $expectedErrors Optional. Number of errors expected. + * Defaults to 0. + * + * @dataProvider dataSuppressScope + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testSuppressScope() + public function testSuppressScope($before, $after, $expectedErrors=0) { - $config = new Config(); - $config->standards = ['PEAR']; - $config->sniffs = ['PEAR.NamingConventions.ValidVariableName']; - - $ruleset = new Ruleset($config); - - // Process without suppression. - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); - $file->process(); + static $config, $ruleset; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with suppression. - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); - $file->process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['PEAR']; + $config->sniffs = ['PEAR.Functions.FunctionDeclaration']; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + $ruleset = new Ruleset($config); + } - // Process with suppression. - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); - $file->process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with suppression (deprecated syntax). - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; + $content = 'foo(); + } +} +EOD; $file = new DummyFile($content, $ruleset, $config); $file->process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with a docblock suppression. - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - - // Process with a docblock @ suppression. - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + }//end testSuppressScope() - // Process with a docblock suppression (deprecated syntax). - $content = 'foo();'.PHP_EOL.'}'.PHP_EOL.'}'; - $file = new DummyFile($content, $ruleset, $config); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); + /** + * Data provider. + * + * @see testSuppressScope() + * + * @return array + */ + public function dataSuppressScope() + { + return [ + 'no suppression' => [ + 'before' => '', + 'after' => '', + 'expectedErrors' => 1, + ], + + // Process with suppression. + 'disable/enable: slash comment' => [ + 'before' => '//phpcs:disable', + 'after' => '//phpcs:enable', + ], + 'disable/enable: slash comment, with @' => [ + 'before' => '//@phpcs:disable', + 'after' => '//@phpcs:enable', + ], + 'disable/enable: hash comment' => [ + 'before' => '#phpcs:disable', + 'after' => '#phpcs:enable', + ], + 'disable/enable: single line docblock comment' => [ + 'before' => '/** phpcs:disable */', + 'after' => '/** phpcs:enable */', + ], + 'disable/enable: single line docblock comment, with @' => [ + 'before' => '/** @phpcs:disable */', + 'after' => '/** @phpcs:enable */', + ], + + // Deprecated syntax. + 'old style: start/end, slash comment' => [ + 'before' => '//@codingStandardsIgnoreStart', + 'after' => '//@codingStandardsIgnoreEnd', + ], + 'old style: start/end, single line docblock comment' => [ + 'before' => '/** @codingStandardsIgnoreStart */', + 'after' => '/** @codingStandardsIgnoreEnd */', + ], + ]; - }//end testSuppressScope() + }//end dataSuppressScope() /** * Test suppressing a whole file. * + * @param string $before Annotation to place before the code. + * @param string $after Optional. Annotation to place after the code. + * Defaults to an empty string. + * @param int $expectedWarnings Optional. Number of warnings expected. + * Defaults to 0. + * + * @dataProvider dataSuppressFile + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testSuppressFile() + public function testSuppressFile($before, $after='', $expectedWarnings=0) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = ['Generic.Commenting.Todo']; - - $ruleset = new Ruleset($config); - - // Process without suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Process with suppression. - $content = 'process(); + static $config, $ruleset; - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = ['Generic.Commenting.Todo']; - // Process with @ suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with suppression (deprecated syntax). - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); + $ruleset = new Ruleset($config); + } - // Process mixed case. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process late comment. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process late comment (deprecated syntax). - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with a block comment suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with a multi-line block comment suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with a block comment suppression (deprecated syntax). - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with a multi-line block comment suppression (deprecated syntax). - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with docblock suppression. - $content = 'process(); - - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Process with docblock suppression (deprecated syntax). - $content = 'process(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); }//end testSuppressFile() /** - * Test disabling specific sniffs. + * Data provider. * - * @return void + * @see testSuppressFile() + * + * @return array */ - public function testDisableSelected() + public function dataSuppressFile() { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = [ - 'Generic.PHP.LowerCaseConstant', - 'Generic.Commenting.Todo', + return [ + 'no suppression' => [ + 'before' => '', + 'after' => '', + 'expectedErrors' => 1, + ], + + // Process with suppression. + 'ignoreFile: start of file, slash comment' => ['before' => '// phpcs:ignoreFile'], + 'ignoreFile: start of file, slash comment, with @' => ['before' => '// @phpcs:ignoreFile'], + 'ignoreFile: start of file, slash comment, mixed case' => ['before' => '// PHPCS:Ignorefile'], + 'ignoreFile: start of file, hash comment' => ['before' => '# phpcs:ignoreFile'], + 'ignoreFile: start of file, hash comment, with @' => ['before' => '# @phpcs:ignoreFile'], + 'ignoreFile: start of file, single-line star comment' => ['before' => '/* phpcs:ignoreFile */'], + 'ignoreFile: start of file, multi-line star comment' => [ + 'before' => '/*'.PHP_EOL.' phpcs:ignoreFile'.PHP_EOL.' */', + ], + 'ignoreFile: start of file, single-line docblock comment' => ['before' => '/** phpcs:ignoreFile */'], + + // Process late comment. + 'ignoreFile: late comment, slash comment' => [ + 'before' => '', + 'after' => '// phpcs:ignoreFile', + ], + + // Deprecated syntax. + 'old style: start of file, slash comment' => ['before' => '// @codingStandardsIgnoreFile'], + 'old style: start of file, single-line star comment' => ['before' => '/* @codingStandardsIgnoreFile */'], + 'old style: start of file, multi-line star comment' => [ + 'before' => '/*'.PHP_EOL.' @codingStandardsIgnoreFile'.PHP_EOL.' */', + ], + 'old style: start of file, single-line docblock comment' => ['before' => '/** @codingStandardsIgnoreFile */'], + + // Deprecated syntax, late comment. + 'old style: late comment, slash comment' => [ + 'before' => '', + 'after' => '// @codingStandardsIgnoreFile', + ], ]; - $ruleset = new Ruleset($config); + }//end dataSuppressFile() - // Suppress a single sniff. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress multiple sniffs. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress adding sniffs. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress a category of sniffs. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress a whole standard. - $content = 'process(); + /** + * Test disabling specific sniffs. + * + * @param string $before Annotation to place before the code. + * @param int $expectedErrors Optional. Number of errors expected. + * Defaults to 0. + * @param int $expectedWarnings Optional. Number of warnings expected. + * Defaults to 0. + * + * @dataProvider dataDisableSelected + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * + * @return void + */ + public function testDisableSelected($before, $expectedErrors=0, $expectedWarnings=0) + { + static $config, $ruleset; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress using docblocks. - $content = 'process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = [ + 'Generic.PHP.LowerCaseConstant', + 'Generic.Commenting.Todo', + ]; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - $content = 'process(); + $ruleset = new Ruleset($config); + } - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress wrong category using docblocks. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - $content = 'process(); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); }//end testDisableSelected() /** - * Test re-enabling specific sniffs that have been disabled. + * Data provider. * - * @return void + * @see testDisableSelected() + * + * @return array */ - public function testEnableSelected() + public function dataDisableSelected() { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = [ - 'Generic.PHP.LowerCaseConstant', - 'Generic.Commenting.Todo', + return [ + // Single sniff. + 'disable: single sniff' => [ + 'before' => '// phpcs:disable Generic.Commenting.Todo', + 'expectedErrors' => 1, + ], + 'disable: single sniff with reason' => [ + 'before' => '# phpcs:disable Generic.Commenting.Todo -- for reasons', + 'expectedErrors' => 1, + ], + 'disable: single sniff, docblock' => [ + 'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ ', + 'expectedErrors' => 1, + ], + 'disable: single sniff, docblock, with @' => [ + 'before' => '/**'.PHP_EOL.' * @phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ ', + 'expectedErrors' => 1, + ], + + // Multiple sniffs. + 'disable: multiple sniffs in one comment' => ['before' => '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'], + 'disable: multiple sniff in multiple comments' => [ + 'before' => '// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:disable Generic.PHP.LowerCaseConstant', + ], + + // Selectiveness variations. + 'disable: complete category' => [ + 'before' => '// phpcs:disable Generic.Commenting', + 'expectedErrors' => 1, + ], + 'disable: whole standard' => ['before' => '// phpcs:disable Generic'], + 'disable: single errorcode' => [ + 'before' => '# @phpcs:disable Generic.Commenting.Todo.TaskFound', + 'expectedErrors' => 1, + ], + 'disable: single errorcode and a category' => ['before' => '// phpcs:disable Generic.PHP.LowerCaseConstant.Found,Generic.Commenting'], + + // Wrong category/sniff/code. + 'disable: wrong error code and category' => [ + 'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.PHP.LowerCaseConstant.Upper,Generic.Comments'.PHP_EOL.' */ ', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: wrong category, docblock' => [ + 'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.Files'.PHP_EOL.' */ ', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: wrong category, docblock, with @' => [ + 'before' => '/**'.PHP_EOL.' * @phpcs:disable Generic.Files'.PHP_EOL.' */ ', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], ]; - $ruleset = new Ruleset($config); + }//end dataDisableSelected() - // Suppress a single sniff and re-enable. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress multiple sniffs and re-enable. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress multiple sniffs and re-enable one. - $content = 'process(); - - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a category of sniffs and re-enable. - $content = 'process(); + /** + * Test re-enabling specific sniffs that have been disabled. + * + * @param string $code Code pattern to check. + * @param int $expectedErrors Number of errors expected. + * @param int $expectedWarnings Number of warnings expected. + * + * @dataProvider dataEnableSelected + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * + * @return void + */ + public function testEnableSelected($code, $expectedErrors, $expectedWarnings) + { + static $config, $ruleset; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a whole standard and re-enable. - $content = 'process(); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = [ + 'Generic.PHP.LowerCaseConstant', + 'Generic.Commenting.Todo', + ]; - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a whole standard and re-enable a category. - $content = 'process(); + $ruleset = new Ruleset($config); + } - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a category and re-enable a whole standard. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a sniff and re-enable a category. - $content = 'process(); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a whole standard and re-enable a sniff. - $content = 'process(); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a whole standard and re-enable and re-disable a sniff. - $content = 'process(); + }//end testEnableSelected() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(2, $numWarnings); - $this->assertCount(2, $warnings); - - // Suppress a whole standard and re-enable 2 specific sniffs independently. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(2, $numWarnings); - $this->assertCount(2, $warnings); + /** + * Data provider. + * + * @see testEnableSelected() + * + * @return array + */ + public function dataEnableSelected() + { + return [ + 'disable/enable: a single sniff' => [ + 'code' => ' + // phpcs:disable Generic.Commenting.Todo + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable/enable: multiple sniffs' => [ + 'code' => ' + // phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant + //TODO: write some code + $var = FALSE;', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: multiple sniffs; enable: one' => [ + 'code' => ' + # phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant + $var = FALSE; + //TODO: write some code + # phpcs:enable Generic.Commenting.Todo + //TODO: write some code + $var = FALSE;', + 'expectedErrors' => 0, + 'expectedWarnings' => 1, + ], + 'disable/enable: complete category' => [ + 'code' => ' + // phpcs:disable Generic.Commenting + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable/enable: whole standard' => [ + 'code' => ' + // phpcs:disable Generic + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic + //TODO: write some code', + 'expectedErrors' => 0, + 'expectedWarnings' => 1, + ], + 'disable: whole standard; enable: category from the standard' => [ + 'code' => ' + // phpcs:disable Generic + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting + //TODO: write some code', + 'expectedErrors' => 0, + 'expectedWarnings' => 1, + ], + 'disable: a category; enable: the whole standard containing the category' => [ + 'code' => ' + # phpcs:disable Generic.Commenting + $var = FALSE; + //TODO: write some code + # phpcs:enable Generic + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: single sniff; enable: the category containing the sniff' => [ + 'code' => ' + // phpcs:disable Generic.Commenting.Todo + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: whole standard; enable: single sniff from the standard' => [ + 'code' => ' + // phpcs:disable Generic + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo + //TODO: write some code', + 'expectedErrors' => 0, + 'expectedWarnings' => 1, + ], + 'disable: whole standard; enable: single sniff from the standard; disable: that same sniff; enable: everything' => [ + 'code' => ' + // phpcs:disable Generic + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo + //TODO: write some code + // phpcs:disable Generic.Commenting.Todo + //TODO: write some code + // phpcs:enable + //TODO: write some code', + 'expectedErrors' => 0, + 'expectedWarnings' => 2, + ], + 'disable: whole standard; enable: single sniff from the standard; enable: other sniff from the standard' => [ + 'code' => ' + // phpcs:disable Generic + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo + //TODO: write some code + $var = FALSE; + // phpcs:enable Generic.PHP.LowerCaseConstant + //TODO: write some code + $var = FALSE;', + 'expectedErrors' => 1, + 'expectedWarnings' => 2, + ], + ]; - }//end testEnableSelected() + }//end dataEnableSelected() /** * Test ignoring specific sniffs. * + * @param string $before Annotation to place before the code. + * @param int $expectedErrors Number of errors expected. + * @param int $expectedWarnings Number of warnings expected. + * + * @dataProvider dataIgnoreSelected + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testIgnoreSelected() + public function testIgnoreSelected($before, $expectedErrors, $expectedWarnings) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = [ - 'Generic.PHP.LowerCaseConstant', - 'Generic.Commenting.Todo', - ]; + static $config, $ruleset; - $ruleset = new Ruleset($config); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = [ + 'Generic.PHP.LowerCaseConstant', + 'Generic.Commenting.Todo', + ]; - // No suppression. - $content = 'process(); + $ruleset = new Ruleset($config); + } - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - $this->assertEquals(2, $numWarnings); - $this->assertCount(2, $warnings); - - // Suppress a single sniff. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress multiple sniffs. - $content = 'process(); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Add to suppression. - $content = 'process(); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress a category of sniffs. - $content = 'process(); + }//end testIgnoreSelected() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a whole standard. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); + /** + * Data provider. + * + * @see testIgnoreSelected() + * + * @return array + */ + public function dataIgnoreSelected() + { + return [ + 'no suppression' => [ + 'before' => '', + 'expectedErrors' => 2, + 'expectedWarnings' => 2, + ], + + // With suppression. + 'ignore: single sniff' => [ + 'before' => '// phpcs:ignore Generic.Commenting.Todo', + 'expectedErrors' => 2, + 'expectedWarnings' => 1, + ], + 'ignore: multiple sniffs' => [ + 'before' => '// phpcs:ignore Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: single sniff; ignore: single sniff' => [ + 'before' => '// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:ignore Generic.PHP.LowerCaseConstant', + 'expectedErrors' => 1, + 'expectedWarnings' => 0, + ], + 'ignore: category of sniffs' => [ + 'before' => '# phpcs:ignore Generic.Commenting', + 'expectedErrors' => 2, + 'expectedWarnings' => 1, + ], + 'ignore: whole standard' => [ + 'before' => '// phpcs:ignore Generic', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + ]; - }//end testIgnoreSelected() + }//end dataIgnoreSelected() /** * Test ignoring specific sniffs. * + * @param string $code Code pattern to check. + * @param int $expectedErrors Number of errors expected. + * @param int $expectedWarnings Number of warnings expected. + * + * @dataProvider dataCommenting + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * * @return void */ - public function testCommenting() + public function testCommenting($code, $expectedErrors, $expectedWarnings) { - $config = new Config(); - $config->standards = ['Generic']; - $config->sniffs = [ - 'Generic.PHP.LowerCaseConstant', - 'Generic.Commenting.Todo', - ]; + static $config, $ruleset; - $ruleset = new Ruleset($config); + if (isset($config, $ruleset) === false) { + $config = new Config(); + $config->standards = ['Generic']; + $config->sniffs = [ + 'Generic.PHP.LowerCaseConstant', + 'Generic.Commenting.Todo', + ]; - // Suppress a single sniff. - $content = 'process(); + $ruleset = new Ruleset($config); + } - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a single sniff and re-enable. - $content = 'process(); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Suppress a single sniff using block comments. - $content = 'process(); + $this->assertSame($expectedErrors, $file->getErrorCount()); + $this->assertCount($expectedErrors, $file->getErrors()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(1, $numErrors); - $this->assertCount(1, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - - // Suppress a single sniff with a multi-line comment. - $content = 'process(); + $this->assertSame($expectedWarnings, $file->getWarningCount()); + $this->assertCount($expectedWarnings, $file->getWarnings()); - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(2, $numErrors); - $this->assertCount(2, $errors); - $this->assertEquals(1, $numWarnings); - $this->assertCount(1, $warnings); - - // Ignore an enable before a disable. - $content = 'process(); + }//end testCommenting() - $errors = $file->getErrors(); - $numErrors = $file->getErrorCount(); - $warnings = $file->getWarnings(); - $numWarnings = $file->getWarningCount(); - $this->assertEquals(0, $numErrors); - $this->assertCount(0, $errors); - $this->assertEquals(0, $numWarnings); - $this->assertCount(0, $warnings); - }//end testCommenting() + /** + * Data provider. + * + * @see testCommenting() + * + * @return array + */ + public function dataCommenting() + { + return [ + 'ignore: single sniff' => [ + 'code' => ' + // phpcs:ignore Generic.Commenting.Todo -- Because reasons + $var = FALSE; //TODO: write some code + $var = FALSE; //TODO: write some code', + 'expectedErrors' => 2, + 'expectedWarnings' => 1, + ], + 'disable: single sniff; enable: same sniff - test whitespace handling around reason delimiter' => [ + 'code' => ' + // phpcs:disable Generic.Commenting.Todo --Because reasons + $var = FALSE; + //TODO: write some code + // phpcs:enable Generic.Commenting.Todo -- Because reasons + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 1, + ], + 'disable: single sniff, multi-line comment' => [ + 'code' => ' + /* + Disable some checks + phpcs:disable Generic.Commenting.Todo + */ + $var = FALSE; + //TODO: write some code', + 'expectedErrors' => 1, + 'expectedWarnings' => 0, + ], + 'ignore: single sniff, multi-line slash comment' => [ + 'code' => ' + // Turn off a check for the next line of code. + // phpcs:ignore Generic.Commenting.Todo + $var = FALSE; //TODO: write some code + $var = FALSE; //TODO: write some code', + 'expectedErrors' => 2, + 'expectedWarnings' => 1, + ], + 'enable before disable, sniff not in standard' => [ + 'code' => ' + // phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons + $var = @delete( $filename ); + ', + 'expectedErrors' => 0, + 'expectedWarnings' => 0, + ], + ]; + + }//end dataCommenting() }//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindEndOfStatementTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindEndOfStatementTest.inc index 6dfd0a28..83516798 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindEndOfStatementTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindEndOfStatementTest.inc @@ -39,6 +39,8 @@ $a = [ /* testStaticArrowFunction */ static fn ($a) => $a; +return 0; + /* testArrowFunctionReturnValue */ fn(): array => [a($a, $b)]; @@ -101,5 +103,3 @@ $result = match ($key) { 2 => 'one', }, }; - -return 0; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.inc index 3885b27e..44c0f643 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.inc @@ -24,3 +24,12 @@ class testFECNClassThatExtendsAndImplements extends testFECNClass implements Int /* testClassThatImplementsAndExtends */ class testFECNClassThatImplementsAndExtends implements \InterfaceA, InterfaceB extends testFECNClass {} + +/* testBackedEnumWithoutImplements */ +enum Suit:string {} + +/* testEnumImplements */ +enum Suit implements Colorful {} + +/* testBackedEnumImplements */ +enum Suit: string implements Colorful, \Deck {} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.php index 834e0832..23950328 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindImplementedInterfaceNamesTest.php @@ -27,7 +27,7 @@ class FindImplementedInterfaceNamesTest extends AbstractMethodUnitTest */ public function testFindImplementedInterfaceNames($identifier, $expected) { - $OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE]); + $OOToken = $this->getTargetToken($identifier, [T_CLASS, T_ANON_CLASS, T_INTERFACE, T_ENUM]); $result = self::$phpcsFile->findImplementedInterfaceNames($OOToken); $this->assertSame($expected, $result); @@ -81,6 +81,21 @@ public function dataImplementedInterface() 'InterfaceB', ], ], + [ + '/* testBackedEnumWithoutImplements */', + false, + ], + [ + '/* testEnumImplements */', + ['Colorful'], + ], + [ + '/* testBackedEnumImplements */', + [ + 'Colorful', + '\Deck', + ], + ], ]; }//end dataImplementedInterface() diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.inc index a759a1aa..ce9dfad3 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.inc @@ -111,3 +111,13 @@ $result = match ($key) { }; return 0; + +/* testOpenTag */ +?> +

Test

+', foo(), ''; + +/* testOpenTagWithEcho */ +?> +

Test

+', foo(), ''; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.php index 33c0686e..ff859eca 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/FindStartOfStatementTest.php @@ -468,4 +468,36 @@ public function testNestedMatch() }//end testNestedMatch() + /** + * Test PHP open tag. + * + * @return void + */ + public function testOpenTag() + { + $start = $this->getTargetToken('/* testOpenTag */', T_OPEN_TAG); + $start += 2; + $found = self::$phpcsFile->findStartOfStatement($start); + + $this->assertSame(($start - 1), $found); + + }//end testOpenTag() + + + /** + * Test PHP short open echo tag. + * + * @return void + */ + public function testOpenTagWithEcho() + { + $start = $this->getTargetToken('/* testOpenTagWithEcho */', T_OPEN_TAG_WITH_ECHO); + $start += 3; + $found = self::$phpcsFile->findStartOfStatement($start); + + $this->assertSame(($start - 1), $found); + + }//end testOpenTagWithEcho() + + }//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.inc index ea47e9fc..f40b6021 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.inc @@ -239,6 +239,21 @@ $anon = class() { /* testPHP8DuplicateTypeInUnionWhitespaceAndComment */ // Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method. public int |string| /*comment*/ INT $duplicateTypeInUnion; + + /* testPHP81Readonly */ + public readonly int $readonly; + + /* testPHP81ReadonlyWithNullableType */ + public readonly ?array $array; + + /* testPHP81ReadonlyWithUnionType */ + public readonly string|int $readonlyWithUnionType; + + /* testPHP81ReadonlyWithUnionTypeWithNull */ + protected ReadOnly string|null $readonlyWithUnionTypeWithNull; + + /* testPHP81OnlyReadonlyWithUnionType */ + readonly string|int $onlyReadonly; }; $anon = class { @@ -256,3 +271,34 @@ $anon = class { ] private mixed $baz; }; + +enum Suit +{ + /* testEnumProperty */ + protected $anonymous; +} + +enum Direction implements ArrayAccess +{ + case Up; + case Down; + + /* testEnumMethodParamNotProperty */ + public function offsetGet($val) { ... } +} + +$anon = class() { + /* testPHP81IntersectionTypes */ + public Foo&Bar $intersectionType; + + /* testPHP81MoreIntersectionTypes */ + public Foo&Bar&Baz $moreIntersectionTypes; + + /* testPHP81IllegalIntersectionTypes */ + // Intentional fatal error - types which are not allowed for intersection type, but that's not the concern of the method. + public int&string $illegalIntersectionType; + + /* testPHP81NulltableIntersectionType */ + // Intentional fatal error - nullability is not allowed with intersection type, but that's not the concern of the method. + public ?Foo&Bar $nullableIntersectionType; +}; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.php index 0af04379..934d8e28 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMemberPropertiesTest.php @@ -51,6 +51,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -61,6 +62,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, + 'is_readonly' => false, 'type' => '?int', 'nullable_type' => true, ], @@ -71,6 +73,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -81,6 +84,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'string', 'nullable_type' => false, ], @@ -91,6 +95,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -101,6 +106,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'bool', 'nullable_type' => false, ], @@ -111,6 +117,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -121,6 +128,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'array', 'nullable_type' => false, ], @@ -131,6 +139,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -141,6 +150,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, + 'is_readonly' => false, 'type' => '?string', 'nullable_type' => true, ], @@ -151,6 +161,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -161,6 +172,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -171,6 +183,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -181,6 +194,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -191,6 +205,18 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, + 'type' => '', + 'nullable_type' => false, + ], + ], + [ + '/* testNoPrefix */', + [ + 'scope' => 'public', + 'scope_specified' => false, + 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -201,6 +227,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -211,6 +238,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -221,6 +249,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -231,6 +260,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'float', 'nullable_type' => false, ], @@ -241,6 +271,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'float', 'nullable_type' => false, ], @@ -251,6 +282,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '?string', 'nullable_type' => true, ], @@ -261,26 +293,18 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '?string', 'nullable_type' => true, ], ], - [ - '/* testNoPrefix */', - [ - 'scope' => 'public', - 'scope_specified' => false, - 'is_static' => false, - 'type' => '', - 'nullable_type' => false, - ], - ], [ '/* testGroupProtectedStatic 1 */', [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -291,6 +315,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -301,6 +326,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -311,6 +337,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -321,6 +348,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -331,6 +359,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -341,6 +370,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -351,6 +381,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -361,6 +392,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -371,6 +403,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -381,6 +414,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?array', 'nullable_type' => true, ], @@ -391,6 +425,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '\MyNamespace\MyClass', 'nullable_type' => false, ], @@ -401,6 +436,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?ClassName', 'nullable_type' => true, ], @@ -411,6 +447,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?Folder\ClassName', 'nullable_type' => true, ], @@ -421,6 +458,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '\MyNamespace\MyClass\Foo', 'nullable_type' => false, ], @@ -431,6 +469,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -445,6 +484,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -455,6 +495,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '', 'nullable_type' => false, ], @@ -465,6 +506,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, + 'is_readonly' => false, 'type' => 'miXed', 'nullable_type' => false, ], @@ -475,6 +517,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?mixed', 'nullable_type' => true, ], @@ -485,6 +528,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?namespace\Name', 'nullable_type' => true, ], @@ -495,6 +539,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'int|float', 'nullable_type' => false, ], @@ -505,6 +550,7 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'MyClassA|\Package\MyClassB', 'nullable_type' => false, ], @@ -515,6 +561,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'array|bool|int|float|NULL|object|string', 'nullable_type' => false, ], @@ -525,6 +572,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, + 'is_readonly' => false, 'type' => 'false|mixed|self|parent|iterable|Resource', 'nullable_type' => false, ], @@ -535,6 +583,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, // Missing static, but that's OK as not an allowed syntax. 'type' => 'callable||void', 'nullable_type' => false, @@ -546,6 +595,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?int|float', 'nullable_type' => true, ], @@ -556,6 +606,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'null', 'nullable_type' => false, ], @@ -566,6 +617,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'false', 'nullable_type' => false, ], @@ -576,6 +628,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'bool|FALSE', 'nullable_type' => false, ], @@ -586,6 +639,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'object|ClassName', 'nullable_type' => false, ], @@ -596,6 +650,7 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'iterable|array|Traversable', 'nullable_type' => false, ], @@ -606,16 +661,73 @@ public function dataGetMemberProperties() 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'int|string|INT', 'nullable_type' => false, ], ], + [ + '/* testPHP81Readonly */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'int', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81ReadonlyWithNullableType */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => true, + 'type' => '?array', + 'nullable_type' => true, + ], + ], + [ + '/* testPHP81ReadonlyWithUnionType */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'string|int', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81ReadonlyWithUnionTypeWithNull */', + [ + 'scope' => 'protected', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'string|null', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81OnlyReadonlyWithUnionType */', + [ + 'scope' => 'public', + 'scope_specified' => false, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'string|int', + 'nullable_type' => false, + ], + ], [ '/* testPHP8PropertySingleAttribute */', [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'string', 'nullable_type' => false, ], @@ -626,6 +738,7 @@ public function dataGetMemberProperties() 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => '?int|float', 'nullable_type' => true, ], @@ -636,10 +749,55 @@ public function dataGetMemberProperties() 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, + 'is_readonly' => false, 'type' => 'mixed', 'nullable_type' => false, ], ], + [ + '/* testEnumProperty */', + [], + ], + [ + '/* testPHP81IntersectionTypes */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'type' => 'Foo&Bar', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81MoreIntersectionTypes */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'type' => 'Foo&Bar&Baz', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81IllegalIntersectionTypes */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'type' => 'int&string', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP81NulltableIntersectionType */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'type' => '?Foo&Bar', + 'nullable_type' => true, + ], + ], ]; }//end dataGetMemberProperties() @@ -681,6 +839,7 @@ public function dataNotClassProperty() ['/* testGlobalVariable */'], ['/* testNestedMethodParam 1 */'], ['/* testNestedMethodParam 2 */'], + ['/* testEnumMethodParamNotProperty */'], ]; }//end dataNotClassProperty() diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.inc index b78301d3..dc465491 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.inc @@ -108,6 +108,11 @@ class ConstructorPropertyPromotionAndNormalParams { public function __construct(public int $promotedProp, ?int $normalArg) {} } +class ConstructorPropertyPromotionWithReadOnly { + /* testPHP81ConstructorPropertyPromotionWithReadOnly */ + public function __construct(public readonly ?int $promotedProp, readonly private string|bool &$promotedToo) {} +} + /* testPHP8ConstructorPropertyPromotionGlobalFunction */ // Intentional fatal error. Property promotion not allowed in non-constructor, but that's not the concern of this method. function globalFunction(private $x) {} @@ -120,3 +125,40 @@ abstract class ConstructorPropertyPromotionAbstractMethod { // 3. The callable type is not supported for properties, but that's not the concern of this method. abstract public function __construct(public callable $y, private ...$x); } + +/* testCommentsInParameter */ +function commentsInParams( + // Leading comment. + ?MyClass /*-*/ & /*-*/.../*-*/ $param /*-*/ = /*-*/ 'default value' . /*-*/ 'second part' // Trailing comment. +) {} + +/* testParameterAttributesInFunctionDeclaration */ +class ParametersWithAttributes( + public function __construct( + #[\MyExample\MyAttribute] private string $constructorPropPromTypedParamSingleAttribute, + #[MyAttr([1, 2])] + Type|false + $typedParamSingleAttribute, + #[MyAttribute(1234), MyAttribute(5678)] ?int $nullableTypedParamMultiAttribute, + #[WithoutArgument] #[SingleArgument(0)] $nonTypedParamTwoAttributes, + #[MyAttribute(array("key" => "value"))] + &...$otherParam, + ) {} +} + +/* testPHP8IntersectionTypes */ +function intersectionTypes(Foo&Bar $obj1, Boo&Bar $obj2) {} + +/* testPHP81IntersectionTypesWithSpreadOperatorAndReference */ +function globalFunctionWithSpreadAndReference(Boo&Bar &$paramA, Foo&Bar ...$paramB) {} + +/* testPHP81MoreIntersectionTypes */ +function moreIntersectionTypes(MyClassA&\Package\MyClassB&\Package\MyClassC $var) {} + +/* testPHP81IllegalIntersectionTypes */ +// Intentional fatal error - simple types are not allowed with intersection types, but that's not the concern of the method. +$closure = function (string&int $numeric_string) {}; + +/* testPHP81NullableIntersectionTypes */ +// Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. +$closure = function (?Foo&Bar $object) {}; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.php index 253b8062..ba4d7544 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodParametersTest.php @@ -26,6 +26,7 @@ public function testPassByReference() $expected[0] = [ 'name' => '$var', 'content' => '&$var', + 'has_attributes' => false, 'pass_by_reference' => true, 'variable_length' => false, 'type_hint' => '', @@ -48,6 +49,7 @@ public function testArrayHint() $expected[0] = [ 'name' => '$var', 'content' => 'array $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'array', @@ -60,164 +62,173 @@ public function testArrayHint() /** - * Verify type hint parsing. + * Verify variable. * * @return void */ - public function testTypeHint() + public function testVariable() { $expected = []; $expected[0] = [ - 'name' => '$var1', - 'content' => 'foo $var1', - 'pass_by_reference' => false, - 'variable_length' => false, - 'type_hint' => 'foo', - 'nullable_type' => false, - ]; - - $expected[1] = [ - 'name' => '$var2', - 'content' => 'bar $var2', + 'name' => '$var', + 'content' => '$var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => 'bar', + 'type_hint' => '', 'nullable_type' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testTypeHint() + }//end testVariable() /** - * Verify self type hint parsing. + * Verify default value parsing with a single function param. * * @return void */ - public function testSelfTypeHint() + public function testSingleDefaultValue() { $expected = []; $expected[0] = [ - 'name' => '$var', - 'content' => 'self $var', + 'name' => '$var1', + 'content' => '$var1=self::CONSTANT', + 'has_attributes' => false, + 'default' => 'self::CONSTANT', 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => 'self', + 'type_hint' => '', 'nullable_type' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testSelfTypeHint() + }//end testSingleDefaultValue() /** - * Verify nullable type hint parsing. + * Verify default value parsing. * * @return void */ - public function testNullableTypeHint() + public function testDefaultValues() { $expected = []; $expected[0] = [ 'name' => '$var1', - 'content' => '?int $var1', + 'content' => '$var1=1', + 'has_attributes' => false, + 'default' => '1', 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '?int', - 'nullable_type' => true, + 'type_hint' => '', + 'nullable_type' => false, ]; - $expected[1] = [ 'name' => '$var2', - 'content' => '?\bar $var2', + 'content' => "\$var2='value'", + 'has_attributes' => false, + 'default' => "'value'", 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '?\bar', - 'nullable_type' => true, + 'type_hint' => '', + 'nullable_type' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testNullableTypeHint() + }//end testDefaultValues() /** - * Verify variable. + * Verify type hint parsing. * * @return void */ - public function testVariable() + public function testTypeHint() { $expected = []; $expected[0] = [ - 'name' => '$var', - 'content' => '$var', + 'name' => '$var1', + 'content' => 'foo $var1', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '', + 'type_hint' => 'foo', + 'nullable_type' => false, + ]; + + $expected[1] = [ + 'name' => '$var2', + 'content' => 'bar $var2', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'bar', 'nullable_type' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testVariable() + }//end testTypeHint() /** - * Verify default value parsing with a single function param. + * Verify self type hint parsing. * * @return void */ - public function testSingleDefaultValue() + public function testSelfTypeHint() { $expected = []; $expected[0] = [ - 'name' => '$var1', - 'content' => '$var1=self::CONSTANT', - 'default' => 'self::CONSTANT', + 'name' => '$var', + 'content' => 'self $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '', + 'type_hint' => 'self', 'nullable_type' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testSingleDefaultValue() + }//end testSelfTypeHint() /** - * Verify default value parsing. + * Verify nullable type hint parsing. * * @return void */ - public function testDefaultValues() + public function testNullableTypeHint() { $expected = []; $expected[0] = [ 'name' => '$var1', - 'content' => '$var1=1', - 'default' => '1', + 'content' => '?int $var1', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '', - 'nullable_type' => false, + 'type_hint' => '?int', + 'nullable_type' => true, ]; + $expected[1] = [ 'name' => '$var2', - 'content' => "\$var2='value'", - 'default' => "'value'", + 'content' => '?\bar $var2', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, - 'type_hint' => '', - 'nullable_type' => false, + 'type_hint' => '?\bar', + 'nullable_type' => true, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); - }//end testDefaultValues() + }//end testNullableTypeHint() /** @@ -232,6 +243,7 @@ public function testBitwiseAndConstantExpressionDefaultValue() 'name' => '$a', 'content' => '$a = 10 & 20', 'default' => '10 & 20', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '', @@ -254,6 +266,7 @@ public function testArrowFunction() $expected[0] = [ 'name' => '$a', 'content' => 'int $a', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'int', @@ -263,6 +276,7 @@ public function testArrowFunction() $expected[1] = [ 'name' => '$b', 'content' => '...$b', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => true, 'type_hint' => '', @@ -285,6 +299,7 @@ public function testPHP8MixedTypeHint() $expected[0] = [ 'name' => '$var1', 'content' => 'mixed &...$var1', + 'has_attributes' => false, 'pass_by_reference' => true, 'variable_length' => true, 'type_hint' => 'mixed', @@ -307,6 +322,7 @@ public function testPHP8MixedTypeHintNullable() $expected[0] = [ 'name' => '$var1', 'content' => '?Mixed $var1', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '?Mixed', @@ -329,6 +345,7 @@ public function testNamespaceOperatorTypeHint() $expected[0] = [ 'name' => '$var1', 'content' => '?namespace\Name $var1', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '?namespace\Name', @@ -351,6 +368,7 @@ public function testPHP8UnionTypesSimple() $expected[0] = [ 'name' => '$number', 'content' => 'int|float $number', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'int|float', @@ -359,6 +377,7 @@ public function testPHP8UnionTypesSimple() $expected[1] = [ 'name' => '$obj', 'content' => 'self|parent &...$obj', + 'has_attributes' => false, 'pass_by_reference' => true, 'variable_length' => true, 'type_hint' => 'self|parent', @@ -381,6 +400,7 @@ public function testPHP8UnionTypesWithSpreadOperatorAndReference() $expected[0] = [ 'name' => '$paramA', 'content' => 'float|null &$paramA', + 'has_attributes' => false, 'pass_by_reference' => true, 'variable_length' => false, 'type_hint' => 'float|null', @@ -389,6 +409,7 @@ public function testPHP8UnionTypesWithSpreadOperatorAndReference() $expected[1] = [ 'name' => '$paramB', 'content' => 'string|int ...$paramB', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => true, 'type_hint' => 'string|int', @@ -412,6 +433,7 @@ public function testPHP8UnionTypesSimpleWithBitwiseOrInDefault() 'name' => '$var', 'content' => 'int|float $var = CONSTANT_A | CONSTANT_B', 'default' => 'CONSTANT_A | CONSTANT_B', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'int|float', @@ -434,6 +456,7 @@ public function testPHP8UnionTypesTwoClasses() $expected[0] = [ 'name' => '$var', 'content' => 'MyClassA|\Package\MyClassB $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'MyClassA|\Package\MyClassB', @@ -456,6 +479,7 @@ public function testPHP8UnionTypesAllBaseTypes() $expected[0] = [ 'name' => '$var', 'content' => 'array|bool|callable|int|float|null|object|string $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'array|bool|callable|int|float|null|object|string', @@ -478,6 +502,7 @@ public function testPHP8UnionTypesAllPseudoTypes() $expected[0] = [ 'name' => '$var', 'content' => 'false|mixed|self|parent|iterable|Resource $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'false|mixed|self|parent|iterable|Resource', @@ -500,6 +525,7 @@ public function testPHP8UnionTypesNullable() $expected[0] = [ 'name' => '$number', 'content' => '?int|float $number', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '?int|float', @@ -523,6 +549,7 @@ public function testPHP8PseudoTypeNull() 'name' => '$var', 'content' => 'null $var = null', 'default' => 'null', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'null', @@ -546,6 +573,7 @@ public function testPHP8PseudoTypeFalse() 'name' => '$var', 'content' => 'false $var = false', 'default' => 'false', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'false', @@ -569,6 +597,7 @@ public function testPHP8PseudoTypeFalseAndBool() 'name' => '$var', 'content' => 'bool|false $var = false', 'default' => 'false', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'bool|false', @@ -591,6 +620,7 @@ public function testPHP8ObjectAndClass() $expected[0] = [ 'name' => '$var', 'content' => 'object|ClassName $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'object|ClassName', @@ -613,6 +643,7 @@ public function testPHP8PseudoTypeIterableAndArray() $expected[0] = [ 'name' => '$var', 'content' => 'iterable|array|Traversable $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'iterable|array|Traversable', @@ -635,6 +666,7 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() $expected[0] = [ 'name' => '$var', 'content' => 'int | string /*comment*/ | INT $var', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'int|string|INT', @@ -658,31 +690,37 @@ public function testPHP8ConstructorPropertyPromotionNoTypes() 'name' => '$x', 'content' => 'public $x = 0.0', 'default' => '0.0', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '', 'nullable_type' => false, 'property_visibility' => 'public', + 'property_readonly' => false, ]; $expected[1] = [ 'name' => '$y', 'content' => 'protected $y = \'\'', 'default' => "''", + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '', 'nullable_type' => false, 'property_visibility' => 'protected', + 'property_readonly' => false, ]; $expected[2] = [ 'name' => '$z', 'content' => 'private $z = null', 'default' => 'null', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '', 'nullable_type' => false, 'property_visibility' => 'private', + 'property_readonly' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); @@ -701,30 +739,36 @@ public function testPHP8ConstructorPropertyPromotionWithTypes() $expected[0] = [ 'name' => '$x', 'content' => 'protected float|int $x', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'float|int', 'nullable_type' => false, 'property_visibility' => 'protected', + 'property_readonly' => false, ]; $expected[1] = [ 'name' => '$y', 'content' => 'public ?string &$y = \'test\'', 'default' => "'test'", + 'has_attributes' => false, 'pass_by_reference' => true, 'variable_length' => false, 'type_hint' => '?string', 'nullable_type' => true, 'property_visibility' => 'public', + 'property_readonly' => false, ]; $expected[2] = [ 'name' => '$z', 'content' => 'private mixed $z', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'mixed', 'nullable_type' => false, 'property_visibility' => 'private', + 'property_readonly' => false, ]; $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); @@ -743,15 +787,18 @@ public function testPHP8ConstructorPropertyPromotionAndNormalParam() $expected[0] = [ 'name' => '$promotedProp', 'content' => 'public int $promotedProp', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'int', 'nullable_type' => false, 'property_visibility' => 'public', + 'property_readonly' => false, ]; $expected[1] = [ 'name' => '$normalArg', 'content' => '?int $normalArg', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '?int', @@ -763,6 +810,42 @@ public function testPHP8ConstructorPropertyPromotionAndNormalParam() }//end testPHP8ConstructorPropertyPromotionAndNormalParam() + /** + * Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword. + * + * @return void + */ + public function testPHP81ConstructorPropertyPromotionWithReadOnly() + { + $expected = []; + $expected[0] = [ + 'name' => '$promotedProp', + 'content' => 'public readonly ?int $promotedProp', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => '?int', + 'nullable_type' => true, + 'property_visibility' => 'public', + 'property_readonly' => true, + ]; + $expected[1] = [ + 'name' => '$promotedToo', + 'content' => 'readonly private string|bool &$promotedToo', + 'has_attributes' => false, + 'pass_by_reference' => true, + 'variable_length' => false, + 'type_hint' => 'string|bool', + 'nullable_type' => false, + 'property_visibility' => 'private', + 'property_readonly' => true, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81ConstructorPropertyPromotionWithReadOnly() + + /** * Verify behaviour when a non-constructor function uses PHP 8 property promotion syntax. * @@ -774,6 +857,7 @@ public function testPHP8ConstructorPropertyPromotionGlobalFunction() $expected[0] = [ 'name' => '$x', 'content' => 'private $x', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => '', @@ -797,6 +881,7 @@ public function testPHP8ConstructorPropertyPromotionAbstractMethod() $expected[0] = [ 'name' => '$y', 'content' => 'public callable $y', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => false, 'type_hint' => 'callable', @@ -806,6 +891,7 @@ public function testPHP8ConstructorPropertyPromotionAbstractMethod() $expected[1] = [ 'name' => '$x', 'content' => 'private ...$x', + 'has_attributes' => false, 'pass_by_reference' => false, 'variable_length' => true, 'type_hint' => '', @@ -818,6 +904,226 @@ public function testPHP8ConstructorPropertyPromotionAbstractMethod() }//end testPHP8ConstructorPropertyPromotionAbstractMethod() + /** + * Verify and document behaviour when there are comments within a parameter declaration. + * + * @return void + */ + public function testCommentsInParameter() + { + $expected = []; + $expected[0] = [ + 'name' => '$param', + 'content' => '// Leading comment. + ?MyClass /*-*/ & /*-*/.../*-*/ $param /*-*/ = /*-*/ \'default value\' . /*-*/ \'second part\' // Trailing comment.', + 'has_attributes' => false, + 'pass_by_reference' => true, + 'variable_length' => true, + 'type_hint' => '?MyClass', + 'nullable_type' => true, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testCommentsInParameter() + + + /** + * Verify behaviour when parameters have attributes attached. + * + * @return void + */ + public function testParameterAttributesInFunctionDeclaration() + { + $expected = []; + $expected[0] = [ + 'name' => '$constructorPropPromTypedParamSingleAttribute', + 'content' => '#[\MyExample\MyAttribute] private string $constructorPropPromTypedParamSingleAttribute', + 'has_attributes' => true, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'string', + 'nullable_type' => false, + 'property_visibility' => 'private', + ]; + $expected[1] = [ + 'name' => '$typedParamSingleAttribute', + 'content' => '#[MyAttr([1, 2])] + Type|false + $typedParamSingleAttribute', + 'has_attributes' => true, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'Type|false', + 'nullable_type' => false, + ]; + $expected[2] = [ + 'name' => '$nullableTypedParamMultiAttribute', + 'content' => '#[MyAttribute(1234), MyAttribute(5678)] ?int $nullableTypedParamMultiAttribute', + 'has_attributes' => true, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => '?int', + 'nullable_type' => true, + ]; + $expected[3] = [ + 'name' => '$nonTypedParamTwoAttributes', + 'content' => '#[WithoutArgument] #[SingleArgument(0)] $nonTypedParamTwoAttributes', + 'has_attributes' => true, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => '', + 'nullable_type' => false, + ]; + $expected[4] = [ + 'name' => '$otherParam', + 'content' => '#[MyAttribute(array("key" => "value"))] + &...$otherParam', + 'has_attributes' => true, + 'pass_by_reference' => true, + 'variable_length' => true, + 'type_hint' => '', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testParameterAttributesInFunctionDeclaration() + + + /** + * Verify recognition of PHP8.1 intersection type declaration. + * + * @return void + */ + public function testPHP8IntersectionTypes() + { + $expected = []; + $expected[0] = [ + 'name' => '$obj1', + 'content' => 'Foo&Bar $obj1', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'Foo&Bar', + 'nullable_type' => false, + ]; + $expected[1] = [ + 'name' => '$obj2', + 'content' => 'Boo&Bar $obj2', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'Boo&Bar', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP8IntersectionTypes() + + + /** + * Verify recognition of PHP8 intersection type declaration when the variable has either a spread operator or a reference. + * + * @return void + */ + public function testPHP81IntersectionTypesWithSpreadOperatorAndReference() + { + $expected = []; + $expected[0] = [ + 'name' => '$paramA', + 'content' => 'Boo&Bar &$paramA', + 'has_attributes' => false, + 'pass_by_reference' => true, + 'variable_length' => false, + 'type_hint' => 'Boo&Bar', + 'nullable_type' => false, + ]; + $expected[1] = [ + 'name' => '$paramB', + 'content' => 'Foo&Bar ...$paramB', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => true, + 'type_hint' => 'Foo&Bar', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81IntersectionTypesWithSpreadOperatorAndReference() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with more types. + * + * @return void + */ + public function testPHP81MoreIntersectionTypes() + { + $expected = []; + $expected[0] = [ + 'name' => '$var', + 'content' => 'MyClassA&\Package\MyClassB&\Package\MyClassC $var', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'MyClassA&\Package\MyClassB&\Package\MyClassC', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81MoreIntersectionTypes() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with illegal simple types. + * + * @return void + */ + public function testPHP81IllegalIntersectionTypes() + { + $expected = []; + $expected[0] = [ + 'name' => '$numeric_string', + 'content' => 'string&int $numeric_string', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'string&int', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81IllegalIntersectionTypes() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * + * @return void + */ + public function testPHP81NullableIntersectionTypes() + { + $expected = []; + $expected[0] = [ + 'name' => '$object', + 'content' => '?Foo&Bar $object', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => '?Foo&Bar', + 'nullable_type' => true, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81NullableIntersectionTypes() + + /** * Test helper. * diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.inc index 3e9682df..0c592369 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.inc @@ -33,7 +33,7 @@ class MyClass { /* testMessyNullableReturnMethod */ public function myFunction() /* comment - */ : + */ : /* comment */ ? //comment array {} @@ -126,3 +126,27 @@ interface FooBar { /* testPHP8DuplicateTypeInUnionWhitespaceAndComment */ // Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method. function duplicateTypeInUnion(): int | /*comment*/ string | INT {} + +/* testPHP81NeverType */ +function never(): never {} + +/* testPHP81NullableNeverType */ +// Intentional fatal error - nullability is not allowed with never, but that's not the concern of the method. +function nullableNever(): ?never {} + +/* testPHP8IntersectionTypes */ +function intersectionTypes(): Foo&Bar {} + +/* testPHP81MoreIntersectionTypes */ +function moreIntersectionTypes(): MyClassA&\Package\MyClassB&\Package\MyClassC {} + +/* testPHP81IntersectionArrowFunction */ +$fn = fn($var): MyClassA&\Package\MyClassB => $var; + +/* testPHP81IllegalIntersectionTypes */ +// Intentional fatal error - simple types are not allowed with intersection types, but that's not the concern of the method. +$closure = function (): string&int {}; + +/* testPHP81NullableIntersectionTypes */ +// Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. +$closure = function (): ?Foo&Bar {}; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.php index d912d6b1..66f4eea3 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/GetMethodPropertiesTest.php @@ -728,6 +728,167 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment() }//end testPHP8DuplicateTypeInUnionWhitespaceAndComment() + /** + * Verify recognition of PHP8.1 type "never". + * + * @return void + */ + public function testPHP81NeverType() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'never', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81NeverType() + + + /** + * Verify recognition of PHP8.1 type "never" with (illegal) nullability. + * + * @return void + */ + public function testPHP81NullableNeverType() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => '?never', + 'nullable_return_type' => true, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81NullableNeverType() + + + /** + * Verify recognition of PHP8.1 intersection type declaration. + * + * @return void + */ + public function testPHP8IntersectionTypes() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'Foo&Bar', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP8IntersectionTypes() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with more types. + * + * @return void + */ + public function testPHP81MoreIntersectionTypes() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'MyClassA&\Package\MyClassB&\Package\MyClassC', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81MoreIntersectionTypes() + + + /** + * Verify recognition of PHP8.1 intersection type declaration in arrow function. + * + * @return void + */ + public function testPHP81IntersectionArrowFunction() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'MyClassA&\Package\MyClassB', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81IntersectionArrowFunction() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with illegal simple types. + * + * @return void + */ + public function testPHP81IllegalIntersectionTypes() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'string&int', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81IllegalIntersectionTypes() + + + /** + * Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability. + * + * @return void + */ + public function testPHP81NullableIntersectionTypes() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => '?Foo&Bar', + 'nullable_return_type' => true, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP81NullableIntersectionTypes() + + /** * Test helper. * diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/File/IsReferenceTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/File/IsReferenceTest.inc index cd40ed3b..f71e2639 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/File/IsReferenceTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/File/IsReferenceTest.inc @@ -12,7 +12,7 @@ $a = [ $something & $somethingElse ]; $a = [ $first, $something & self::$somethingElse ]; /* testBitwiseAndD */ -$a = array $first, $something & $somethingElse ); +$a = array( $first, $something & $somethingElse ); /* testBitwiseAndE */ $a = [ 'a' => $first, 'b' => $something & $somethingElse ]; @@ -51,7 +51,7 @@ function myFunction(array &$one) {} $closure = function (\MyClass &$one) {}; /* testFunctionPassByReferenceG */ -$closure = function myFunc($param, &...$moreParams) {}; +$closure = function ($param, &...$moreParams) {}; /* testForeachValueByReference */ foreach( $array as $key => &$value ) {} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.inc new file mode 100644 index 00000000..ce5c553c --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.inc @@ -0,0 +1,35 @@ + 10); + +/* testArrayWithComment */ +$var = Array /*comment*/ (1 => 10); + +/* testNestingArray */ +$var = array( + /* testNestedArray */ + array( + 'key' => 'value', + + /* testClosureReturnType */ + 'closure' => function($a) use($global) : Array {}, + ), +); + +/* testFunctionDeclarationParamType */ +function foo(array $a) {} + +/* testFunctionDeclarationReturnType */ +function foo($a) : int|array|null {} + +class Bar { + /* testClassConst */ + const ARRAY = []; + + /* testClassMethod */ + public function array() {} +} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.php new file mode 100644 index 00000000..237258a6 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ArrayKeywordTest.php @@ -0,0 +1,170 @@ + + * @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class ArrayKeywordTest extends AbstractMethodUnitTest +{ + + + /** + * Test that the array keyword is correctly tokenized as `T_ARRAY`. + * + * @param string $testMarker The comment prefacing the target token. + * @param string $testContent Optional. The token content to look for. + * + * @dataProvider dataArrayKeyword + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createTokenMap + * + * @return void + */ + public function testArrayKeyword($testMarker, $testContent='array') + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent); + $tokenArray = $tokens[$token]; + + $this->assertSame(T_ARRAY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_ARRAY (code)'); + $this->assertSame('T_ARRAY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_ARRAY (type)'); + + $this->assertArrayHasKey('parenthesis_owner', $tokenArray, 'Parenthesis owner is not set'); + $this->assertArrayHasKey('parenthesis_opener', $tokenArray, 'Parenthesis opener is not set'); + $this->assertArrayHasKey('parenthesis_closer', $tokenArray, 'Parenthesis closer is not set'); + + }//end testArrayKeyword() + + + /** + * Data provider. + * + * @see testArrayKeyword() + * + * @return array + */ + public function dataArrayKeyword() + { + return [ + 'empty array' => ['/* testEmptyArray */'], + 'array with space before parenthesis' => ['/* testArrayWithSpace */'], + 'array with comment before parenthesis' => [ + '/* testArrayWithComment */', + 'Array', + ], + 'nested: outer array' => ['/* testNestingArray */'], + 'nested: inner array' => ['/* testNestedArray */'], + ]; + + }//end dataArrayKeyword() + + + /** + * Test that the array keyword when used in a type declaration is correctly tokenized as `T_STRING`. + * + * @param string $testMarker The comment prefacing the target token. + * @param string $testContent Optional. The token content to look for. + * + * @dataProvider dataArrayType + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createTokenMap + * + * @return void + */ + public function testArrayType($testMarker, $testContent='array') + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent); + $tokenArray = $tokens[$token]; + + $this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)'); + $this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)'); + + $this->assertArrayNotHasKey('parenthesis_owner', $tokenArray, 'Parenthesis owner is set'); + $this->assertArrayNotHasKey('parenthesis_opener', $tokenArray, 'Parenthesis opener is set'); + $this->assertArrayNotHasKey('parenthesis_closer', $tokenArray, 'Parenthesis closer is set'); + + }//end testArrayType() + + + /** + * Data provider. + * + * @see testArrayType() + * + * @return array + */ + public function dataArrayType() + { + return [ + 'closure return type' => [ + '/* testClosureReturnType */', + 'Array', + ], + 'function param type' => ['/* testFunctionDeclarationParamType */'], + 'function union return type' => ['/* testFunctionDeclarationReturnType */'], + ]; + + }//end dataArrayType() + + + /** + * Verify that the retokenization of `T_ARRAY` tokens to `T_STRING` is handled correctly + * for tokens with the contents 'array' which aren't in actual fact the array keyword. + * + * @param string $testMarker The comment prefacing the target token. + * @param string $testContent The token content to look for. + * + * @dataProvider dataNotArrayKeyword + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createTokenMap + * + * @return void + */ + public function testNotArrayKeyword($testMarker, $testContent='array') + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent); + $tokenArray = $tokens[$token]; + + $this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)'); + $this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)'); + + $this->assertArrayNotHasKey('parenthesis_owner', $tokenArray, 'Parenthesis owner is set'); + $this->assertArrayNotHasKey('parenthesis_opener', $tokenArray, 'Parenthesis opener is set'); + $this->assertArrayNotHasKey('parenthesis_closer', $tokenArray, 'Parenthesis closer is set'); + + }//end testNotArrayKeyword() + + + /** + * Data provider. + * + * @see testNotArrayKeyword() + * + * @return array + */ + public function dataNotArrayKeyword() + { + return [ + 'class-constant-name' => [ + '/* testClassConst */', + 'ARRAY', + ], + 'class-method-name' => ['/* testClassMethod */'], + ]; + + }//end dataNotArrayKeyword() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.inc index 9b7b869d..e539adf8 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.inc @@ -75,7 +75,16 @@ function multiline_attributes_on_parameter_test(#[ ) ] int $param) {} +/* testAttributeContainingTextLookingLikeCloseTag */ +#[DeprecationReason('reason: ')] +function attribute_containing_text_looking_like_close_tag() {} + +/* testAttributeContainingMultilineTextLookingLikeCloseTag */ +#[DeprecationReason( + 'reason: ' +)] +function attribute_containing_mulitline_text_looking_like_close_tag() {} + /* testInvalidAttribute */ #[ThisIsNotAnAttribute function invalid_attribute_test() {} - diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.php index 46d83654..8ac826f2 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/AttributesTest.php @@ -10,7 +10,6 @@ namespace PHP_CodeSniffer\Tests\Core\Tokenizer; use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; -use PHP_CodeSniffer\Util\Tokens; class AttributesTest extends AbstractMethodUnitTest { @@ -289,7 +288,7 @@ public function testAttributeAndLineComment() /** - * Test that attribute followed by a line comment is parsed correctly. + * Test that attributes on function declaration parameters are parsed correctly. * * @param string $testMarker The comment which prefaces the target token in the test file. * @param int $position The token position (starting from T_FUNCTION) of T_ATTRIBUTE token. @@ -395,6 +394,157 @@ public function dataAttributeOnParameters() }//end dataAttributeOnParameters() + /** + * Test that an attribute containing text which looks like a PHP close tag is tokenized correctly. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param int $length The number of tokens between opener and closer. + * @param array $expectedTokensAttribute The codes of tokens inside the attributes. + * @param array $expectedTokensAfter The codes of tokens after the attributes. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::parsePhpAttribute + * + * @dataProvider dataAttributeOnTextLookingLikeCloseTag + * + * @return void + */ + public function testAttributeContainingTextLookingLikeCloseTag($testMarker, $length, array $expectedTokensAttribute, array $expectedTokensAfter) + { + $tokens = self::$phpcsFile->getTokens(); + + $attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE); + + $this->assertSame('T_ATTRIBUTE', $tokens[$attribute]['type']); + $this->assertArrayHasKey('attribute_closer', $tokens[$attribute]); + + $closer = $tokens[$attribute]['attribute_closer']; + $this->assertSame(($attribute + $length), $closer); + $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]['code']); + $this->assertSame('T_ATTRIBUTE_END', $tokens[$closer]['type']); + + $this->assertSame($tokens[$attribute]['attribute_opener'], $tokens[$closer]['attribute_opener']); + $this->assertSame($tokens[$attribute]['attribute_closer'], $tokens[$closer]['attribute_closer']); + + $i = ($attribute + 1); + foreach ($expectedTokensAttribute as $item) { + list($expectedType, $expectedContents) = $item; + $this->assertSame($expectedType, $tokens[$i]['type']); + $this->assertSame($expectedContents, $tokens[$i]['content']); + $this->assertArrayHasKey('attribute_opener', $tokens[$i]); + $this->assertArrayHasKey('attribute_closer', $tokens[$i]); + ++$i; + } + + $i = ($closer + 1); + foreach ($expectedTokensAfter as $expectedCode) { + $this->assertSame($expectedCode, $tokens[$i]['code']); + ++$i; + } + + }//end testAttributeContainingTextLookingLikeCloseTag() + + + /** + * Data provider. + * + * @see dataAttributeOnTextLookingLikeCloseTag() + * + * @return array + */ + public function dataAttributeOnTextLookingLikeCloseTag() + { + return [ + [ + '/* testAttributeContainingTextLookingLikeCloseTag */', + 5, + [ + [ + 'T_STRING', + 'DeprecationReason', + ], + [ + 'T_OPEN_PARENTHESIS', + '(', + ], + [ + 'T_CONSTANT_ENCAPSED_STRING', + "'reason: '", + ], + [ + 'T_CLOSE_PARENTHESIS', + ')', + ], + [ + 'T_ATTRIBUTE_END', + ']', + ], + ], + [ + T_WHITESPACE, + T_FUNCTION, + T_WHITESPACE, + T_STRING, + T_OPEN_PARENTHESIS, + T_CLOSE_PARENTHESIS, + T_WHITESPACE, + T_OPEN_CURLY_BRACKET, + T_CLOSE_CURLY_BRACKET, + ], + ], + [ + '/* testAttributeContainingMultilineTextLookingLikeCloseTag */', + 8, + [ + [ + 'T_STRING', + 'DeprecationReason', + ], + [ + 'T_OPEN_PARENTHESIS', + '(', + ], + [ + 'T_WHITESPACE', + "\n", + ], + [ + 'T_WHITESPACE', + " ", + ], + [ + 'T_CONSTANT_ENCAPSED_STRING', + "'reason: '", + ], + [ + 'T_WHITESPACE', + "\n", + ], + [ + 'T_CLOSE_PARENTHESIS', + ')', + ], + [ + 'T_ATTRIBUTE_END', + ']', + ], + ], + [ + T_WHITESPACE, + T_FUNCTION, + T_WHITESPACE, + T_STRING, + T_OPEN_PARENTHESIS, + T_CLOSE_PARENTHESIS, + T_WHITESPACE, + T_OPEN_CURLY_BRACKET, + T_CLOSE_CURLY_BRACKET, + ], + ], + ]; + + }//end dataAttributeOnTextLookingLikeCloseTag() + + /** * Test that invalid attribute (or comment starting with #[ and without ]) are parsed correctly. * diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.inc new file mode 100644 index 00000000..82bfe24f --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.inc @@ -0,0 +1,95 @@ +enum = 'foo'; + } +} + +/* testEnumUsedAsFunctionName */ +function enum() +{ +} + +/* testDeclarationContainingComment */ +enum /* comment */ Name +{ + case SOME_CASE; +} + +enum /* testEnumUsedAsEnumName */ Enum +{ +} + +/* testEnumUsedAsNamespaceName */ +namespace Enum; +/* testEnumUsedAsPartOfNamespaceName */ +namespace My\Enum\Collection; +/* testEnumUsedInObjectInitialization */ +$obj = new Enum; +/* testEnumAsFunctionCall */ +$var = enum($a, $b); +/* testEnumAsFunctionCallWithNamespace */ +var = namespace\enum(); +/* testClassConstantFetchWithEnumAsClassName */ +echo Enum::CONSTANT; +/* testClassConstantFetchWithEnumAsConstantName */ +echo ClassName::ENUM; + +/* testParseErrorMissingName */ +enum { + case SOME_CASE; +} + +/* testParseErrorLiveCoding */ +// This must be the last test in the file. +enum diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.php new file mode 100644 index 00000000..33cff3a2 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillEnumTest.php @@ -0,0 +1,229 @@ + + * @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class BackfillEnumTest extends AbstractMethodUnitTest +{ + + + /** + * Test that the "enum" keyword is tokenized as such. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $testContent The token content to look for. + * @param int $openerOffset Offset to find expected scope opener. + * @param int $closerOffset Offset to find expected scope closer. + * + * @dataProvider dataEnums + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testEnums($testMarker, $testContent, $openerOffset, $closerOffset) + { + $tokens = self::$phpcsFile->getTokens(); + + $enum = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent); + + $this->assertSame(T_ENUM, $tokens[$enum]['code']); + $this->assertSame('T_ENUM', $tokens[$enum]['type']); + + $this->assertArrayHasKey('scope_condition', $tokens[$enum]); + $this->assertArrayHasKey('scope_opener', $tokens[$enum]); + $this->assertArrayHasKey('scope_closer', $tokens[$enum]); + + $this->assertSame($enum, $tokens[$enum]['scope_condition']); + + $scopeOpener = $tokens[$enum]['scope_opener']; + $scopeCloser = $tokens[$enum]['scope_closer']; + + $expectedScopeOpener = ($enum + $openerOffset); + $expectedScopeCloser = ($enum + $closerOffset); + + $this->assertSame($expectedScopeOpener, $scopeOpener); + $this->assertArrayHasKey('scope_condition', $tokens[$scopeOpener]); + $this->assertArrayHasKey('scope_opener', $tokens[$scopeOpener]); + $this->assertArrayHasKey('scope_closer', $tokens[$scopeOpener]); + $this->assertSame($enum, $tokens[$scopeOpener]['scope_condition']); + $this->assertSame($scopeOpener, $tokens[$scopeOpener]['scope_opener']); + $this->assertSame($scopeCloser, $tokens[$scopeOpener]['scope_closer']); + + $this->assertSame($expectedScopeCloser, $scopeCloser); + $this->assertArrayHasKey('scope_condition', $tokens[$scopeCloser]); + $this->assertArrayHasKey('scope_opener', $tokens[$scopeCloser]); + $this->assertArrayHasKey('scope_closer', $tokens[$scopeCloser]); + $this->assertSame($enum, $tokens[$scopeCloser]['scope_condition']); + $this->assertSame($scopeOpener, $tokens[$scopeCloser]['scope_opener']); + $this->assertSame($scopeCloser, $tokens[$scopeCloser]['scope_closer']); + + }//end testEnums() + + + /** + * Data provider. + * + * @see testEnums() + * + * @return array + */ + public function dataEnums() + { + return [ + [ + '/* testPureEnum */', + 'enum', + 4, + 12, + ], + [ + '/* testBackedIntEnum */', + 'enum', + 7, + 29, + ], + [ + '/* testBackedStringEnum */', + 'enum', + 8, + 30, + ], + [ + '/* testComplexEnum */', + 'enum', + 11, + 72, + ], + [ + '/* testEnumWithEnumAsClassName */', + 'enum', + 6, + 7, + ], + [ + '/* testEnumIsCaseInsensitive */', + 'EnUm', + 4, + 5, + ], + [ + '/* testDeclarationContainingComment */', + 'enum', + 6, + 14, + ], + ]; + + }//end dataEnums() + + + /** + * Test that "enum" when not used as the keyword is still tokenized as `T_STRING`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $testContent The token content to look for. + * + * @dataProvider dataNotEnums + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testNotEnums($testMarker, $testContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent); + $this->assertSame(T_STRING, $tokens[$target]['code']); + $this->assertSame('T_STRING', $tokens[$target]['type']); + + }//end testNotEnums() + + + /** + * Data provider. + * + * @see testNotEnums() + * + * @return array + */ + public function dataNotEnums() + { + return [ + [ + '/* testEnumAsClassNameAfterEnumKeyword */', + 'Enum', + ], + [ + '/* testEnumUsedAsClassName */', + 'Enum', + ], + [ + '/* testEnumUsedAsClassConstantName */', + 'ENUM', + ], + [ + '/* testEnumUsedAsMethodName */', + 'enum', + ], + [ + '/* testEnumUsedAsPropertyName */', + 'enum', + ], + [ + '/* testEnumUsedAsFunctionName */', + 'enum', + ], + [ + '/* testEnumUsedAsEnumName */', + 'Enum', + ], + [ + '/* testEnumUsedAsNamespaceName */', + 'Enum', + ], + [ + '/* testEnumUsedAsPartOfNamespaceName */', + 'Enum', + ], + [ + '/* testEnumUsedInObjectInitialization */', + 'Enum', + ], + [ + '/* testEnumAsFunctionCall */', + 'enum', + ], + [ + '/* testEnumAsFunctionCallWithNamespace */', + 'enum', + ], + [ + '/* testClassConstantFetchWithEnumAsClassName */', + 'Enum', + ], + [ + '/* testClassConstantFetchWithEnumAsConstantName */', + 'ENUM', + ], + [ + '/* testParseErrorMissingName */', + 'enum', + ], + [ + '/* testParseErrorLiveCoding */', + 'enum', + ], + ]; + + }//end dataNotEnums() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.inc new file mode 100644 index 00000000..154d4895 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.inc @@ -0,0 +1,28 @@ + + * @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class BackfillExplicitOctalNotationTest extends AbstractMethodUnitTest +{ + + + /** + * Test that explicitly-defined octal values are tokenized as a single number and not as a number and a string. + * + * @param string $marker The comment which prefaces the target token in the test file. + * @param string $value The expected content of the token + * @param int|string $nextToken The expected next token. + * @param string $nextContent The expected content of the next token. + * + * @dataProvider dataExplicitOctalNotation + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testExplicitOctalNotation($marker, $value, $nextToken, $nextContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $number = $this->getTargetToken($marker, [T_LNUMBER]); + + $this->assertSame($value, $tokens[$number]['content'], 'Content of integer token does not match expectation'); + + $this->assertSame($nextToken, $tokens[($number + 1)]['code'], 'Next token is not the expected type, but '.$tokens[($number + 1)]['type']); + $this->assertSame($nextContent, $tokens[($number + 1)]['content'], 'Next token did not have the expected contents'); + + }//end testExplicitOctalNotation() + + + /** + * Data provider. + * + * @see testExplicitOctalNotation() + * + * @return array + */ + public function dataExplicitOctalNotation() + { + return [ + [ + 'marker' => '/* testExplicitOctal */', + 'value' => '0o137041', + 'nextToken' => T_SEMICOLON, + 'nextContent' => ';', + ], + [ + 'marker' => '/* testExplicitOctalCapitalised */', + 'value' => '0O137041', + 'nextToken' => T_SEMICOLON, + 'nextContent' => ';', + ], + [ + 'marker' => '/* testExplicitOctalWithNumericSeparator */', + 'value' => '0o137_041', + 'nextToken' => T_SEMICOLON, + 'nextContent' => ';', + ], + [ + 'marker' => '/* testInvalid1 */', + 'value' => '0', + 'nextToken' => T_STRING, + 'nextContent' => 'o_137', + ], + [ + 'marker' => '/* testInvalid2 */', + 'value' => '0', + 'nextToken' => T_STRING, + 'nextContent' => 'O_41', + ], + [ + 'marker' => '/* testInvalid3 */', + 'value' => '0', + 'nextToken' => T_STRING, + 'nextContent' => 'o91', + ], + [ + 'marker' => '/* testInvalid4 */', + 'value' => '0O2', + 'nextToken' => T_LNUMBER, + 'nextContent' => '82', + ], + [ + 'marker' => '/* testInvalid5 */', + 'value' => '0o2', + 'nextToken' => T_LNUMBER, + 'nextContent' => '8_2', + ], + [ + 'marker' => '/* testInvalid6 */', + 'value' => '0o2', + 'nextToken' => T_STRING, + 'nextContent' => '_82', + ], + ]; + + }//end dataExplicitOctalNotation() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.inc index 72cb2442..13f165b7 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.inc @@ -23,6 +23,9 @@ function fn() {} /* testNestedOuter */ $fn = fn($x) => /* testNestedInner */ fn($y) => $x * $y + $z; +/* testNestedSharedCloserOuter */ +$foo = foo(fn() => /* testNestedSharedCloserInner */ fn() => bar() === true); + /* testFunctionCall */ $extended = fn($c) => $callable($factory($c), $c); @@ -60,6 +63,11 @@ $a = [ 'a' => fn() => return 1, ]; +/* testArrayValueNoTrailingComma */ +$a = [ + 'a' => fn() => foo() +]; + /* testYield */ $a = fn($x) => yield 'k' => $x; @@ -93,6 +101,9 @@ $arrowWithUnionReturn = fn($param) : int|float => $param | 10; /* testTernary */ $fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b'; +/* testTernaryWithTypes */ +$fn = fn(int|null $a) : array|null => $a ? null : []; + function matchInArrow($x) { /* testWithMatchValue */ $fn = fn($x) => match(true) { diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.php index 6404026c..4d0f4c06 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillFnTokenTest.php @@ -128,6 +128,41 @@ public function testNestedInner() }//end testNestedInner() + /** + * Test nested arrow functions with a shared closer. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testNestedSharedCloser() + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken('/* testNestedSharedCloserOuter */', T_FN); + $this->backfillHelper($token); + $this->scopePositionTestHelper($token, 4, 20); + + $token = $this->getTargetToken('/* testNestedSharedCloserInner */', T_FN); + $this->backfillHelper($token, true); + + $expectedScopeOpener = ($token + 4); + $expectedScopeCloser = ($token + 12); + + $this->assertSame($expectedScopeOpener, $tokens[$token]['scope_opener'], 'Scope opener for "inner" arrow function is not the arrow token'); + $this->assertSame($expectedScopeCloser, $tokens[$token]['scope_closer'], 'Scope closer for "inner" arrow function is not the TRUE token'); + + $opener = $tokens[$token]['scope_opener']; + $this->assertSame($expectedScopeOpener, $tokens[$opener]['scope_opener'], 'Opener scope opener for "inner" arrow function is not the arrow token'); + $this->assertSame($expectedScopeCloser, $tokens[$opener]['scope_closer'], 'Opener scope closer for "inner" arrow function is not the semicolon token'); + + $closer = $tokens[$token]['scope_closer']; + $this->assertSame(($token - 4), $tokens[$closer]['scope_opener'], 'Closer scope opener for "inner" arrow function is not the arrow token of the "outer" arrow function (shared scope closer)'); + $this->assertSame($expectedScopeCloser, $tokens[$closer]['scope_closer'], 'Closer scope closer for "inner" arrow function is not the TRUE token'); + + }//end testNestedSharedCloser() + + /** * Test arrow functions that call functions. * @@ -272,6 +307,22 @@ public function testArrayValue() }//end testArrayValue() + /** + * Test arrow functions that are used as array values with no trailing comma. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testArrayValueNoTrailingComma() + { + $token = $this->getTargetToken('/* testArrayValueNoTrailingComma */', T_FN); + $this->backfillHelper($token); + $this->scopePositionTestHelper($token, 4, 8, 'closing parenthesis'); + + }//end testArrayValueNoTrailingComma() + + /** * Test arrow functions that use the yield keyword. * @@ -445,6 +496,24 @@ public function testTernary() }//end testTernary() + /** + * Test typed arrow functions used in ternary operators. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testTernaryWithTypes() + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken('/* testTernaryWithTypes */', T_FN); + $this->backfillHelper($token); + $this->scopePositionTestHelper($token, 15, 27); + + }//end testTernaryWithTypes() + + /** * Test arrow function returning a match control structure. * diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc index eef53f59..d8559705 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc @@ -34,6 +34,12 @@ $foo = 0b0101_1111; /* testOctal */ $foo = 0137_041; +/* testExplicitOctal */ +$foo = 0o137_041; + +/* testExplicitOctalCapitalised */ +$foo = 0O137_041; + /* testIntMoreThanMax */ $foo = 10_223_372_036_854_775_807; @@ -71,6 +77,12 @@ $testValue = 107_925_284 .88; /* testInvalid10 */ $testValue = 107_925_284/*comment*/.88; +/* testInvalid11 */ +$foo = 0o_137; + +/* testInvalid12 */ +$foo = 0O_41; + /* * Ensure that legitimate calculations are not touched by the backfill. */ diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.php index ee4275a2..645088fd 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillNumericSeparatorTest.php @@ -132,6 +132,20 @@ public function dataTestBackfill() 'value' => '0137_041', ], ], + [ + [ + 'marker' => '/* testExplicitOctal */', + 'type' => 'T_LNUMBER', + 'value' => '0o137_041', + ], + ], + [ + [ + 'marker' => '/* testExplicitOctalCapitalised */', + 'type' => 'T_LNUMBER', + 'value' => '0O137_041', + ], + ], [ [ 'marker' => '/* testIntMoreThanMax */', @@ -322,6 +336,32 @@ public function dataNoBackfill() ], ], ], + [ + '/* testInvalid11 */', + [ + [ + 'code' => T_LNUMBER, + 'content' => '0', + ], + [ + 'code' => T_STRING, + 'content' => 'o_137', + ], + ], + ], + [ + '/* testInvalid12 */', + [ + [ + 'code' => T_LNUMBER, + 'content' => '0', + ], + [ + 'code' => T_STRING, + 'content' => 'O_41', + ], + ], + ], [ '/* testCalc1 */', [ diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.inc new file mode 100644 index 00000000..eaf0b4b3 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.inc @@ -0,0 +1,100 @@ +readonly = 'foo'; + + /* testReadonlyPropertyInTernaryOperator */ + $isReadonly = $this->readonly ? true : false; + } +} + +/* testReadonlyUsedAsFunctionName */ +function readonly() +{ +} + +/* testReadonlyUsedAsNamespaceName */ +namespace Readonly; +/* testReadonlyUsedAsPartOfNamespaceName */ +namespace My\Readonly\Collection; +/* testReadonlyAsFunctionCall */ +$var = readonly($a, $b); +/* testClassConstantFetchWithReadonlyAsConstantName */ +echo ClassName::READONLY; + +/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */ +$var = readonly /* comment */ (); + +/* testParseErrorLiveCoding */ +// This must be the last test in the file. +readonly diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.php new file mode 100644 index 00000000..dddc18eb --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BackfillReadonlyTest.php @@ -0,0 +1,236 @@ + + * @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class BackfillReadonlyTest extends AbstractMethodUnitTest +{ + + + /** + * Test that the "readonly" keyword is tokenized as such. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $testContent The token content to look for. + * + * @dataProvider dataReadonly + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testReadonly($testMarker, $testContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent); + $this->assertSame(T_READONLY, $tokens[$target]['code']); + $this->assertSame('T_READONLY', $tokens[$target]['type']); + + }//end testReadonly() + + + /** + * Data provider. + * + * @see testReadonly() + * + * @return array + */ + public function dataReadonly() + { + return [ + [ + '/* testReadonlyProperty */', + 'readonly', + ], + [ + '/* testVarReadonlyProperty */', + 'readonly', + ], + [ + '/* testReadonlyVarProperty */', + 'readonly', + ], + [ + '/* testStaticReadonlyProperty */', + 'readonly', + ], + [ + '/* testReadonlyStaticProperty */', + 'readonly', + ], + [ + '/* testConstReadonlyProperty */', + 'readonly', + ], + [ + '/* testReadonlyPropertyWithoutType */', + 'readonly', + ], + [ + '/* testPublicReadonlyProperty */', + 'readonly', + ], + [ + '/* testProtectedReadonlyProperty */', + 'readonly', + ], + [ + '/* testPrivateReadonlyProperty */', + 'readonly', + ], + [ + '/* testPublicReadonlyPropertyWithReadonlyFirst */', + 'readonly', + ], + [ + '/* testProtectedReadonlyPropertyWithReadonlyFirst */', + 'readonly', + ], + [ + '/* testPrivateReadonlyPropertyWithReadonlyFirst */', + 'readonly', + ], + [ + '/* testReadonlyWithCommentsInDeclaration */', + 'readonly', + ], + [ + '/* testReadonlyWithNullableProperty */', + 'readonly', + ], + [ + '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */', + 'readonly', + ], + [ + '/* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */', + 'readonly', + ], + [ + '/* testReadonlyPropertyWithArrayTypeHint */', + 'readonly', + ], + [ + '/* testReadonlyPropertyWithSelfTypeHint */', + 'readonly', + ], + [ + '/* testReadonlyPropertyWithParentTypeHint */', + 'readonly', + ], + [ + '/* testReadonlyPropertyWithFullyQualifiedTypeHint */', + 'readonly', + ], + [ + '/* testReadonlyIsCaseInsensitive */', + 'ReAdOnLy', + ], + [ + '/* testReadonlyConstructorPropertyPromotion */', + 'readonly', + ], + [ + '/* testReadonlyConstructorPropertyPromotionWithReference */', + 'ReadOnly', + ], + [ + '/* testReadonlyPropertyInAnonymousClass */', + 'readonly', + ], + [ + '/* testReadonlyUsedAsFunctionCallWithSpaceBetweenKeywordAndParens */', + 'readonly', + ], + [ + '/* testParseErrorLiveCoding */', + 'readonly', + ], + ]; + + }//end dataReadonly() + + + /** + * Test that "readonly" when not used as the keyword is still tokenized as `T_STRING`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $testContent The token content to look for. + * + * @dataProvider dataNotReadonly + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testNotReadonly($testMarker, $testContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, [T_READONLY, T_STRING], $testContent); + $this->assertSame(T_STRING, $tokens[$target]['code']); + $this->assertSame('T_STRING', $tokens[$target]['type']); + + }//end testNotReadonly() + + + /** + * Data provider. + * + * @see testNotReadonly() + * + * @return array + */ + public function dataNotReadonly() + { + return [ + [ + '/* testReadonlyUsedAsClassConstantName */', + 'READONLY', + ], + [ + '/* testReadonlyUsedAsMethodName */', + 'readonly', + ], + [ + '/* testReadonlyUsedAsPropertyName */', + 'readonly', + ], + [ + '/* testReadonlyPropertyInTernaryOperator */', + 'readonly', + ], + [ + '/* testReadonlyUsedAsFunctionName */', + 'readonly', + ], + [ + '/* testReadonlyUsedAsNamespaceName */', + 'Readonly', + ], + [ + '/* testReadonlyUsedAsPartOfNamespaceName */', + 'Readonly', + ], + [ + '/* testReadonlyAsFunctionCall */', + 'readonly', + ], + [ + '/* testClassConstantFetchWithReadonlyAsConstantName */', + 'READONLY', + ], + ]; + + }//end dataNotReadonly() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.inc index ec1801d5..bfdbdc18 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.inc @@ -24,6 +24,30 @@ class TypeUnion /* testTypeUnionPropertyMulti3 */ | null $arrayOrFalse; + /* testTypeUnionPropertyNamespaceRelative */ + public namespace\Sub\NameA|namespace\Sub\NameB $namespaceRelative; + + /* testTypeUnionPropertyPartiallyQualified */ + public Partially\Qualified\NameA|Partially\Qualified\NameB $partiallyQual; + + /* testTypeUnionPropertyFullyQualified */ + public \Fully\Qualified\NameA|\Fully\Qualified\NameB $fullyQual; + + /* testTypeUnionPropertyWithReadOnlyKeyword */ + protected readonly string|null $array; + + /* testTypeUnionPropertyWithStaticAndReadOnlyKeywords */ + static readonly string|null $array; + + /* testTypeUnionPropertyWithVarAndReadOnlyKeywords */ + var readonly string|null $array; + + /* testTypeUnionPropertyWithReadOnlyKeywordFirst */ + readonly protected string|null $array; + + /* testTypeUnionPropertyWithOnlyReadOnlyKeyword */ + readonly string|null $nullableString; + public function paramTypes( /* testTypeUnionParam1 */ int|float $paramA /* testBitwiseOrParamDefaultValue */ = CONSTANT_A | CONSTANT_B, @@ -35,6 +59,15 @@ class TypeUnion return (($a1 ^ $b1) |($a2 ^ $b2)) + $c; } + public function identifierNames( + /* testTypeUnionParamNamespaceRelative */ + namespace\Sub\NameA|namespace\Sub\NameB $paramA, + /* testTypeUnionParamPartiallyQualified */ + Partially\Qualified\NameA|Partially\Qualified\NameB $paramB, + /* testTypeUnionParamFullyQualified */ + \Fully\Qualified\NameA|\Fully\Qualified\NameB $paramC, + ) {} + /* testTypeUnionReturnType */ public function returnType() : int|false {} @@ -43,6 +76,15 @@ class TypeUnion /* testTypeUnionAbstractMethodReturnType1 */ abstract public function abstractMethod(): object|array /* testTypeUnionAbstractMethodReturnType2 */ |false; + + /* testTypeUnionReturnTypeNamespaceRelative */ + public function identifierNamesReturnRelative() : namespace\Sub\NameA|namespace\Sub\NameB {} + + /* testTypeUnionReturnPartiallyQualified */ + public function identifierNamesReturnPQ() : Partially\Qualified\NameA|Partially\Qualified\NameB {} + + /* testTypeUnionReturnFullyQualified */ + public function identifierNamesReturnFQ() : \Fully\Qualified\NameA|\Fully\Qualified\NameB {} } /* testTypeUnionClosureParamIllegalNullable */ diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.php index f6288d81..d56e7340 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/BitwiseOrTest.php @@ -102,13 +102,27 @@ public function dataTypeUnion() ['/* testTypeUnionPropertyMulti1 */'], ['/* testTypeUnionPropertyMulti2 */'], ['/* testTypeUnionPropertyMulti3 */'], + ['/* testTypeUnionPropertyNamespaceRelative */'], + ['/* testTypeUnionPropertyPartiallyQualified */'], + ['/* testTypeUnionPropertyFullyQualified */'], + ['/* testTypeUnionPropertyWithReadOnlyKeyword */'], + ['/* testTypeUnionPropertyWithReadOnlyKeywordFirst */'], + ['/* testTypeUnionPropertyWithStaticAndReadOnlyKeywords */'], + ['/* testTypeUnionPropertyWithVarAndReadOnlyKeywords */'], + ['/* testTypeUnionPropertyWithOnlyReadOnlyKeyword */'], ['/* testTypeUnionParam1 */'], ['/* testTypeUnionParam2 */'], ['/* testTypeUnionParam3 */'], + ['/* testTypeUnionParamNamespaceRelative */'], + ['/* testTypeUnionParamPartiallyQualified */'], + ['/* testTypeUnionParamFullyQualified */'], ['/* testTypeUnionReturnType */'], ['/* testTypeUnionConstructorPropertyPromotion */'], ['/* testTypeUnionAbstractMethodReturnType1 */'], ['/* testTypeUnionAbstractMethodReturnType2 */'], + ['/* testTypeUnionReturnTypeNamespaceRelative */'], + ['/* testTypeUnionReturnPartiallyQualified */'], + ['/* testTypeUnionReturnFullyQualified */'], ['/* testTypeUnionClosureParamIllegalNullable */'], ['/* testTypeUnionWithReference */'], ['/* testTypeUnionWithSpreadOperator */'], diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.inc new file mode 100644 index 00000000..e3c10ad8 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.inc @@ -0,0 +1,227 @@ + 'a', + 2 => 'b', + /* testMatchDefaultIsKeyword */ default => 'default', +}; + +$closure = /* testFnIsKeyword */ fn () => 'string'; + +function () { + /* testYieldIsKeyword */ yield $f; + /* testYieldFromIsKeyword */ yield from someFunction(); +}; + +/* testDeclareIsKeyword */ declare(ticks=1): +/* testEndDeclareIsKeyword */ enddeclare; + +if (true /* testAndIsKeyword */ and false /* testOrIsKeyword */ or null /* testXorIsKeyword */ xor 0) { + +} + +$anonymousClass = new /* testAnonymousClassIsKeyword */ class {}; +$anonymousClass2 = new class /* testExtendsInAnonymousClassIsKeyword */ extends SomeParent {}; +$anonymousClass3 = new class /* testImplementsInAnonymousClassIsKeyword */ implements SomeInterface {}; + +$instantiated1 = new /* testClassInstantiationParentIsKeyword */ parent(); +$instantiated2 = new /* testClassInstantiationSelfIsKeyword */ SELF; +$instantiated3 = new /* testClassInstantiationStaticIsKeyword */ static($param); + +class Foo extends /* testNamespaceInNameIsKeyword */ namespace\Exception +{} + +function /* testKeywordAfterFunctionShouldBeString */ eval() {} +function /* testKeywordAfterFunctionByRefShouldBeString */ &switch() {} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php new file mode 100644 index 00000000..a747e573 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php @@ -0,0 +1,509 @@ + + * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; +use PHP_CodeSniffer\Util\Tokens; + +class ContextSensitiveKeywordsTest extends AbstractMethodUnitTest +{ + + + /** + * Test that context sensitive keyword is tokenized as string when it should be string. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataStrings + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testStrings($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken($testMarker, (Tokens::$contextSensitiveKeywords + [T_STRING])); + + $this->assertSame(T_STRING, $tokens[$token]['code']); + $this->assertSame('T_STRING', $tokens[$token]['type']); + + }//end testStrings() + + + /** + * Data provider. + * + * @see testStrings() + * + * @return array + */ + public function dataStrings() + { + return [ + ['/* testAbstract */'], + ['/* testArray */'], + ['/* testAs */'], + ['/* testBreak */'], + ['/* testCallable */'], + ['/* testCase */'], + ['/* testCatch */'], + ['/* testClass */'], + ['/* testClone */'], + ['/* testConst */'], + ['/* testContinue */'], + ['/* testDeclare */'], + ['/* testDefault */'], + ['/* testDo */'], + ['/* testEcho */'], + ['/* testElse */'], + ['/* testElseIf */'], + ['/* testEmpty */'], + ['/* testEndDeclare */'], + ['/* testEndFor */'], + ['/* testEndForeach */'], + ['/* testEndIf */'], + ['/* testEndSwitch */'], + ['/* testEndWhile */'], + ['/* testEnum */'], + ['/* testEval */'], + ['/* testExit */'], + ['/* testExtends */'], + ['/* testFinal */'], + ['/* testFinally */'], + ['/* testFn */'], + ['/* testFor */'], + ['/* testForeach */'], + ['/* testFunction */'], + ['/* testGlobal */'], + ['/* testGoto */'], + ['/* testIf */'], + ['/* testImplements */'], + ['/* testInclude */'], + ['/* testIncludeOnce */'], + ['/* testInstanceOf */'], + ['/* testInsteadOf */'], + ['/* testInterface */'], + ['/* testIsset */'], + ['/* testList */'], + ['/* testMatch */'], + ['/* testNamespace */'], + ['/* testNew */'], + ['/* testParent */'], + ['/* testPrint */'], + ['/* testPrivate */'], + ['/* testProtected */'], + ['/* testPublic */'], + ['/* testReadonly */'], + ['/* testRequire */'], + ['/* testRequireOnce */'], + ['/* testReturn */'], + ['/* testSelf */'], + ['/* testStatic */'], + ['/* testSwitch */'], + ['/* testThrows */'], + ['/* testTrait */'], + ['/* testTry */'], + ['/* testUnset */'], + ['/* testUse */'], + ['/* testVar */'], + ['/* testWhile */'], + ['/* testYield */'], + ['/* testYieldFrom */'], + ['/* testAnd */'], + ['/* testOr */'], + ['/* testXor */'], + + ['/* testKeywordAfterNamespaceShouldBeString */'], + ['/* testNamespaceNameIsString1 */'], + ['/* testNamespaceNameIsString2 */'], + ['/* testNamespaceNameIsString3 */'], + + ['/* testKeywordAfterFunctionShouldBeString */'], + ['/* testKeywordAfterFunctionByRefShouldBeString */'], + ]; + + }//end dataStrings() + + + /** + * Test that context sensitive keyword is tokenized as keyword when it should be keyword. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expectedTokenType The expected token type. + * + * @dataProvider dataKeywords + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testKeywords($testMarker, $expectedTokenType) + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken($testMarker, (Tokens::$contextSensitiveKeywords + [T_ANON_CLASS, T_MATCH_DEFAULT, T_PARENT, T_SELF, T_STRING])); + + $this->assertSame(constant($expectedTokenType), $tokens[$token]['code']); + $this->assertSame($expectedTokenType, $tokens[$token]['type']); + + }//end testKeywords() + + + /** + * Data provider. + * + * @see testKeywords() + * + * @return array + */ + public function dataKeywords() + { + return [ + [ + '/* testNamespaceIsKeyword */', + 'T_NAMESPACE', + ], + [ + '/* testAbstractIsKeyword */', + 'T_ABSTRACT', + ], + [ + '/* testClassIsKeyword */', + 'T_CLASS', + ], + [ + '/* testExtendsIsKeyword */', + 'T_EXTENDS', + ], + [ + '/* testImplementsIsKeyword */', + 'T_IMPLEMENTS', + ], + [ + '/* testUseIsKeyword */', + 'T_USE', + ], + [ + '/* testInsteadOfIsKeyword */', + 'T_INSTEADOF', + ], + [ + '/* testAsIsKeyword */', + 'T_AS', + ], + [ + '/* testConstIsKeyword */', + 'T_CONST', + ], + [ + '/* testPrivateIsKeyword */', + 'T_PRIVATE', + ], + [ + '/* testProtectedIsKeyword */', + 'T_PROTECTED', + ], + [ + '/* testPublicIsKeyword */', + 'T_PUBLIC', + ], + [ + '/* testVarIsKeyword */', + 'T_VAR', + ], + [ + '/* testStaticIsKeyword */', + 'T_STATIC', + ], + [ + '/* testReadonlyIsKeyword */', + 'T_READONLY', + ], + [ + '/* testFinalIsKeyword */', + 'T_FINAL', + ], + [ + '/* testFunctionIsKeyword */', + 'T_FUNCTION', + ], + [ + '/* testCallableIsKeyword */', + 'T_CALLABLE', + ], + [ + '/* testSelfIsKeyword */', + 'T_SELF', + ], + [ + '/* testParentIsKeyword */', + 'T_PARENT', + ], + [ + '/* testReturnIsKeyword */', + 'T_RETURN', + ], + + [ + '/* testInterfaceIsKeyword */', + 'T_INTERFACE', + ], + [ + '/* testTraitIsKeyword */', + 'T_TRAIT', + ], + [ + '/* testEnumIsKeyword */', + 'T_ENUM', + ], + + [ + '/* testNewIsKeyword */', + 'T_NEW', + ], + [ + '/* testInstanceOfIsKeyword */', + 'T_INSTANCEOF', + ], + [ + '/* testCloneIsKeyword */', + 'T_CLONE', + ], + + [ + '/* testIfIsKeyword */', + 'T_IF', + ], + [ + '/* testEmptyIsKeyword */', + 'T_EMPTY', + ], + [ + '/* testElseIfIsKeyword */', + 'T_ELSEIF', + ], + [ + '/* testElseIsKeyword */', + 'T_ELSE', + ], + [ + '/* testEndIfIsKeyword */', + 'T_ENDIF', + ], + + [ + '/* testForIsKeyword */', + 'T_FOR', + ], + [ + '/* testEndForIsKeyword */', + 'T_ENDFOR', + ], + + [ + '/* testForeachIsKeyword */', + 'T_FOREACH', + ], + [ + '/* testEndForeachIsKeyword */', + 'T_ENDFOREACH', + ], + + [ + '/* testSwitchIsKeyword */', + 'T_SWITCH', + ], + [ + '/* testCaseIsKeyword */', + 'T_CASE', + ], + [ + '/* testDefaultIsKeyword */', + 'T_DEFAULT', + ], + [ + '/* testEndSwitchIsKeyword */', + 'T_ENDSWITCH', + ], + [ + '/* testBreakIsKeyword */', + 'T_BREAK', + ], + [ + '/* testContinueIsKeyword */', + 'T_CONTINUE', + ], + + [ + '/* testDoIsKeyword */', + 'T_DO', + ], + [ + '/* testWhileIsKeyword */', + 'T_WHILE', + ], + [ + '/* testEndWhileIsKeyword */', + 'T_ENDWHILE', + ], + + [ + '/* testTryIsKeyword */', + 'T_TRY', + ], + [ + '/* testThrowIsKeyword */', + 'T_THROW', + ], + [ + '/* testCatchIsKeyword */', + 'T_CATCH', + ], + [ + '/* testFinallyIsKeyword */', + 'T_FINALLY', + ], + + [ + '/* testGlobalIsKeyword */', + 'T_GLOBAL', + ], + [ + '/* testEchoIsKeyword */', + 'T_ECHO', + ], + [ + '/* testPrintIsKeyword */', + 'T_PRINT', + ], + [ + '/* testDieIsKeyword */', + 'T_EXIT', + ], + [ + '/* testEvalIsKeyword */', + 'T_EVAL', + ], + [ + '/* testExitIsKeyword */', + 'T_EXIT', + ], + [ + '/* testIssetIsKeyword */', + 'T_ISSET', + ], + [ + '/* testUnsetIsKeyword */', + 'T_UNSET', + ], + + [ + '/* testIncludeIsKeyword */', + 'T_INCLUDE', + ], + [ + '/* testIncludeOnceIsKeyword */', + 'T_INCLUDE_ONCE', + ], + [ + '/* testRequireIsKeyword */', + 'T_REQUIRE', + ], + [ + '/* testRequireOnceIsKeyword */', + 'T_REQUIRE_ONCE', + ], + + [ + '/* testListIsKeyword */', + 'T_LIST', + ], + [ + '/* testGotoIsKeyword */', + 'T_GOTO', + ], + [ + '/* testMatchIsKeyword */', + 'T_MATCH', + ], + [ + '/* testMatchDefaultIsKeyword */', + 'T_MATCH_DEFAULT', + ], + [ + '/* testFnIsKeyword */', + 'T_FN', + ], + + [ + '/* testYieldIsKeyword */', + 'T_YIELD', + ], + [ + '/* testYieldFromIsKeyword */', + 'T_YIELD_FROM', + ], + + [ + '/* testDeclareIsKeyword */', + 'T_DECLARE', + ], + [ + '/* testEndDeclareIsKeyword */', + 'T_ENDDECLARE', + ], + + [ + '/* testAndIsKeyword */', + 'T_LOGICAL_AND', + ], + [ + '/* testOrIsKeyword */', + 'T_LOGICAL_OR', + ], + [ + '/* testXorIsKeyword */', + 'T_LOGICAL_XOR', + ], + + [ + '/* testAnonymousClassIsKeyword */', + 'T_ANON_CLASS', + ], + [ + '/* testExtendsInAnonymousClassIsKeyword */', + 'T_EXTENDS', + ], + [ + '/* testImplementsInAnonymousClassIsKeyword */', + 'T_IMPLEMENTS', + ], + [ + '/* testClassInstantiationParentIsKeyword */', + 'T_PARENT', + ], + [ + '/* testClassInstantiationSelfIsKeyword */', + 'T_SELF', + ], + [ + '/* testClassInstantiationStaticIsKeyword */', + 'T_STATIC', + ], + [ + '/* testNamespaceInNameIsKeyword */', + 'T_NAMESPACE', + ], + ]; + + }//end dataKeywords() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.inc index 6de44857..648149d2 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.inc @@ -193,3 +193,11 @@ function switchWithConstantNonDefault($i) { return 2; } } + +class Foo { + /* testClassConstant */ + const DEFAULT = 'foo'; + + /* testMethodDeclaration */ + public function default() {} +} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.php index 2d1e68cb..9a5b061a 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DefaultKeywordTest.php @@ -267,9 +267,36 @@ public function dataNotDefaultKeyword() 'class-property-in-switch-case' => ['/* testClassPropertyInSwitchCase */'], 'namespaced-constant-in-switch-case' => ['/* testNamespacedConstantInSwitchCase */'], 'namespace-relative-constant-in-switch-case' => ['/* testNamespaceRelativeConstantInSwitchCase */'], + + 'class-constant-declaration' => ['/* testClassConstant */'], + 'class-method-declaration' => [ + '/* testMethodDeclaration */', + 'default', + ], ]; }//end dataNotDefaultKeyword() + /** + * Test a specific edge case where a scope opener would be incorrectly set. + * + * @link https://github.com/squizlabs/PHP_CodeSniffer/issues/3326 + * + * @return void + */ + public function testIssue3326() + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken('/* testClassConstant */', [T_SEMICOLON]); + $tokenArray = $tokens[$token]; + + $this->assertArrayNotHasKey('scope_condition', $tokenArray, 'Scope condition is set'); + $this->assertArrayNotHasKey('scope_opener', $tokenArray, 'Scope opener is set'); + $this->assertArrayNotHasKey('scope_closer', $tokenArray, 'Scope closer is set'); + + }//end testIssue3326() + + }//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.inc index 3ca10257..b67b0660 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.inc @@ -185,7 +185,7 @@ function matchShortArrayMismash() { } => match ($test) { /* testMatchArrowInComplexShortArrayValue1 */ 1 => [ /* testShortArrayArrowInComplexMatchValueinShortArrayValue */ 1 => 'a'], - /* testMatchArrowInComplexShortArrayValue1 */ + /* testMatchArrowInComplexShortArrayValue2 */ 2 => /* testFnArrowInComplexMatchValueInShortArrayValue */ fn($y) => callMe($y) }, ]; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.php index 9a0b174c..ad1a411f 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleArrowTest.php @@ -50,52 +50,52 @@ public function testDoubleArrow($testMarker) public function dataDoubleArrow() { return [ - 'simple_long_array' => ['/* testLongArrayArrowSimple */'], - 'simple_short_array' => ['/* testShortArrayArrowSimple */'], - 'simple_long_list' => ['/* testLongListArrowSimple */'], - 'simple_short_list' => ['/* testShortListArrowSimple */'], - 'simple_yield' => ['/* testYieldArrowSimple */'], - 'simple_foreach' => ['/* testForeachArrowSimple */'], - - 'long_array_with_match_value_1' => ['/* testLongArrayArrowWithNestedMatchValue1 */'], - 'long_array_with_match_value_2' => ['/* testLongArrayArrowWithNestedMatchValue2 */'], - 'short_array_with_match_value_1' => ['/* testShortArrayArrowWithNestedMatchValue1 */'], - 'short_array_with_match_value_2' => ['/* testShortArrayArrowWithNestedMatchValue2 */'], - - 'long_array_with_match_key' => ['/* testLongArrayArrowWithMatchKey */'], - 'short_array_with_match_key' => ['/* testShortArrayArrowWithMatchKey */'], - - 'long_array_in_match_body_1' => ['/* testLongArrayArrowInMatchBody1 */'], - 'long_array_in_match_body_2' => ['/* testLongArrayArrowInMatchBody2 */'], - 'long_array_in_match_body_2' => ['/* testLongArrayArrowInMatchBody3 */'], - 'short_array_in_match_body_1' => ['/* testShortArrayArrowInMatchBody1 */'], - 'short_array_in_match_body_2' => ['/* testShortArrayArrowInMatchBody2 */'], - 'short_array_in_match_body_2' => ['/* testShortArrayArrowInMatchBody3 */'], - - 'short_array_in_match_case_1' => ['/* testShortArrayArrowinMatchCase1 */'], - 'short_array_in_match_case_2' => ['/* testShortArrayArrowinMatchCase2 */'], - 'short_array_in_match_case_3' => ['/* testShortArrayArrowinMatchCase3 */'], - 'long_array_in_match_case_4' => ['/* testLongArrayArrowinMatchCase4 */'], - - 'in_complex_short_array_key_match_value' => ['/* testShortArrayArrowInComplexMatchValueinShortArrayKey */'], - 'in_complex_short_array_toplevel' => ['/* testShortArrayArrowInComplexMatchArrayMismash */'], - 'in_complex_short_array_value_match_value' => ['/* testShortArrayArrowInComplexMatchValueinShortArrayValue */'], - - 'long_list_in_match_body' => ['/* testLongListArrowInMatchBody */'], - 'long_list_in_match_case' => ['/* testLongListArrowInMatchCase */'], - 'short_list_in_match_body' => ['/* testShortListArrowInMatchBody */'], - 'short_list_in_match_case' => ['/* testShortListArrowInMatchCase */'], - 'long_list_with_match_in_key' => ['/* testLongListArrowWithMatchInKey */'], - 'short_list_with_match_in_key' => ['/* testShortListArrowWithMatchInKey */'], - - 'long_array_with_constant_default_in_key' => ['/* testLongArrayArrowWithClassConstantKey */'], - 'short_array_with_constant_default_in_key' => ['/* testShortArrayArrowWithClassConstantKey */'], - 'yield_with_constant_default_in_key' => ['/* testYieldArrowWithClassConstantKey */'], - - 'long_array_with_default_in_key_in_match' => ['/* testLongArrayArrowWithClassConstantKeyNestedInMatch */'], - 'short_array_with_default_in_key_in_match' => ['/* testShortArrayArrowWithClassConstantKeyNestedInMatch */'], - 'long_array_with_default_in_key_with_match' => ['/* testLongArrayArrowWithClassConstantKeyWithNestedMatch */'], - 'long_array_with_default_in_key_with_match' => ['/* testShortArrayArrowWithClassConstantKeyWithNestedMatch */'], + 'simple_long_array' => ['/* testLongArrayArrowSimple */'], + 'simple_short_array' => ['/* testShortArrayArrowSimple */'], + 'simple_long_list' => ['/* testLongListArrowSimple */'], + 'simple_short_list' => ['/* testShortListArrowSimple */'], + 'simple_yield' => ['/* testYieldArrowSimple */'], + 'simple_foreach' => ['/* testForeachArrowSimple */'], + + 'long_array_with_match_value_1' => ['/* testLongArrayArrowWithNestedMatchValue1 */'], + 'long_array_with_match_value_2' => ['/* testLongArrayArrowWithNestedMatchValue2 */'], + 'short_array_with_match_value_1' => ['/* testShortArrayArrowWithNestedMatchValue1 */'], + 'short_array_with_match_value_2' => ['/* testShortArrayArrowWithNestedMatchValue2 */'], + + 'long_array_with_match_key' => ['/* testLongArrayArrowWithMatchKey */'], + 'short_array_with_match_key' => ['/* testShortArrayArrowWithMatchKey */'], + + 'long_array_in_match_body_1' => ['/* testLongArrayArrowInMatchBody1 */'], + 'long_array_in_match_body_2' => ['/* testLongArrayArrowInMatchBody2 */'], + 'long_array_in_match_body_3' => ['/* testLongArrayArrowInMatchBody3 */'], + 'short_array_in_match_body_1' => ['/* testShortArrayArrowInMatchBody1 */'], + 'short_array_in_match_body_2' => ['/* testShortArrayArrowInMatchBody2 */'], + 'short_array_in_match_body_3' => ['/* testShortArrayArrowInMatchBody3 */'], + + 'short_array_in_match_case_1' => ['/* testShortArrayArrowinMatchCase1 */'], + 'short_array_in_match_case_2' => ['/* testShortArrayArrowinMatchCase2 */'], + 'short_array_in_match_case_3' => ['/* testShortArrayArrowinMatchCase3 */'], + 'long_array_in_match_case_4' => ['/* testLongArrayArrowinMatchCase4 */'], + + 'in_complex_short_array_key_match_value' => ['/* testShortArrayArrowInComplexMatchValueinShortArrayKey */'], + 'in_complex_short_array_toplevel' => ['/* testShortArrayArrowInComplexMatchArrayMismash */'], + 'in_complex_short_array_value_match_value' => ['/* testShortArrayArrowInComplexMatchValueinShortArrayValue */'], + + 'long_list_in_match_body' => ['/* testLongListArrowInMatchBody */'], + 'long_list_in_match_case' => ['/* testLongListArrowInMatchCase */'], + 'short_list_in_match_body' => ['/* testShortListArrowInMatchBody */'], + 'short_list_in_match_case' => ['/* testShortListArrowInMatchCase */'], + 'long_list_with_match_in_key' => ['/* testLongListArrowWithMatchInKey */'], + 'short_list_with_match_in_key' => ['/* testShortListArrowWithMatchInKey */'], + + 'long_array_with_constant_default_in_key' => ['/* testLongArrayArrowWithClassConstantKey */'], + 'short_array_with_constant_default_in_key' => ['/* testShortArrayArrowWithClassConstantKey */'], + 'yield_with_constant_default_in_key' => ['/* testYieldArrowWithClassConstantKey */'], + + 'long_array_with_default_in_key_in_match' => ['/* testLongArrayArrowWithClassConstantKeyNestedInMatch */'], + 'short_array_with_default_in_key_in_match' => ['/* testShortArrayArrowWithClassConstantKeyNestedInMatch */'], + 'long_array_with_default_in_key_with_match' => ['/* testLongArrayArrowWithClassConstantKeyWithNestedMatch */'], + 'short_array_with_default_in_key_with_match' => ['/* testShortArrayArrowWithClassConstantKeyWithNestedMatch */'], ]; }//end dataDoubleArrow() @@ -170,7 +170,7 @@ public function dataMatchArrow() 'in_complex_short_array_key_1' => ['/* testMatchArrowInComplexShortArrayKey1 */'], 'in_complex_short_array_key_2' => ['/* testMatchArrowInComplexShortArrayKey2 */'], 'in_complex_short_array_value_1' => ['/* testMatchArrowInComplexShortArrayValue1 */'], - 'in_complex_short_array_key_2' => ['/* testMatchArrowInComplexShortArrayValue1 */'], + 'in_complex_short_array_value_2' => ['/* testMatchArrowInComplexShortArrayValue2 */'], 'with_long_list_in_body' => ['/* testMatchArrowWithLongListBody */'], 'with_long_list_in_case' => ['/* testMatchArrowWithLongListInCase */'], diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.inc new file mode 100644 index 00000000..62535b1e --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.inc @@ -0,0 +1,52 @@ +bar"; +/* testProperty2 */ +"{$foo->bar}"; + +/* testMethod1 */ +"{$foo->bar()}"; + +/* testClosure1 */ +"{$foo()}"; + +/* testChain1 */ +"{$foo['bar']->baz()()}"; + +/* testVariableVar1 */ +"${$bar}"; +/* testVariableVar2 */ +"${(foo)}"; +/* testVariableVar3 */ +"${foo->bar}"; + +/* testNested1 */ +"${foo["${bar}"]}"; +/* testNested2 */ +"${foo["${bar['baz']}"]}"; +/* testNested3 */ +"${foo->{$baz}}"; +/* testNested4 */ +"${foo->{${'a'}}}"; +/* testNested5 */ +"${foo->{"${'a'}"}}"; + +/* testParseError */ +"${foo["${bar diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.php new file mode 100644 index 00000000..cc9fe49e --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/DoubleQuotedStringTest.php @@ -0,0 +1,136 @@ + + * @copyright 2022 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class DoubleQuotedStringTest extends AbstractMethodUnitTest +{ + + + /** + * Test that double quoted strings contain the complete string. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expectedContent The expected content of the double quoted string. + * + * @dataProvider dataDoubleQuotedString + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testDoubleQuotedString($testMarker, $expectedContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, T_DOUBLE_QUOTED_STRING); + $this->assertSame($expectedContent, $tokens[$target]['content']); + + }//end testDoubleQuotedString() + + + /** + * Data provider. + * + * @see testDoubleQuotedString() + * + * @return array + */ + public function dataDoubleQuotedString() + { + return [ + [ + 'testMarker' => '/* testSimple1 */', + 'expectedContent' => '"$foo"', + ], + [ + 'testMarker' => '/* testSimple2 */', + 'expectedContent' => '"{$foo}"', + ], + [ + 'testMarker' => '/* testSimple3 */', + 'expectedContent' => '"${foo}"', + ], + [ + 'testMarker' => '/* testDIM1 */', + 'expectedContent' => '"$foo[bar]"', + ], + [ + 'testMarker' => '/* testDIM2 */', + 'expectedContent' => '"{$foo[\'bar\']}"', + ], + [ + 'testMarker' => '/* testDIM3 */', + 'expectedContent' => '"${foo[\'bar\']}"', + ], + [ + 'testMarker' => '/* testProperty1 */', + 'expectedContent' => '"$foo->bar"', + ], + [ + 'testMarker' => '/* testProperty2 */', + 'expectedContent' => '"{$foo->bar}"', + ], + [ + 'testMarker' => '/* testMethod1 */', + 'expectedContent' => '"{$foo->bar()}"', + ], + [ + 'testMarker' => '/* testClosure1 */', + 'expectedContent' => '"{$foo()}"', + ], + [ + 'testMarker' => '/* testChain1 */', + 'expectedContent' => '"{$foo[\'bar\']->baz()()}"', + ], + [ + 'testMarker' => '/* testVariableVar1 */', + 'expectedContent' => '"${$bar}"', + ], + [ + 'testMarker' => '/* testVariableVar2 */', + 'expectedContent' => '"${(foo)}"', + ], + [ + 'testMarker' => '/* testVariableVar3 */', + 'expectedContent' => '"${foo->bar}"', + ], + [ + 'testMarker' => '/* testNested1 */', + 'expectedContent' => '"${foo["${bar}"]}"', + ], + [ + 'testMarker' => '/* testNested2 */', + 'expectedContent' => '"${foo["${bar[\'baz\']}"]}"', + ], + [ + 'testMarker' => '/* testNested3 */', + 'expectedContent' => '"${foo->{$baz}}"', + ], + [ + 'testMarker' => '/* testNested4 */', + 'expectedContent' => '"${foo->{${\'a\'}}}"', + ], + [ + 'testMarker' => '/* testNested5 */', + 'expectedContent' => '"${foo->{"${\'a\'}"}}"', + ], + [ + 'testMarker' => '/* testParseError */', + 'expectedContent' => '"${foo["${bar +', + ], + ]; + + }//end dataDoubleQuotedString() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/EnumCaseTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/EnumCaseTest.inc new file mode 100644 index 00000000..13b87242 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/EnumCaseTest.inc @@ -0,0 +1,95 @@ + + * @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class EnumCaseTest extends AbstractMethodUnitTest +{ + + + /** + * Test that the enum "case" is converted to T_ENUM_CASE. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataEnumCases + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::recurseScopeMap + * + * @return void + */ + public function testEnumCases($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $enumCase = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]); + + $this->assertSame(T_ENUM_CASE, $tokens[$enumCase]['code']); + $this->assertSame('T_ENUM_CASE', $tokens[$enumCase]['type']); + + $this->assertArrayNotHasKey('scope_condition', $tokens[$enumCase], 'Scope condition is set'); + $this->assertArrayNotHasKey('scope_opener', $tokens[$enumCase], 'Scope opener is set'); + $this->assertArrayNotHasKey('scope_closer', $tokens[$enumCase], 'Scope closer is set'); + + }//end testEnumCases() + + + /** + * Data provider. + * + * @see testEnumCases() + * + * @return array + */ + public function dataEnumCases() + { + return [ + ['/* testPureEnumCase */'], + ['/* testBackingIntegerEnumCase */'], + ['/* testBackingStringEnumCase */'], + ['/* testEnumCaseInComplexEnum */'], + ['/* testEnumCaseIsCaseInsensitive */'], + ['/* testEnumCaseAfterSwitch */'], + ['/* testEnumCaseAfterSwitchWithEndSwitch */'], + ]; + + }//end dataEnumCases() + + + /** + * Test that "case" that is not enum case is still tokenized as `T_CASE`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataNotEnumCases + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::recurseScopeMap + * + * @return void + */ + public function testNotEnumCases($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $case = $this->getTargetToken($testMarker, [T_ENUM_CASE, T_CASE]); + + $this->assertSame(T_CASE, $tokens[$case]['code']); + $this->assertSame('T_CASE', $tokens[$case]['type']); + + $this->assertArrayHasKey('scope_condition', $tokens[$case], 'Scope condition is not set'); + $this->assertArrayHasKey('scope_opener', $tokens[$case], 'Scope opener is not set'); + $this->assertArrayHasKey('scope_closer', $tokens[$case], 'Scope closer is not set'); + + }//end testNotEnumCases() + + + /** + * Data provider. + * + * @see testNotEnumCases() + * + * @return array + */ + public function dataNotEnumCases() + { + return [ + ['/* testCaseWithSemicolonIsNotEnumCase */'], + ['/* testCaseWithConstantIsNotEnumCase */'], + ['/* testCaseWithConstantAndIdenticalIsNotEnumCase */'], + ['/* testCaseWithAssigmentToConstantIsNotEnumCase */'], + ['/* testIsNotEnumCaseIsCaseInsensitive */'], + ['/* testCaseInSwitchWhenCreatingEnumInSwitch1 */'], + ['/* testCaseInSwitchWhenCreatingEnumInSwitch2 */'], + ]; + + }//end dataNotEnumCases() + + + /** + * Test that "case" that is not enum case is still tokenized as `T_CASE`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataKeywordAsEnumCaseNameShouldBeString + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testKeywordAsEnumCaseNameShouldBeString($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $enumCaseName = $this->getTargetToken($testMarker, [T_STRING, T_INTERFACE, T_TRAIT, T_ENUM, T_FUNCTION, T_FALSE, T_DEFAULT, T_ARRAY]); + + $this->assertSame(T_STRING, $tokens[$enumCaseName]['code']); + $this->assertSame('T_STRING', $tokens[$enumCaseName]['type']); + + }//end testKeywordAsEnumCaseNameShouldBeString() + + + /** + * Data provider. + * + * @see testKeywordAsEnumCaseNameShouldBeString() + * + * @return array + */ + public function dataKeywordAsEnumCaseNameShouldBeString() + { + return [ + ['/* testKeywordAsEnumCaseNameShouldBeString1 */'], + ['/* testKeywordAsEnumCaseNameShouldBeString2 */'], + ['/* testKeywordAsEnumCaseNameShouldBeString3 */'], + ['/* testKeywordAsEnumCaseNameShouldBeString4 */'], + ]; + + }//end dataKeywordAsEnumCaseNameShouldBeString() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.inc new file mode 100644 index 00000000..e65600b6 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.inc @@ -0,0 +1,40 @@ +finally = 'foo'; + } +} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.php new file mode 100644 index 00000000..2b28bc5d --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/FinallyTest.php @@ -0,0 +1,96 @@ + + * @copyright 2021 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class FinallyTest extends AbstractMethodUnitTest +{ + + + /** + * Test that the finally keyword is tokenized as such. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataFinallyKeyword + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testFinallyKeyword($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]); + $this->assertSame(T_FINALLY, $tokens[$target]['code']); + $this->assertSame('T_FINALLY', $tokens[$target]['type']); + + }//end testFinallyKeyword() + + + /** + * Data provider. + * + * @see testFinallyKeyword() + * + * @return array + */ + public function dataFinallyKeyword() + { + return [ + ['/* testTryCatchFinally */'], + ['/* testTryFinallyCatch */'], + ['/* testTryFinally */'], + ]; + + }//end dataFinallyKeyword() + + + /** + * Test that 'finally' when not used as the reserved keyword is tokenized as `T_STRING`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataFinallyNonKeyword + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testFinallyNonKeyword($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]); + $this->assertSame(T_STRING, $tokens[$target]['code']); + $this->assertSame('T_STRING', $tokens[$target]['type']); + + }//end testFinallyNonKeyword() + + + /** + * Data provider. + * + * @see testFinallyNonKeyword() + * + * @return array + */ + public function dataFinallyNonKeyword() + { + return [ + ['/* testFinallyUsedAsClassConstantName */'], + ['/* testFinallyUsedAsMethodName */'], + ['/* testFinallyUsedAsPropertyName */'], + ]; + + }//end dataFinallyNonKeyword() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.inc index f6920f54..12df5d29 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.inc @@ -51,3 +51,6 @@ switch (true) { // Do something. break; } + +/* testNotGotoDeclarationEnumWithType */ +enum Suit: string implements Colorful, CardGame {} diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.php index fa6f8cfb..0f937cc8 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/GotoLabelTest.php @@ -163,6 +163,10 @@ public function dataNotAGotoDeclaration() '/* testNotGotoDeclarationGlobalConstantInTernary */', 'CONST_B', ], + [ + '/* testNotGotoDeclarationEnumWithType */', + 'Suit', + ], ]; }//end dataNotAGotoDeclaration() diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocNowdocCloserTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocNowdocCloserTest.inc new file mode 100644 index 00000000..a800980b --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocNowdocCloserTest.inc @@ -0,0 +1,43 @@ + + * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Files\DummyFile; +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +/** + * Heredoc/nowdoc closer token test. + * + * @requires PHP 7.3 + */ +class HeredocNowdocCloserTest extends AbstractMethodUnitTest +{ + + + /** + * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file. + * + * {@internal This is a near duplicate of the original method. Only difference is that + * tab replacement is enabled for this test.} + * + * @return void + */ + public static function setUpBeforeClass() + { + $config = new Config(); + $config->standards = ['PSR1']; + $config->tabWidth = 4; + + $ruleset = new Ruleset($config); + + // Default to a file with the same name as the test class. Extension is property based. + $relativeCN = str_replace(__NAMESPACE__, '', get_called_class()); + $relativePath = str_replace('\\', DIRECTORY_SEPARATOR, $relativeCN); + $pathToTestFile = realpath(__DIR__).$relativePath.'.'.static::$fileExtension; + + // Make sure the file gets parsed correctly based on the file type. + $contents = 'phpcs_input_file: '.$pathToTestFile.PHP_EOL; + $contents .= file_get_contents($pathToTestFile); + + self::$phpcsFile = new DummyFile($contents, $ruleset, $config); + self::$phpcsFile->process(); + + }//end setUpBeforeClass() + + + /** + * Verify that leading (indent) whitespace in a heredoc/nowdoc closer token get the tab replacement treatment. + * + * @param string $testMarker The comment prefacing the target token. + * @param array $expected Expectations for the token array. + * + * @dataProvider dataHeredocNowdocCloserTabReplacement + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap + * + * @return void + */ + public function testHeredocNowdocCloserTabReplacement($testMarker, $expected) + { + $tokens = self::$phpcsFile->getTokens(); + + $closer = $this->getTargetToken($testMarker, [T_END_HEREDOC, T_END_NOWDOC]); + + foreach ($expected as $key => $value) { + if ($key === 'orig_content' && $value === null) { + $this->assertArrayNotHasKey($key, $tokens[$closer], "Unexpected 'orig_content' key found in the token array."); + continue; + } + + $this->assertArrayHasKey($key, $tokens[$closer], "Key $key not found in the token array."); + $this->assertSame($value, $tokens[$closer][$key], "Value for key $key does not match expectation."); + } + + }//end testHeredocNowdocCloserTabReplacement() + + + /** + * Data provider. + * + * @see testHeredocNowdocCloserTabReplacement() + * + * @return array + */ + public function dataHeredocNowdocCloserTabReplacement() + { + return [ + [ + 'testMarker' => '/* testHeredocCloserNoIndent */', + 'expected' => [ + 'length' => 3, + 'content' => 'EOD', + 'orig_content' => null, + ], + ], + [ + 'testMarker' => '/* testNowdocCloserNoIndent */', + 'expected' => [ + 'length' => 3, + 'content' => 'EOD', + 'orig_content' => null, + ], + ], + [ + 'testMarker' => '/* testHeredocCloserSpaceIndent */', + 'expected' => [ + 'length' => 7, + 'content' => ' END', + 'orig_content' => null, + ], + ], + [ + 'testMarker' => '/* testNowdocCloserSpaceIndent */', + 'expected' => [ + 'length' => 8, + 'content' => ' END', + 'orig_content' => null, + ], + ], + [ + 'testMarker' => '/* testHeredocCloserTabIndent */', + 'expected' => [ + 'length' => 8, + 'content' => ' END', + 'orig_content' => ' END', + ], + ], + [ + 'testMarker' => '/* testNowdocCloserTabIndent */', + 'expected' => [ + 'length' => 7, + 'content' => ' END', + 'orig_content' => ' END', + ], + ], + ]; + + }//end dataHeredocNowdocCloserTabReplacement() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.inc new file mode 100644 index 00000000..ae43e24a --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.inc @@ -0,0 +1,193 @@ +bar +EOD; + +/* testProperty2 */ +$heredoc = <<<"EOD" +{$foo->bar} +EOD; + +/* testMethod1 */ +$heredoc = <<bar()} +EOD; + +/* testClosure1 */ +$heredoc = <<<"EOD" +{$foo()} +EOD; + +/* testChain1 */ +$heredoc = <<baz()()} +EOD; + +/* testVariableVar1 */ +$heredoc = <<<"EOD" +${$bar} +EOD; + +/* testVariableVar2 */ +$heredoc = <<bar} +EOD; + +/* testNested1 */ +$heredoc = <<{$baz}} +EOD; + +/* testNested4 */ +$heredoc = <<<"EOD" +${foo->{${'a'}}} +EOD; + +/* testNested5 */ +$heredoc = <<{"${'a'}"}} +EOD; + +/* testSimple1Wrapped */ +$heredoc = <<bar Something +EOD; + +/* testProperty2Wrapped */ +$heredoc = <<<"EOD" +Do {$foo->bar} Something +EOD; + +/* testMethod1Wrapped */ +$heredoc = <<bar()} Something +EOD; + +/* testClosure1Wrapped */ +$heredoc = <<<"EOD" +Do {$foo()} Something +EOD; + +/* testChain1Wrapped */ +$heredoc = <<baz()()} Something +EOD; + +/* testVariableVar1Wrapped */ +$heredoc = <<<"EOD" +Do ${$bar} Something +EOD; + +/* testVariableVar2Wrapped */ +$heredoc = <<bar} Something +EOD; + +/* testNested1Wrapped */ +$heredoc = <<{$baz}} Something +EOD; + +/* testNested4Wrapped */ +$heredoc = <<<"EOD" +Do ${foo->{${'a'}}} Something +EOD; + +/* testNested5Wrapped */ +$heredoc = <<{"${'a'}"}} Something +EOD; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.php new file mode 100644 index 00000000..2c808be9 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/HeredocStringTest.php @@ -0,0 +1,153 @@ + + * @copyright 2022 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class HeredocStringTest extends AbstractMethodUnitTest +{ + + + /** + * Test that heredoc strings contain the complete interpolated string. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expectedContent The expected content of the heredoc string. + * + * @dataProvider dataHeredocString + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testHeredocString($testMarker, $expectedContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $target = $this->getTargetToken($testMarker, T_HEREDOC); + $this->assertSame($expectedContent."\n", $tokens[$target]['content']); + + }//end testHeredocString() + + + /** + * Test that heredoc strings contain the complete interpolated string when combined with other texts. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * @param string $expectedContent The expected content of the heredoc string. + * + * @dataProvider dataHeredocString + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testHeredocStringWrapped($testMarker, $expectedContent) + { + $tokens = self::$phpcsFile->getTokens(); + + $testMarker = substr($testMarker, 0, -3).'Wrapped */'; + $target = $this->getTargetToken($testMarker, T_HEREDOC); + $this->assertSame('Do '.$expectedContent." Something\n", $tokens[$target]['content']); + + }//end testHeredocStringWrapped() + + + /** + * Data provider. + * + * @see testHeredocString() + * + * @return array + */ + public function dataHeredocString() + { + return [ + [ + 'testMarker' => '/* testSimple1 */', + 'expectedContent' => '$foo', + ], + [ + 'testMarker' => '/* testSimple2 */', + 'expectedContent' => '{$foo}', + ], + [ + 'testMarker' => '/* testSimple3 */', + 'expectedContent' => '${foo}', + ], + [ + 'testMarker' => '/* testDIM1 */', + 'expectedContent' => '$foo[bar]', + ], + [ + 'testMarker' => '/* testDIM2 */', + 'expectedContent' => '{$foo[\'bar\']}', + ], + [ + 'testMarker' => '/* testDIM3 */', + 'expectedContent' => '${foo[\'bar\']}', + ], + [ + 'testMarker' => '/* testProperty1 */', + 'expectedContent' => '$foo->bar', + ], + [ + 'testMarker' => '/* testProperty2 */', + 'expectedContent' => '{$foo->bar}', + ], + [ + 'testMarker' => '/* testMethod1 */', + 'expectedContent' => '{$foo->bar()}', + ], + [ + 'testMarker' => '/* testClosure1 */', + 'expectedContent' => '{$foo()}', + ], + [ + 'testMarker' => '/* testChain1 */', + 'expectedContent' => '{$foo[\'bar\']->baz()()}', + ], + [ + 'testMarker' => '/* testVariableVar1 */', + 'expectedContent' => '${$bar}', + ], + [ + 'testMarker' => '/* testVariableVar2 */', + 'expectedContent' => '${(foo)}', + ], + [ + 'testMarker' => '/* testVariableVar3 */', + 'expectedContent' => '${foo->bar}', + ], + [ + 'testMarker' => '/* testNested1 */', + 'expectedContent' => '${foo["${bar}"]}', + ], + [ + 'testMarker' => '/* testNested2 */', + 'expectedContent' => '${foo["${bar[\'baz\']}"]}', + ], + [ + 'testMarker' => '/* testNested3 */', + 'expectedContent' => '${foo->{$baz}}', + ], + [ + 'testMarker' => '/* testNested4 */', + 'expectedContent' => '${foo->{${\'a\'}}}', + ], + [ + 'testMarker' => '/* testNested5 */', + 'expectedContent' => '${foo->{"${\'a\'}"}}', + ], + ]; + + }//end dataHeredocString() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc index d05d27d9..b9c0df24 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.inc @@ -208,6 +208,9 @@ foobar(elseif: $value, /* testReservedKeywordElseif2 */ elseif: $value); /* testReservedKeywordEmpty1 */ foobar(empty: $value, /* testReservedKeywordEmpty2 */ empty: $value); +/* testReservedKeywordEnum1 */ +foobar(enum: $value, /* testReservedKeywordEnum2 */ enum: $value); + /* testReservedKeywordEnddeclare1 */ foobar(enddeclare: $value, /* testReservedKeywordEnddeclare2 */ enddeclare: $value); @@ -310,6 +313,9 @@ foobar(protected: $value, /* testReservedKeywordProtected2 */ protected: $value) /* testReservedKeywordPublic1 */ foobar(public: $value, /* testReservedKeywordPublic2 */ public: $value); +/* testReservedKeywordReadonly1 */ +foobar(readonly: $value, /* testReservedKeywordReadonly2 */ readonly: $value); + /* testReservedKeywordRequire1 */ foobar(require: $value, /* testReservedKeywordRequire2 */ require: $value); @@ -396,3 +402,6 @@ foobar(parent: $value, /* testReservedKeywordParent2 */ parent: $value); /* testReservedKeywordSelf1 */ foobar(self: $value, /* testReservedKeywordSelf2 */ self: $value); + +/* testReservedKeywordNever1 */ +foobar(never: $value, /* testReservedKeywordNever2 */ never: $value); diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php index 13be10e5..cc57637c 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php @@ -38,7 +38,7 @@ public function testNamedFunctionCallArguments($testMarker, $parameters) $this->assertSame( T_PARAM_NAME, $tokens[$label]['code'], - 'Token tokenized as '.$tokens[$label]['code'].', not T_PARAM_NAME (code)' + 'Token tokenized as '.$tokens[$label]['type'].', not T_PARAM_NAME (code)' ); $this->assertSame( 'T_PARAM_NAME', @@ -278,7 +278,7 @@ public function testOtherTstringInFunctionCall($testMarker, $content) $this->assertSame( T_STRING, $tokens[$label]['code'], - 'Token tokenized as '.$tokens[$label]['code'].', not T_STRING (code)' + 'Token tokenized as '.$tokens[$label]['type'].', not T_STRING (code)' ); $this->assertSame( 'T_STRING', @@ -709,7 +709,7 @@ public function testReservedKeywordsAsName($testMarker, $tokenTypes, $tokenConte $this->assertSame( T_PARAM_NAME, $tokens[$label]['code'], - 'Token tokenized as '.$tokens[$label]['code'].', not T_PARAM_NAME (code)' + 'Token tokenized as '.$tokens[$label]['type'].', not T_PARAM_NAME (code)' ); $this->assertSame( 'T_PARAM_NAME', @@ -776,6 +776,7 @@ public function dataReservedKeywordsAsName() 'endif', 'endswitch', 'endwhile', + 'enum', 'eval', 'exit', 'extends', @@ -804,6 +805,7 @@ public function dataReservedKeywordsAsName() 'private', 'protected', 'public', + 'readonly', 'require', 'require_once', 'return', @@ -831,6 +833,7 @@ public function dataReservedKeywordsAsName() 'resource', 'mixed', 'numeric', + 'never', // Not reserved keyword, but do have their own token in PHPCS. 'parent', diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ScopeSettingWithNamespaceOperatorTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ScopeSettingWithNamespaceOperatorTest.inc index e2d61bb6..38e5a47d 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ScopeSettingWithNamespaceOperatorTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ScopeSettingWithNamespaceOperatorTest.inc @@ -13,7 +13,7 @@ interface FooBar extends namespace\BarFoo {} function foo() : namespace\Baz {} /* testClosureReturnType */ -$closure = function () : namespace\Baz {} +$closure = function () : namespace\Baz {}; /* testArrowFunctionReturnType */ $fn = fn() : namespace\Baz => new namespace\Baz; diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.inc index 54065f21..60b23a51 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.inc @@ -92,6 +92,20 @@ echo [1, 2, 3][0]; /* testArrayWithinFunctionCall */ $var = functionCall([$x, $y]); +if ( true ) { + /* testShortListDeclarationAfterBracedControlStructure */ + [ $a ] = [ 'hi' ]; +} + +if ( true ) + /* testShortListDeclarationAfterNonBracedControlStructure */ + [ $a ] = [ 'hi' ]; + +if ( true ) : + /* testShortListDeclarationAfterAlternativeControlStructure */ + [ $a ] = [ 'hi' ]; +endif; + /* testLiveCoding */ // Intentional parse error. This has to be the last test in the file. $array = [ diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.php index 0484d4fc..1d97894f 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.php +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ShortArrayTest.php @@ -52,29 +52,29 @@ public function testSquareBrackets($testMarker) public function dataSquareBrackets() { return [ - ['/* testArrayAccess1 */'], - ['/* testArrayAccess2 */'], - ['/* testArrayAssignment */'], - ['/* testFunctionCallDereferencing */'], - ['/* testMethodCallDereferencing */'], - ['/* testStaticMethodCallDereferencing */'], - ['/* testPropertyDereferencing */'], - ['/* testPropertyDereferencingWithInaccessibleName */'], - ['/* testStaticPropertyDereferencing */'], - ['/* testStringDereferencing */'], - ['/* testStringDereferencingDoubleQuoted */'], - ['/* testConstantDereferencing */'], - ['/* testClassConstantDereferencing */'], - ['/* testMagicConstantDereferencing */'], - ['/* testArrayAccessCurlyBraces */'], - ['/* testArrayLiteralDereferencing */'], - ['/* testShortArrayLiteralDereferencing */'], - ['/* testClassMemberDereferencingOnInstantiation1 */'], - ['/* testClassMemberDereferencingOnInstantiation2 */'], - ['/* testClassMemberDereferencingOnClone */'], - ['/* testNullsafeMethodCallDereferencing */'], - ['/* testInterpolatedStringDereferencing */'], - ['/* testLiveCoding */'], + 'array access 1' => ['/* testArrayAccess1 */'], + 'array access 2' => ['/* testArrayAccess2 */'], + 'array assignment' => ['/* testArrayAssignment */'], + 'function call dereferencing' => ['/* testFunctionCallDereferencing */'], + 'method call dereferencing' => ['/* testMethodCallDereferencing */'], + 'static method call dereferencing' => ['/* testStaticMethodCallDereferencing */'], + 'property dereferencing' => ['/* testPropertyDereferencing */'], + 'property dereferencing with inaccessable name' => ['/* testPropertyDereferencingWithInaccessibleName */'], + 'static property dereferencing' => ['/* testStaticPropertyDereferencing */'], + 'string dereferencing single quotes' => ['/* testStringDereferencing */'], + 'string dereferencing double quotes' => ['/* testStringDereferencingDoubleQuoted */'], + 'global constant dereferencing' => ['/* testConstantDereferencing */'], + 'class constant dereferencing' => ['/* testClassConstantDereferencing */'], + 'magic constant dereferencing' => ['/* testMagicConstantDereferencing */'], + 'array access with curly braces' => ['/* testArrayAccessCurlyBraces */'], + 'array literal dereferencing' => ['/* testArrayLiteralDereferencing */'], + 'short array literal dereferencing' => ['/* testShortArrayLiteralDereferencing */'], + 'class member dereferencing on instantiation 1' => ['/* testClassMemberDereferencingOnInstantiation1 */'], + 'class member dereferencing on instantiation 2' => ['/* testClassMemberDereferencingOnInstantiation2 */'], + 'class member dereferencing on clone' => ['/* testClassMemberDereferencingOnClone */'], + 'nullsafe method call dereferencing' => ['/* testNullsafeMethodCallDereferencing */'], + 'interpolated string dereferencing' => ['/* testInterpolatedStringDereferencing */'], + 'live coding' => ['/* testLiveCoding */'], ]; }//end dataSquareBrackets() @@ -117,13 +117,16 @@ public function testShortArrays($testMarker) public function dataShortArrays() { return [ - ['/* testShortArrayDeclarationEmpty */'], - ['/* testShortArrayDeclarationWithOneValue */'], - ['/* testShortArrayDeclarationWithMultipleValues */'], - ['/* testShortArrayDeclarationWithDereferencing */'], - ['/* testShortListDeclaration */'], - ['/* testNestedListDeclaration */'], - ['/* testArrayWithinFunctionCall */'], + 'short array empty' => ['/* testShortArrayDeclarationEmpty */'], + 'short array with value' => ['/* testShortArrayDeclarationWithOneValue */'], + 'short array with values' => ['/* testShortArrayDeclarationWithMultipleValues */'], + 'short array with dereferencing' => ['/* testShortArrayDeclarationWithDereferencing */'], + 'short list' => ['/* testShortListDeclaration */'], + 'short list nested' => ['/* testNestedListDeclaration */'], + 'short array within function call' => ['/* testArrayWithinFunctionCall */'], + 'short list after braced control structure' => ['/* testShortListDeclarationAfterBracedControlStructure */'], + 'short list after non-braced control structure' => ['/* testShortListDeclarationAfterNonBracedControlStructure */'], + 'short list after alternative control structure' => ['/* testShortListDeclarationAfterAlternativeControlStructure */'], ]; }//end dataShortArrays() diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/StableCommentWhitespaceWinTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/StableCommentWhitespaceWinTest.inc index dc98eb01..6ca7026d 100644 --- a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/StableCommentWhitespaceWinTest.inc +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/StableCommentWhitespaceWinTest.inc @@ -1,63 +1,63 @@ - - - + + - * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - */ - -namespace PHP_CodeSniffer\Tests\Core\Tokenizer; - -use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; -use PHP_CodeSniffer\Util\Tokens; - -class StableCommentWhitespaceWinTest extends AbstractMethodUnitTest -{ - - - /** - * Test that comment tokenization with new lines at the end of the comment is stable. - * - * @param string $testMarker The comment prefacing the test. - * @param array $expectedTokens The tokenization expected. - * - * @dataProvider dataCommentTokenization - * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize - * - * @return void - */ - public function testCommentTokenization($testMarker, $expectedTokens) - { - $tokens = self::$phpcsFile->getTokens(); - $comment = $this->getTargetToken($testMarker, Tokens::$commentTokens); - - foreach ($expectedTokens as $key => $tokenInfo) { - $this->assertSame(constant($tokenInfo['type']), $tokens[$comment]['code']); - $this->assertSame($tokenInfo['type'], $tokens[$comment]['type']); - $this->assertSame($tokenInfo['content'], $tokens[$comment]['content']); - - ++$comment; - } - - }//end testCommentTokenization() - - - /** - * Data provider. - * - * @see testCommentTokenization() - * - * @return array - */ - public function dataCommentTokenization() - { - return [ - [ - '/* testSingleLineSlashComment */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testSingleLineSlashCommentTrailing */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testSingleLineSlashAnnotation */', - [ - [ - 'type' => 'T_PHPCS_DISABLE', - 'content' => '// phpcs:disable Stnd.Cat -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineSlashComment */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment1 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment2 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineSlashCommentWithIndent */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment1 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' ', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment2 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' ', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineSlashCommentWithAnnotationStart */', - [ - [ - 'type' => 'T_PHPCS_IGNORE', - 'content' => '// phpcs:ignore Stnd.Cat -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment2 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineSlashCommentWithAnnotationMiddle */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment1 -', - ], - [ - 'type' => 'T_PHPCS_IGNORE', - 'content' => '// @phpcs:ignore Stnd.Cat -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineSlashCommentWithAnnotationEnd */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment1 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '// Comment2 -', - ], - [ - 'type' => 'T_PHPCS_IGNORE', - 'content' => '// phpcs:ignore Stnd.Cat -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testSingleLineSlashCommentNoNewLineAtEnd */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '// Slash ', - ], - [ - 'type' => 'T_CLOSE_TAG', - 'content' => '?> -', - ], - ], - ], - [ - '/* testSingleLineHashComment */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testSingleLineHashCommentTrailing */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineHashComment */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment1 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment2 -', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testMultiLineHashCommentWithIndent */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment1 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' ', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment2 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' ', - ], - [ - 'type' => 'T_COMMENT', - 'content' => '# Comment3 -', - ], - [ - 'type' => 'T_WHITESPACE', - 'content' => ' -', - ], - ], - ], - [ - '/* testSingleLineHashCommentNoNewLineAtEnd */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '# Hash ', - ], - [ - 'type' => 'T_CLOSE_TAG', - 'content' => '?> -', - ], - ], - ], - [ - '/* testCommentAtEndOfFile */', - [ - [ - 'type' => 'T_COMMENT', - 'content' => '/* Comment', - ], - ], - ], - ]; - - }//end dataCommentTokenization() - - -}//end class + + * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; +use PHP_CodeSniffer\Util\Tokens; + +class StableCommentWhitespaceWinTest extends AbstractMethodUnitTest +{ + + + /** + * Test that comment tokenization with new lines at the end of the comment is stable. + * + * @param string $testMarker The comment prefacing the test. + * @param array $expectedTokens The tokenization expected. + * + * @dataProvider dataCommentTokenization + * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize + * + * @return void + */ + public function testCommentTokenization($testMarker, $expectedTokens) + { + $tokens = self::$phpcsFile->getTokens(); + $comment = $this->getTargetToken($testMarker, Tokens::$commentTokens); + + foreach ($expectedTokens as $key => $tokenInfo) { + $this->assertSame(constant($tokenInfo['type']), $tokens[$comment]['code']); + $this->assertSame($tokenInfo['type'], $tokens[$comment]['type']); + $this->assertSame($tokenInfo['content'], $tokens[$comment]['content']); + + ++$comment; + } + + }//end testCommentTokenization() + + + /** + * Data provider. + * + * @see testCommentTokenization() + * + * @return array + */ + public function dataCommentTokenization() + { + return [ + [ + '/* testSingleLineSlashComment */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testSingleLineSlashCommentTrailing */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testSingleLineSlashAnnotation */', + [ + [ + 'type' => 'T_PHPCS_DISABLE', + 'content' => '// phpcs:disable Stnd.Cat +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineSlashComment */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment1 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment2 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineSlashCommentWithIndent */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment1 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' ', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment2 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' ', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineSlashCommentWithAnnotationStart */', + [ + [ + 'type' => 'T_PHPCS_IGNORE', + 'content' => '// phpcs:ignore Stnd.Cat +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment2 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineSlashCommentWithAnnotationMiddle */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment1 +', + ], + [ + 'type' => 'T_PHPCS_IGNORE', + 'content' => '// @phpcs:ignore Stnd.Cat +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineSlashCommentWithAnnotationEnd */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment1 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '// Comment2 +', + ], + [ + 'type' => 'T_PHPCS_IGNORE', + 'content' => '// phpcs:ignore Stnd.Cat +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testSingleLineSlashCommentNoNewLineAtEnd */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '// Slash ', + ], + [ + 'type' => 'T_CLOSE_TAG', + 'content' => '?> +', + ], + ], + ], + [ + '/* testSingleLineHashComment */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testSingleLineHashCommentTrailing */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineHashComment */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment1 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment2 +', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testMultiLineHashCommentWithIndent */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment1 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' ', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment2 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' ', + ], + [ + 'type' => 'T_COMMENT', + 'content' => '# Comment3 +', + ], + [ + 'type' => 'T_WHITESPACE', + 'content' => ' +', + ], + ], + ], + [ + '/* testSingleLineHashCommentNoNewLineAtEnd */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '# Hash ', + ], + [ + 'type' => 'T_CLOSE_TAG', + 'content' => '?> +', + ], + ], + ], + [ + '/* testCommentAtEndOfFile */', + [ + [ + 'type' => 'T_COMMENT', + 'content' => '/* Comment', + ], + ], + ], + ]; + + }//end dataCommentTokenization() + + +}//end class diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.inc b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.inc new file mode 100644 index 00000000..abf9b85b --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.inc @@ -0,0 +1,120 @@ + $param & $int; + +/* testTypeIntersectionArrowReturnType */ +$arrowWithReturnType = fn ($param) : Foo&Bar => $param * 10; + +/* testBitwiseAndInArrayKey */ +$array = array( + A & B => /* testBitwiseAndInArrayValue */ B & C +); + +/* testBitwiseAndInShortArrayKey */ +$array = [ + A & B => /* testBitwiseAndInShortArrayValue */ B & C +]; + +/* testBitwiseAndNonArrowFnFunctionCall */ +$obj->fn($something & $else); + +/* testBitwiseAnd6 */ +function &fn(/* testTypeIntersectionNonArrowFunctionDeclaration */ Foo&Bar $something) {} + +/* testTypeIntersectionWithInvalidTypes */ +function (int&string $var) {}; + +/* testLiveCoding */ +// Intentional parse error. This has to be the last test in the file. +return function( Foo& diff --git a/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.php b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.php new file mode 100644 index 00000000..21700219 --- /dev/null +++ b/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/TypeIntersectionTest.php @@ -0,0 +1,138 @@ + + * @author Jaroslav Hanslík + * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; + +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; + +class TypeIntersectionTest extends AbstractMethodUnitTest +{ + + + /** + * Test that non-intersection type bitwise and tokens are still tokenized as bitwise and. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataBitwiseAnd + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testBitwiseAnd($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $opener = $this->getTargetToken($testMarker, [T_BITWISE_AND, T_TYPE_INTERSECTION]); + $this->assertSame(T_BITWISE_AND, $tokens[$opener]['code']); + $this->assertSame('T_BITWISE_AND', $tokens[$opener]['type']); + + }//end testBitwiseAnd() + + + /** + * Data provider. + * + * @see testBitwiseAnd() + * + * @return array + */ + public function dataBitwiseAnd() + { + return [ + ['/* testBitwiseAnd1 */'], + ['/* testBitwiseAnd2 */'], + ['/* testBitwiseAndPropertyDefaultValue */'], + ['/* testBitwiseAndParamDefaultValue */'], + ['/* testBitwiseAnd3 */'], + ['/* testBitwiseAnd4 */'], + ['/* testBitwiseAnd5 */'], + ['/* testBitwiseAndClosureParamDefault */'], + ['/* testBitwiseAndArrowParamDefault */'], + ['/* testBitwiseAndArrowExpression */'], + ['/* testBitwiseAndInArrayKey */'], + ['/* testBitwiseAndInArrayValue */'], + ['/* testBitwiseAndInShortArrayKey */'], + ['/* testBitwiseAndInShortArrayValue */'], + ['/* testBitwiseAndNonArrowFnFunctionCall */'], + ['/* testBitwiseAnd6 */'], + ['/* testLiveCoding */'], + ]; + + }//end dataBitwiseAnd() + + + /** + * Test that bitwise and tokens when used as part of a intersection type are tokenized as `T_TYPE_INTERSECTION`. + * + * @param string $testMarker The comment which prefaces the target token in the test file. + * + * @dataProvider dataTypeIntersection + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testTypeIntersection($testMarker) + { + $tokens = self::$phpcsFile->getTokens(); + + $opener = $this->getTargetToken($testMarker, [T_BITWISE_AND, T_TYPE_INTERSECTION]); + $this->assertSame(T_TYPE_INTERSECTION, $tokens[$opener]['code']); + $this->assertSame('T_TYPE_INTERSECTION', $tokens[$opener]['type']); + + }//end testTypeIntersection() + + + /** + * Data provider. + * + * @see testTypeIntersection() + * + * @return array + */ + public function dataTypeIntersection() + { + return [ + ['/* testTypeIntersectionPropertySimple */'], + ['/* testTypeIntersectionPropertyReverseModifierOrder */'], + ['/* testTypeIntersectionPropertyMulti1 */'], + ['/* testTypeIntersectionPropertyMulti2 */'], + ['/* testTypeIntersectionPropertyMulti3 */'], + ['/* testTypeIntersectionPropertyNamespaceRelative */'], + ['/* testTypeIntersectionPropertyPartiallyQualified */'], + ['/* testTypeIntersectionPropertyFullyQualified */'], + ['/* testTypeIntersectionPropertyWithReadOnlyKeyword */'], + ['/* testTypeIntersectionParam1 */'], + ['/* testTypeIntersectionParam2 */'], + ['/* testTypeIntersectionParam3 */'], + ['/* testTypeIntersectionParamNamespaceRelative */'], + ['/* testTypeIntersectionParamPartiallyQualified */'], + ['/* testTypeIntersectionParamFullyQualified */'], + ['/* testTypeIntersectionReturnType */'], + ['/* testTypeIntersectionConstructorPropertyPromotion */'], + ['/* testTypeIntersectionAbstractMethodReturnType1 */'], + ['/* testTypeIntersectionAbstractMethodReturnType2 */'], + ['/* testTypeIntersectionReturnTypeNamespaceRelative */'], + ['/* testTypeIntersectionReturnPartiallyQualified */'], + ['/* testTypeIntersectionReturnFullyQualified */'], + ['/* testTypeIntersectionClosureParamIllegalNullable */'], + ['/* testTypeIntersectionWithReference */'], + ['/* testTypeIntersectionWithSpreadOperator */'], + ['/* testTypeIntersectionClosureReturn */'], + ['/* testTypeIntersectionArrowParam */'], + ['/* testTypeIntersectionArrowReturnType */'], + ['/* testTypeIntersectionNonArrowFunctionDeclaration */'], + ['/* testTypeIntersectionWithInvalidTypes */'], + ]; + + }//end dataTypeIntersection() + + +}//end class