Skip to content

Commit

Permalink
Merge pull request #14 from sspat/new-words
Browse files Browse the repository at this point in the history
Updated reserved words for php 8.0
  • Loading branch information
sspat authored Dec 26, 2020
2 parents fb4e689 + b56d530 commit 62d8dff
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 88 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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');
```
10 changes: 9 additions & 1 deletion src/ReservedWords.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit 62d8dff

Please sign in to comment.