From b56d530e7a2603e3cb6595cb237c67df3f4ffc55 Mon Sep 17 00:00:00 2001 From: Patrik Foldes Date: Sat, 26 Dec 2020 19:31:48 +0300 Subject: [PATCH] Updated reserved words for php 8.0 --- CHANGELOG.md | 15 ++ README.md | 13 +- src/ReservedWords.php | 10 +- src/ReservedWordsList.php | 264 ++++++++++++++++++++++---------- tests/ReservedWordsListTest.php | 7 +- tests/ReservedWordsTest.php | 26 ++++ 6 files changed, 247 insertions(+), 88 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..48af0af --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +### 2.0.0 (26.12.2020) + +* Added support for PHP 8.0 +* BC Break: Dropped support of PHP 7.2 +* BC Break: Added new keyword reserved in php 8 - `match` +* BC Break: Updated `mixed` keyword to reflect changes in php 8 +* BC Break: Updated all keywords except `namespace` and `__halt_compiler` + to reflect that they can be used as namespace parts since php 8.0 +* BC Break: Added new method `isReservedClassName` to check for reserved words in + class/trait/interface names. The method `isReservedNamespaceName` should + be now used only for checking for reserved words in namespaces. + These changes are necessary because php 8 changed the reserved words behavior for namespaces. +* Migrated CI to GitHub actions +* Added mutation testing +* Added phpstan static analysis diff --git a/README.md b/README.md index 804d33d..d9ca8b0 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,17 @@ $isReserved = $reservedWords->isReserved($word); */ $cannotUseAsConstantName = $reservedWords->isReservedConstantName($word); /** - * Checks that the word cannot be used as a namespace part or class/interface/trait name in your current php version. + * Checks that the word cannot be used as a namespace part in your current php version. + * + * This is used for checking parts of namespaces, not full namespace strings. + * E.g. calling this with `Some\Namespace\String` is incorrect, you should make three separate calls + * with `Some`, `Namespace` and `String`. */ $cannotUseAsNamespaceName = $reservedWords->isReservedNamespaceName($word); +/** + * Checks that the word cannot be used as a class/interface/trait name in your current php version. + */ +$cannotUseAsNamespaceName = $reservedWords->isReservedClassName($word); /** * Checks that the word cannot be used as a function name in your current php version. */ @@ -66,6 +74,7 @@ $cannotUseAsMethodName = $reservedWords->isReservedMethodName($word); */ $cannotUseAsConstantName = $reservedWords->isReservedConstantName($word, '5.6'); $cannotUseAsNamespaceName = $reservedWords->isReservedNamespaceName($word, '5.6.1'); -$cannotUseAsFunctionName = $reservedWords->isReservedFunctionName($word, '7.0'); +$cannotUseAsNamespaceName = $reservedWords->isReservedClassName($word, '5.6.1'); +$cannotUseAsFunctionName = $reservedWords->isReservedFunctionName($word, '8.0'); $cannotUseAsMethodName = $reservedWords->isReservedMethodName($word, '7.4.2'); ``` diff --git a/src/ReservedWords.php b/src/ReservedWords.php index 7b88a5f..9ef5071 100644 --- a/src/ReservedWords.php +++ b/src/ReservedWords.php @@ -51,13 +51,21 @@ public function isReservedConstantName(string $string, ?string $phpVersion = nul } /** - * Checks that the word cannot be used as a namespace part or class/interface/trait name + * Checks that the word cannot be used as a namespace part */ public function isReservedNamespaceName(string $string, ?string $phpVersion = null): bool { return $this->isReservedAs($string, 'namespace', $phpVersion); } + /** + * Checks that the word cannot be used as a class/interface/trait name + */ + public function isReservedClassName(string $string, ?string $phpVersion = null): bool + { + return $this->isReservedAs($string, 'class', $phpVersion); + } + /** * Checks that the word cannot be used as a function name */ diff --git a/src/ReservedWordsList.php b/src/ReservedWordsList.php index 147c804..534440d 100644 --- a/src/ReservedWordsList.php +++ b/src/ReservedWordsList.php @@ -11,7 +11,8 @@ final class ReservedWordsList * * The nested array keys have the following meaning: * "constant" - whether the reserved word can be used as a constant name - * "namespace" - whether the reserved word can be used as part of a namespace, class, interface or trait name. + * "namespace" - whether the reserved word can be used as part of a namespace + * "class" - whether the reserved word can be used as a class, interface or trait name * "function" - whether the reserved word can be used as a function name * "method" - whether the reserved word can be used as a method name * @@ -24,528 +25,623 @@ final class ReservedWordsList '__halt_compiler' => [ 'constant' => ['5.1', '7.0'], 'namespace' => '5.1', + 'class' => '5.1', 'function' => '5.1', 'method' => ['5.1', '7.0'], ], 'abstract' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'and' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'array' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'as' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'break' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'callable' => [ 'constant' => ['5.4', '7.0'], - 'namespace' => '5.4', + 'namespace' => ['5.4', '8.0'], + 'class' => '5.4', 'function' => '5.4', 'method' => ['5.4', '7.0'], ], 'case' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'catch' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'class' => [ 'constant' => '4.0', - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'clone' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'const' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'continue' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'declare' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'default' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'die' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'do' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'echo' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'else' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'elseif' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'empty' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'enddeclare' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'endfor' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'endforeach' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'endif' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'endswitch' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'endwhile' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'eval' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'exit' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'extends' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'final' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'finally' => [ 'constant' => ['5.5', '7.0'], - 'namespace' => '5.5', + 'namespace' => ['5.5', '8.0'], + 'class' => '5.5', 'function' => '5.5', 'method' => ['5.5', '7.0'], ], 'for' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'foreach' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'function' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'global' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'goto' => [ 'constant' => ['5.3', '7.0'], - 'namespace' => '5.3', + 'namespace' => ['5.3', '8.0'], + 'class' => '5.3', 'function' => '5.3', 'method' => ['5.3', '7.0'], ], 'if' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'implements' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'include' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'include_once' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'instanceof' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'insteadof' => [ 'constant' => ['5.4', '7.0'], - 'namespace' => '5.4', + 'namespace' => ['5.4', '8.0'], + 'class' => '5.4', 'function' => '5.4', 'method' => ['5.4', '7.0'], ], 'interface' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'isset' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'list' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], + 'match' => [ + 'constant' => false, + 'namespace' => false, + 'class' => '8.0', + 'function' => '8.0', + 'method' => false, + ], 'namespace' => [ 'constant' => ['5.3', '7.0'], 'namespace' => '5.3', + 'class' => '5.3', 'function' => '5.3', 'method' => ['5.3', '7.0'], ], 'new' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'or' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'print' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'private' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'protected' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'public' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'require' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'require_once' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'return' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'static' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'switch' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'throw' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'trait' => [ 'constant' => ['5.4', '7.0'], - 'namespace' => '5.4', + 'namespace' => ['5.4', '8.0'], + 'class' => '5.4', 'function' => '5.4', 'method' => ['5.4', '7.0'], ], 'try' => [ 'constant' => ['5.0', '7.0'], - 'namespace' => '5.0', + 'namespace' => ['5.0', '8.0'], + 'class' => '5.0', 'function' => '5.0', 'method' => ['5.0', '7.0'], ], 'unset' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'use' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'var' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'while' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'xor' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], 'yield' => [ 'constant' => ['5.5', '7.0'], - 'namespace' => '5.5', + 'namespace' => ['5.5', '8.0'], + 'class' => '5.5', 'function' => '5.5', 'method' => ['5.5', '7.0'], ], '__class__' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], '__dir__' => [ 'constant' => ['5.3', '7.0'], - 'namespace' => '5.3', + 'namespace' => ['5.3', '8.0'], + 'class' => '5.3', 'function' => '5.3', 'method' => ['5.3', '7.0'], ], '__file__' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], '__function__' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], '__line__' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], '__method__' => [ 'constant' => ['4.0', '7.0'], - 'namespace' => '4.0', + 'namespace' => ['4.0', '8.0'], + 'class' => '4.0', 'function' => '4.0', 'method' => ['4.0', '7.0'], ], '__namespace__' => [ 'constant' => ['5.3', '7.0'], - 'namespace' => '5.3', + 'namespace' => ['5.3', '8.0'], + 'class' => '5.3', 'function' => '5.3', 'method' => ['5.3', '7.0'], ], '__trait__' => [ 'constant' => ['5.4', '7.0'], - 'namespace' => '5.4', + 'namespace' => ['5.4', '8.0'], + 'class' => '5.4', 'function' => '5.4', 'method' => ['5.4', '7.0'], ], 'int' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'float' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'bool' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'string' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'true' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'false' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'null' => [ 'constant' => false, - 'namespace' => '7.0', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'void' => [ 'constant' => false, - 'namespace' => '7.1', + 'namespace' => ['7.0', '8.0'], + 'class' => '7.0', 'function' => false, 'method' => false, ], 'iterable' => [ 'constant' => false, - 'namespace' => '7.1', + 'namespace' => ['7.1', '8.0'], + 'class' => '7.1', 'function' => false, 'method' => false, ], 'object' => [ 'constant' => false, - 'namespace' => '7.2', + 'namespace' => ['7.2', '8.0'], + 'class' => '7.2', 'function' => false, 'method' => false, ], 'resource' => [ 'constant' => false, 'namespace' => false, + 'class' => false, 'function' => false, 'method' => false, ], 'mixed' => [ 'constant' => false, 'namespace' => false, + 'class' => '8.0', 'function' => false, 'method' => false, ], 'numeric' => [ 'constant' => false, 'namespace' => false, + 'class' => false, 'function' => false, 'method' => false, ], diff --git a/tests/ReservedWordsListTest.php b/tests/ReservedWordsListTest.php index 3dee361..c455465 100644 --- a/tests/ReservedWordsListTest.php +++ b/tests/ReservedWordsListTest.php @@ -28,9 +28,10 @@ public function testReservedWordsList(): void foreach (ReservedWordsList::PHP_RESERVED_WORDS as $reservedWord => $reservedWordConfig) { Assert::assertIsString($reservedWord); Assert::assertIsArray($reservedWordConfig); - Assert::assertCount(4, $reservedWordConfig); + Assert::assertCount(5, $reservedWordConfig); Assert::assertArrayHasKey('constant', $reservedWordConfig); Assert::assertArrayHasKey('namespace', $reservedWordConfig); + Assert::assertArrayHasKey('class', $reservedWordConfig); Assert::assertArrayHasKey('function', $reservedWordConfig); Assert::assertArrayHasKey('method', $reservedWordConfig); Assert::assertTrue( @@ -41,6 +42,10 @@ public function testReservedWordsList(): void $this->isValidConstraint($reservedWordConfig['namespace']), sprintf($errorMessage, $reservedWord) ); + Assert::assertTrue( + $this->isValidConstraint($reservedWordConfig['class']), + sprintf($errorMessage, $reservedWord) + ); Assert::assertTrue( $this->isValidConstraint($reservedWordConfig['function']), sprintf($errorMessage, $reservedWord) diff --git a/tests/ReservedWordsTest.php b/tests/ReservedWordsTest.php index 38be7fd..80bd400 100644 --- a/tests/ReservedWordsTest.php +++ b/tests/ReservedWordsTest.php @@ -87,6 +87,22 @@ public function testNamespaceName( Assert::assertEquals($isReserved, $reservedWords->isReservedNamespaceName($reservedWord, $phpVersion)); } + /** + * @param array> $reservedWordParameters + * + * @dataProvider reservedWordsList + */ + public function testClassName( + string $reservedWord, + array $reservedWordParameters, + string $phpVersion, + bool $isReserved + ): void { + $reservedWords = new ReservedWords([$reservedWord => $reservedWordParameters]); + + Assert::assertEquals($isReserved, $reservedWords->isReservedClassName($reservedWord, $phpVersion)); + } + /** * @param array> $reservedWordParameters * @@ -140,6 +156,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => false, 'namespace' => false, + 'class' => false, 'function' => false, 'method' => false, ], @@ -151,6 +168,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => '7.0', 'namespace' => '7.0', + 'class' => '7.0', 'function' => '7.0', 'method' => '7.0', ], @@ -162,6 +180,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => '7.0', 'namespace' => '7.0', + 'class' => '7.0', 'function' => '7.0', 'method' => '7.0', ], @@ -173,6 +192,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => '7.0', 'namespace' => '7.0', + 'class' => '7.0', 'function' => '7.0', 'method' => '7.0', ], @@ -184,6 +204,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => '7.0', 'namespace' => '7.0', + 'class' => '7.0', 'function' => '7.0', 'method' => '7.0', ], @@ -195,6 +216,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => ['5.0', '7.0'], 'namespace' => ['5.0', '7.0'], + 'class' => ['5.0', '7.0'], 'function' => ['5.0', '7.0'], 'method' => ['5.0', '7.0'], ], @@ -206,6 +228,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => ['5.0', '7.0'], 'namespace' => ['5.0', '7.0'], + 'class' => ['5.0', '7.0'], 'function' => ['5.0', '7.0'], 'method' => ['5.0', '7.0'], ], @@ -217,6 +240,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => ['5.0', '7.0'], 'namespace' => ['5.0', '7.0'], + 'class' => ['5.0', '7.0'], 'function' => ['5.0', '7.0'], 'method' => ['5.0', '7.0'], ], @@ -228,6 +252,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => ['5.0', '7.0'], 'namespace' => ['5.0', '7.0'], + 'class' => ['5.0', '7.0'], 'function' => ['5.0', '7.0'], 'method' => ['5.0', '7.0'], ], @@ -239,6 +264,7 @@ public function reservedWordsList(): array 'reservedWordParameters' => [ 'constant' => ['5.0', '7.0'], 'namespace' => ['5.0', '7.0'], + 'class' => ['5.0', '7.0'], 'function' => ['5.0', '7.0'], 'method' => ['5.0', '7.0'], ],