diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 71ab83c..d4cdbb6 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -80,12 +80,17 @@ jobs:
name: tools
path: tools
+ - name: Set tools as an executable
+ run: find tools -type f -print0 | xargs -0 chmod +x
+
- name: Run lint
+ env:
+ PSALM_SHEPHERD: 1
+ # TODO: Remove it when psalm no longer tries to create a cache directory
+ # https://github.com/vimeo/psalm/issues/4267
+ XDG_CACHE_HOME: /tmp
run: composer lint
- - name: Run bug analysis
- run: composer findbugs
-
- name: Run unit tests
env:
XDEBUG_MODE: coverage
diff --git a/.laradock/env-development b/.laradock/env-development
index accb120..77495cc 100644
--- a/.laradock/env-development
+++ b/.laradock/env-development
@@ -100,6 +100,7 @@ SHELL_OH_MY_ZSH_ALIASES=false
WORKSPACE_BASE_IMAGE_TAG_PREFIX=latest
WORKSPACE_COMPOSER_GLOBAL_INSTALL=true
+WORKSPACE_COMPOSER_VERSION=2
WORKSPACE_COMPOSER_AUTH=false
WORKSPACE_COMPOSER_REPO_PACKAGIST=
WORKSPACE_NVM_NODEJS_ORG_MIRROR=
@@ -122,6 +123,7 @@ WORKSPACE_INSTALL_WORKSPACE_SSH=false
WORKSPACE_INSTALL_SUBVERSION=false
WORKSPACE_INSTALL_BZ2=false
WORKSPACE_INSTALL_GMP=false
+WORKSPACE_INSTALL_GNUPG=false
WORKSPACE_INSTALL_XDEBUG=true
WORKSPACE_INSTALL_PCOV=false
WORKSPACE_INSTALL_PHPDBG=false
@@ -137,7 +139,7 @@ WORKSPACE_INSTALL_CASSANDRA=false
WORKSPACE_INSTALL_GEARMAN=false
WORKSPACE_INSTALL_MSSQL=false
WORKSPACE_INSTALL_DRUSH=false
-WORKSPACE_DRUSH_VERSION=8.1.17
+WORKSPACE_DRUSH_VERSION=8.4.6
WORKSPACE_INSTALL_DRUPAL_CONSOLE=false
WORKSPACE_INSTALL_WP_CLI=false
WORKSPACE_INSTALL_AEROSPIKE=false
@@ -146,7 +148,7 @@ WORKSPACE_INSTALL_V8JS=false
WORKSPACE_INSTALL_LARAVEL_ENVOY=false
WORKSPACE_INSTALL_LARAVEL_INSTALLER=false
WORKSPACE_INSTALL_DEPLOYER=false
-WORKSPACE_INSTALL_PRESTISSIMO=true
+WORKSPACE_INSTALL_PRESTISSIMO=false
WORKSPACE_INSTALL_LINUXBREW=false
WORKSPACE_INSTALL_MC=false
WORKSPACE_INSTALL_SYMFONY=false
@@ -156,6 +158,7 @@ WORKSPACE_INSTALL_POWERLINE=false
WORKSPACE_INSTALL_SUPERVISOR=false
WORKSPACE_INSTALL_IMAGE_OPTIMIZERS=false
WORKSPACE_INSTALL_IMAGEMAGICK=false
+WORKSPACE_IMAGEMAGICK_VERSION=latest
WORKSPACE_INSTALL_TERRAFORM=false
WORKSPACE_INSTALL_DUSK_DEPS=false
WORKSPACE_INSTALL_PG_CLIENT=false
@@ -164,7 +167,7 @@ WORKSPACE_INSTALL_SWOOLE=false
WORKSPACE_INSTALL_TAINT=false
WORKSPACE_INSTALL_LIBPNG=false
WORKSPACE_INSTALL_GRAPHVIZ=false
-WORKSPACE_INSTALL_IONCUBE=false
+WORKSPACE_INSTALL_IONCUBE=false # PHP 8.0 is not supported yet. Reference: https://forum.ioncube.com/viewtopic.php?t=4592
WORKSPACE_INSTALL_MYSQL_CLIENT=false
WORKSPACE_INSTALL_PING=false
WORKSPACE_INSTALL_SSHPASS=false
@@ -184,7 +187,7 @@ WORKSPACE_INSTALL_AUDIOWAVEFORM=false
WORKSPACE_INSTALL_WKHTMLTOPDF=false
WORKSPACE_INSTALL_GNU_PARALLEL=false
WORKSPACE_INSTALL_AST=true
-WORKSPACE_AST_VERSION=1.0.3
+WORKSPACE_AST_VERSION=1.0.10
WORKSPACE_BROWSERSYNC_HOST_PORT=3000
WORKSPACE_BROWSERSYNC_UI_HOST_PORT=3001
WORKSPACE_VUE_CLI_SERVE_HOST_PORT=8080
@@ -194,6 +197,7 @@ WORKSPACE_INSTALL_GIT_PROMPT=false
WORKSPACE_INSTALL_DOCKER_CLIENT=false
WORKSPACE_INSTALL_LNAV=false
WORKSPACE_INSTALL_PROTOC=false
+WORKSPACE_INSTALL_PHPDECIMAL=false
WORKSPACE_PROTOC_VERSION=latest
### PHP_FPM ###############################################
@@ -203,12 +207,14 @@ PHP_FPM_INSTALL_BCMATH=true
PHP_FPM_INSTALL_MYSQLI=true
PHP_FPM_INSTALL_INTL=true
PHP_FPM_INSTALL_IMAGEMAGICK=true
+PHP_FPM_IMAGEMAGICK_VERSION=latest
PHP_FPM_INSTALL_OPCACHE=true
PHP_FPM_INSTALL_IMAGE_OPTIMIZERS=true
PHP_FPM_INSTALL_PHPREDIS=true
PHP_FPM_INSTALL_MEMCACHED=false
PHP_FPM_INSTALL_BZ2=false
PHP_FPM_INSTALL_GMP=false
+PHP_FPM_INSTALL_GNUPG=false
PHP_FPM_INSTALL_XDEBUG=false
PHP_FPM_INSTALL_PCOV=false
PHP_FPM_INSTALL_XHPROF=false
@@ -237,7 +243,7 @@ PHP_FPM_INSTALL_POSTGIS=false
PHP_FPM_INSTALL_PCNTL=false
PHP_FPM_INSTALL_CALENDAR=false
PHP_FPM_INSTALL_FAKETIME=false
-PHP_FPM_INSTALL_IONCUBE=false
+PHP_FPM_INSTALL_IONCUBE=false # PHP 8.0 is not supported yet. Reference: https://forum.ioncube.com/viewtopic.php?t=4592
PHP_FPM_INSTALL_RDKAFKA=false
PHP_FPM_INSTALL_GETTEXT=false
PHP_FPM_INSTALL_XMLRPC=false
@@ -251,11 +257,13 @@ PHP_FPM_INSTALL_PING=false
PHP_FPM_INSTALL_SSHPASS=false
PHP_FPM_INSTALL_MAILPARSE=false
PHP_FPM_INSTALL_WKHTMLTOPDF=false
+PHP_FPM_INSTALL_PHPDECIMAL=false
PHP_FPM_FFMPEG=false
PHP_FPM_AUDIOWAVEFORM=false
PHP_FPM_ADDITIONAL_LOCALES="en_US.UTF-8 es_ES.UTF-8 fr_FR.UTF-8"
PHP_FPM_INSTALL_DOCKER_CLIENT=false
PHP_FPM_DEFAULT_LOCALE=POSIX
+PHP_FPM_XDEBUG_PORT=9003
PHP_FPM_PUID=1000
PHP_FPM_PGID=1000
@@ -271,8 +279,11 @@ PHP_FPM_NEW_RELIC_APP_NAME=app_name
PHP_WORKER_INSTALL_BZ2=false
PHP_WORKER_INSTALL_GD=false
PHP_WORKER_INSTALL_IMAGEMAGICK=false
+PHP_WORKER_IMAGEMAGICK_VERSION=latest
PHP_WORKER_INSTALL_GMP=false
+PHP_WORKER_INSTALL_GNUPG=false
PHP_WORKER_INSTALL_PGSQL=false
+PHP_WORKER_INSTALL_MONGO=false
PHP_WORKER_INSTALL_BCMATH=false
# PHP_WORKER_INSTALL_OCI8 Does not work in php5.6 version
PHP_WORKER_INSTALL_OCI8=false
@@ -310,12 +321,15 @@ NGINX_SSL_PATH=./nginx/ssl/
LARAVEL_HORIZON_INSTALL_BZ2=false
LARAVEL_HORIZON_INSTALL_GD=false
LARAVEL_HORIZON_INSTALL_GMP=false
+LARAVEL_HORIZON_INSTALL_GNUPG=false
LARAVEL_HORIZON_INSTALL_IMAGEMAGICK=false
+LARAVEL_HORIZON_IMAGEMAGICK_VERSION=latest
LARAVEL_HORIZON_INSTALL_SOCKETS=false
LARAVEL_HORIZON_INSTALL_YAML=false
LARAVEL_HORIZON_INSTALL_ZIP_ARCHIVE=false
-LARAVEL_HORIZON_INSTALL_PHPREDIS=true
+LARAVEL_HORIZON_INSTALL_PHPREDIS=false
LARAVEL_HORIZON_INSTALL_MONGO=false
+LARAVEL_HORIZON_INSTALL_CASSANDRA=false
LARAVEL_HORIZON_INSTALL_FFMPEG=false
LARAVEL_HORIZON_INSTALL_AUDIOWAVEFORM=false
LARAVEL_HORIZON_PGID=1000
@@ -327,10 +341,12 @@ APACHE_HOST_HTTP_PORT=80
APACHE_HOST_HTTPS_PORT=443
APACHE_HOST_LOG_PATH=./logs/apache2
APACHE_SITES_PATH=./apache2/sites
+APACHE_SSL_PATH=./apache2/ssl
APACHE_PHP_UPSTREAM_CONTAINER=php-fpm
APACHE_PHP_UPSTREAM_PORT=9000
APACHE_PHP_UPSTREAM_TIMEOUT=60
APACHE_DOCUMENT_ROOT=/var/www/
+APACHE_SSL_PATH=./apache2/ssl/
APACHE_INSTALL_HTTP2=false
### MYSQL #################################################
@@ -868,6 +884,15 @@ PGADMIN_PORT=5050
PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
PGADMIN_DEFAULT_PASSWORD=admin
+### SWAGGER EDITOR ###########################################
+
+SWAGGER_EDITOR_PORT=5151
+
+### SWAGGER UI ###############################################
+
+SWAGGER_API_URL=http://generator.swagger.io/api/swagger.json
+SWAGGER_UI_PORT=5555
+
### SONARQUBE ################################################
## docker-compose up -d sonarqube
## (If you encounter a database error)
diff --git a/.phive/phars.xml b/.phive/phars.xml
index 54f64a1..acda6c4 100644
--- a/.phive/phars.xml
+++ b/.phive/phars.xml
@@ -1,10 +1,11 @@
-
+
-
-
+
+
+
diff --git a/.php_cs.dist b/.php_cs.dist
index 2fa2632..8739662 100644
--- a/.php_cs.dist
+++ b/.php_cs.dist
@@ -9,6 +9,7 @@ return PhpCsFixer\Config::create()
'inheritDoc' => 'inheritdoc',
],
],
+ 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
'native_constant_invocation' => true,
'native_function_invocation' => true,
'no_empty_phpdoc' => true,
diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json
index df73b46..c183557 100644
--- a/.vim/coc-settings.json
+++ b/.vim/coc-settings.json
@@ -1,10 +1,13 @@
{
"diagnostic-languageserver.linters": {
- "ngmy.laradock.composer.lint": {
- "args": ["exec", "-u", "laradock", "laradock-ngmy-php-enum_workspace_1", "composer", "lint", "--", "--report=emacs"]
+ "ngmy.laradock.phive.phpcs": {
+ "args": ["exec", "-u", "laradock", "laradock-ngmy-php-enum_workspace_1", "php", "tools/phpcs", "--report=emacs"]
},
- "ngmy.laradock.composer.findbugs": {
- "args": ["exec", "-u", "laradock", "laradock-ngmy-php-enum_workspace_1", "composer", "findbugs", "--", "--error-format", "raw", "--no-progress"]
+ "ngmy.laradock.phive.phpstan": {
+ "args": ["exec", "-u", "laradock", "laradock-ngmy-php-enum_workspace_1", "php", "tools/phpstan", "analyse", "--error-format", "raw", "--no-progress"]
+ },
+ "ngmy.laradock.phive.psalm": {
+ "args": ["exec", "-u", "laradock", "laradock-ngmy-php-enum_workspace_1", "php", "tools/psalm", "--output-format=emacs", "--no-progress", "--no-cache"]
}
}
}
diff --git a/README.md b/README.md
index 780e3e3..fd35f6d 100644
--- a/README.md
+++ b/README.md
@@ -7,12 +7,14 @@
[](https://github.com/ngmy/php-typed-array/actions/workflows/php.yml)
[](https://coveralls.io/github/ngmy/php-enum?branch=master)
[](https://github.com/phpstan/phpstan)
+[](https://shepherd.dev/github/ngmy/php-typed-array)
+[](https://shepherd.dev/github/ngmy/php-typed-array)
PHP Enum is the enumeration type for PHP.
- Interface like the enum type of Java
- Also provides the enum map and set like Java
-- Supports the static analysis like PHPStan. Please see [examples](docs/examples)
+- Supports the static analysis like PHPStan and Psalm. Please see [examples](docs/examples)
```php
/**
diff --git a/composer.json b/composer.json
index e02c095..9fb3b76 100644
--- a/composer.json
+++ b/composer.json
@@ -20,7 +20,7 @@
],
"require": {
"php": "^7.3|^8.0",
- "ngmy/typed-array": "^0.8.0"
+ "ngmy/typed-array": "^0.11.0"
},
"autoload": {
"psr-4": {
@@ -39,20 +39,40 @@
"prefer-stable": true,
"scripts": {
"test": [
- "@php tools/phpunit --colors=always"
+ "@phpunit"
],
"lint": [
- "@php tools/phpcs"
- ],
- "findbugs": [
- "@php tools/phpstan analyse --ansi"
+ "@phpcs",
+ "@phpstan",
+ "@psalm"
],
"fmt": [
- "@php tools/phpcbf | exit 0",
- "@php tools/php-cs-fixer fix --ansi"
+ "@php-cs-fixer",
+ "@phpcbf"
+ ],
+ "doc": [
+ "@phpdoc"
+ ],
+ "php-cs-fixer": [
+ "tools/php-cs-fixer fix --ansi"
+ ],
+ "phpcbf": [
+ "tools/phpcbf"
+ ],
+ "phpcs": [
+ "tools/phpcs"
+ ],
+ "phpdoc": [
+ "tools/phpDocumentor --force"
+ ],
+ "phpstan": [
+ "tools/phpstan analyse --ansi"
+ ],
+ "phpunit": [
+ "tools/phpunit --colors=always"
],
- "docs": [
- "@php tools/phpDocumentor --force"
+ "psalm": [
+ "if [ \"${PSALM_SHEPHERD:-0}\" = '0' ]; then tools/psalm --no-cache; else tools/psalm --no-cache --shepherd; fi"
]
}
}
diff --git a/composer.lock b/composer.lock
index 24c3434..7b687d7 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "66253266947ae0e3c0d9562c9406f21c",
+ "content-hash": "08291a67ba4ef71a81a03982068481c7",
"packages": [
{
"name": "ngmy/typed-array",
- "version": "0.8.0",
+ "version": "0.11.0",
"source": {
"type": "git",
"url": "https://github.com/ngmy/php-typed-array.git",
- "reference": "edc2ba905657f8b7373ad8f08c9011fa524389ad"
+ "reference": "8dc440701096474f8848a7bd5d4028661277874f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/ngmy/php-typed-array/zipball/edc2ba905657f8b7373ad8f08c9011fa524389ad",
- "reference": "edc2ba905657f8b7373ad8f08c9011fa524389ad",
+ "url": "https://api.github.com/repos/ngmy/php-typed-array/zipball/8dc440701096474f8848a7bd5d4028661277874f",
+ "reference": "8dc440701096474f8848a7bd5d4028661277874f",
"shasum": ""
},
"require": {
@@ -50,7 +50,7 @@
],
"support": {
"issues": "https://github.com/ngmy/php-typed-array/issues",
- "source": "https://github.com/ngmy/php-typed-array/tree/0.8.0"
+ "source": "https://github.com/ngmy/php-typed-array/tree/0.11.0"
},
"funding": [
{
@@ -62,7 +62,7 @@
"type": "github"
}
],
- "time": "2021-03-20T15:20:15+00:00"
+ "time": "2021-04-03T12:43:11+00:00"
}
],
"packages-dev": [],
diff --git a/docs/api/classes/Ngmy-Enum-Enum.html b/docs/api/classes/Ngmy-Enum-Enum.html
index 174c5f2..8c7a8aa 100644
--- a/docs/api/classes/Ngmy-Enum-Enum.html
+++ b/docs/api/classes/Ngmy-Enum-Enum.html
@@ -90,7 +90,7 @@
@@ -241,7 +241,7 @@
@@ -272,7 +272,7 @@
@@ -298,6 +298,15 @@
Returns the enum constant of the specified name.
@@ -366,6 +375,15 @@
+
+
+ psalm-param
+
+
+
+
+
@@ -389,7 +407,7 @@
@@ -440,7 +458,7 @@
Returns the name of this enum constant, as contained in the declaration.
@@ -474,7 +492,7 @@
@@ -506,7 +524,7 @@
Returns true if the specified object is equal to this enum constant.
@@ -550,7 +568,7 @@
Returns the hash code for this enum constant
@@ -584,7 +602,7 @@
Returns the name of this enum constant, exactly as declared in its enum declaration.
@@ -618,7 +636,7 @@
Returns the ordinal of this enum constant.
@@ -653,7 +671,7 @@
Returns the enum constant of the specified name.
@@ -697,7 +715,7 @@
Returns all constants of this enum type.
@@ -723,6 +741,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -746,7 +773,7 @@
@@ -779,7 +806,7 @@
@@ -821,7 +848,7 @@
diff --git a/docs/api/classes/Ngmy-Enum-EnumMap.html b/docs/api/classes/Ngmy-Enum-EnumMap.html
index 705355a..945c8cf 100644
--- a/docs/api/classes/Ngmy-Enum-EnumMap.html
+++ b/docs/api/classes/Ngmy-Enum-EnumMap.html
@@ -93,7 +93,7 @@
@@ -155,7 +155,7 @@
-
@@ -185,6 +185,42 @@
IteratorAggregate<string, TValue>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-template
+
+
+
+
+
+
+
+ template-implements
+
+
+
+ ArrayAccess<TKey, TValue>
+
+
+
+
+ template-implements
+
+
+
+ IteratorAggregate<string, TValue>
+
+
@@ -410,7 +446,7 @@
@@ -436,6 +472,15 @@
+
+
+ psalm-var
+
+
+
+
+
@@ -456,7 +501,7 @@
@@ -482,6 +527,15 @@
+
+
+ psalm-var
+
+
+
+ TypedArray<TKey, TValue>
+
+
@@ -506,7 +560,7 @@
@@ -531,6 +585,24 @@
+
+
+ phpstan-return
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -554,7 +626,7 @@
@@ -588,6 +660,15 @@
Traversable<string, TValue>
+
+
+ psalm-return
+
+
+
+ Traversable<string, TValue>
+
+
@@ -611,7 +692,7 @@
Determines if the enum map is empty or not.
@@ -645,7 +726,7 @@
Creates a new instance of the enum map with the specified enum type key.
@@ -678,7 +759,7 @@
-
@@ -690,6 +771,42 @@
+
+
+ phpstan-return
+
+
+
+
+
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -713,13 +830,13 @@
public
- offsetExists(mixed $key) : bool
+ offsetExists(Enum $key) : bool
@@ -727,7 +844,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -749,6 +866,24 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
@@ -772,13 +907,13 @@
public
- offsetGet(mixed $key) : mixed|null
+ offsetGet(Enum $key) : mixed|null
@@ -786,7 +921,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -808,6 +943,15 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
-
phpstan-return
@@ -817,6 +961,24 @@
+
+ -
+ psalm-param
+
+ -
+
+
+
+
+ -
+ psalm-return
+
+ -
+
+
+
@@ -840,7 +1002,7 @@
@@ -902,6 +1064,24 @@
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
@@ -925,13 +1105,13 @@
public
- offsetUnset(mixed $key) : void
+ offsetUnset(Enum $key) : void
@@ -939,7 +1119,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -961,6 +1141,24 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
@@ -984,7 +1182,7 @@
Gets the enum map of values as a plain array.
@@ -1010,6 +1208,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1033,7 +1240,7 @@
Returns a new instance of the enum map with the array type value.
@@ -1059,6 +1266,15 @@
EnumMap<TKey, array<int|string, mixed>>
+
+
+ psalm-return
+
+
+
+ EnumMap<TKey, array<int|string, mixed>>
+
+
@@ -1082,7 +1298,7 @@
Returns a new instance of the enum map with the bool type value.
@@ -1108,6 +1324,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1131,7 +1356,7 @@
Returns a new instance of the enum map with the specified class type value.
@@ -1185,6 +1410,33 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -1208,7 +1460,7 @@
Returns a new instance of the enum map with the float type value.
@@ -1234,6 +1486,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1257,7 +1518,7 @@
Returns a new instance of the enum map with the class type value that implements the specified interface.
@@ -1311,6 +1572,33 @@
EnumMap<TKey, TInterface>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+ class-string $interface
+
+
+
+
+ psalm-return
+
+
+
+ EnumMap<TKey, TInterface>
+
+
@@ -1334,7 +1622,7 @@
Returns a new instance of the enum map with the int type value.
@@ -1360,6 +1648,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1383,7 +1680,7 @@
Returns a new instance of the enum map with the mixed type value.
@@ -1409,6 +1706,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1432,7 +1738,7 @@
Returns a new instance of the enum map with the object type value.
@@ -1458,6 +1764,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1481,7 +1796,7 @@
Returns a new instance of the enum map with the resource type value.
@@ -1507,6 +1822,15 @@
+
+
+ psalm-return
+
+
+
+ EnumMap<TKey, resource>
+
+
@@ -1530,7 +1854,7 @@
Returns a new instance of the enum map with the string type value.
@@ -1556,6 +1880,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1579,7 +1912,7 @@
Returns a new instance of the enum map with the class type value that uses the specified trait.
@@ -1615,6 +1948,33 @@
+
+
+ phpstan-return
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -1638,7 +1998,7 @@
@@ -1674,6 +2034,15 @@
TypedArray<TKey, TValue> $typedArray
+
+
+ psalm-param
+
+
+
+ TypedArray<TKey, TValue> $typedArray
+
+
@@ -1697,7 +2066,7 @@
@@ -1732,6 +2101,15 @@
+
+
+ psalm-param
+
+
+
+
+
diff --git a/docs/api/classes/Ngmy-Enum-EnumSet.html b/docs/api/classes/Ngmy-Enum-EnumSet.html
index 13aa8e8..bef61df 100644
--- a/docs/api/classes/Ngmy-Enum-EnumSet.html
+++ b/docs/api/classes/Ngmy-Enum-EnumSet.html
@@ -93,7 +93,7 @@
@@ -155,7 +155,7 @@
-
@@ -176,6 +176,33 @@
IteratorAggregate<int, T>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ template-implements
+
+
+
+
+
+
+
+ template-implements
+
+
+
+ IteratorAggregate<int, T>
+
+
@@ -338,7 +365,7 @@
@@ -364,6 +391,15 @@
+
+
+ psalm-var
+
+
+
+
+
@@ -388,7 +424,7 @@
Creates an enum set containing all of the elements in the specified element type.
@@ -421,7 +457,7 @@
-
@@ -442,6 +478,33 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -465,7 +528,7 @@
@@ -490,6 +553,24 @@
+
+
+ phpstan-return
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -513,7 +594,7 @@
@@ -547,6 +628,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -570,7 +660,7 @@
Determines if the enum set is empty or not.
@@ -604,7 +694,7 @@
Creates an empty enum set with the specified element type.
@@ -637,7 +727,7 @@
-
@@ -658,6 +748,33 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -681,7 +798,7 @@
Creates an enum set initially containing the specified element.
@@ -735,6 +852,33 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -758,13 +902,13 @@
public
- offsetExists(mixed $key) : bool
+ offsetExists(Enum $key) : bool
@@ -772,7 +916,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -794,6 +938,24 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
@@ -817,13 +979,13 @@
public
- offsetGet(mixed $key) : Enum|null
+ offsetGet(Enum $key) : Enum|null
@@ -831,7 +993,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -853,6 +1015,15 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
-
phpstan-return
@@ -862,6 +1033,24 @@
+
+ -
+ psalm-param
+
+ -
+
+
+
+
+ -
+ psalm-return
+
+ -
+
+
+
@@ -885,7 +1074,7 @@
@@ -935,7 +1124,34 @@
-
+
+ phpstan-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
@@ -961,13 +1177,13 @@
public
- offsetUnset(mixed $key) : void
+ offsetUnset(Enum $key) : void
@@ -975,7 +1191,7 @@ Parameters
-
$key
- : mixed
+ : Enum
-
@@ -997,6 +1213,24 @@
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
@@ -1020,7 +1254,7 @@
Creates an enum set initially containing all of the elements in the range defined by the two specified endpoints.
@@ -1090,6 +1324,42 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -1113,7 +1383,7 @@
Gets the enum set of values as a plain array.
@@ -1139,6 +1409,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1162,7 +1441,7 @@
@@ -1198,6 +1477,15 @@
+
+
+ psalm-param
+
+
+
+
+
@@ -1221,7 +1509,7 @@
@@ -1256,6 +1544,15 @@
+
+
+ psalm-param
+
+
+
+
+
diff --git a/docs/api/classes/Ngmy-TypedArray-TypedArray.html b/docs/api/classes/Ngmy-TypedArray-TypedArray.html
index 7107afb..f40cbda 100644
--- a/docs/api/classes/Ngmy-TypedArray-TypedArray.html
+++ b/docs/api/classes/Ngmy-TypedArray-TypedArray.html
@@ -93,7 +93,7 @@
@@ -185,6 +185,51 @@
IteratorAggregate<int|string, TValue>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-template
+
+
+
+
+
+
+
+ template-implements
+
+
+
+ ArrayAccess<TKey, TValue>
+
+
+
+
+ template-implements
+
+
+
+ IteratorAggregate<int|string, TValue>
+
+
+
+
+ psalm-type
+
+
+
+
+
@@ -294,7 +339,7 @@
getIterator()
- : Traversable<int|string, mixed>
+ : ArrayIterator<int|string, mixed>
@@ -534,7 +579,7 @@
@@ -559,7 +604,7 @@
@@ -584,7 +629,7 @@
@@ -609,7 +654,7 @@
@@ -649,7 +694,7 @@
@@ -680,7 +725,7 @@
The hash map of key's hash codes and keys.
@@ -708,6 +753,15 @@
+
+
+ psalm-var
+
+
+
+ array<int|string, TKey>
+
+
@@ -728,7 +782,7 @@
@@ -754,6 +808,15 @@
+
+
+ psalm-var
+
+
+
+
+
@@ -774,7 +837,7 @@
@@ -805,7 +868,7 @@
The hash map of key's hash codes and values.
@@ -832,6 +895,15 @@
array<int|string, TValue>
+
+
+ psalm-var
+
+
+
+ array<int|string, TValue>
+
+
@@ -852,7 +924,7 @@
@@ -878,6 +950,15 @@
+
+
+ psalm-var
+
+
+
+
+
@@ -902,7 +983,7 @@
@@ -927,6 +1008,24 @@
+
+
+ phpstan-return
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -950,13 +1049,13 @@
public
- getIterator() : Traversable<int|string, mixed>
+ getIterator() : ArrayIterator<int|string, mixed>
@@ -981,14 +1080,27 @@
- Traversable<int|string, TValue>
+ ArrayIterator<int|string, TValue>
+
+
+
+
+ psalm-return
+
+
+
+ ArrayIterator<(
+TKey is IntArrayKey|object
+? int
+: (TKey is bool|float|string|resource ? string : int|string)
+), TValue>
Return values
- Traversable<int|string, mixed>
+ ArrayIterator<int|string, mixed>
—
@@ -1007,7 +1119,7 @@
Determines if the typed array is empty or not.
@@ -1041,7 +1153,7 @@
Creates a new instance of the typed array.
@@ -1075,7 +1187,7 @@
@@ -1111,6 +1223,24 @@
+
+
+ phpstan-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
@@ -1134,7 +1264,7 @@
@@ -1170,6 +1300,15 @@
+
+
+ phpstan-param
+
+
+
+
+
phpstan-return
@@ -1179,6 +1318,24 @@
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+
+
@@ -1202,7 +1359,7 @@
@@ -1264,6 +1421,24 @@
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
@@ -1287,7 +1462,7 @@
@@ -1323,6 +1498,24 @@
+
+
+ phpstan-param
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
@@ -1346,7 +1539,7 @@
Gets the typed array of values as a plain array.
@@ -1372,6 +1565,19 @@
array<int|string, TValue>
+
+
+ psalm-return
+
+
+
+ array<(
+TKey is IntArrayKey|object
+? int
+: (TKey is bool|float|string|resource ? string : int|string)
+), TValue>
+
+
@@ -1395,7 +1601,7 @@
Returns a new instance of the typed array with the array type value.
@@ -1421,6 +1627,15 @@
TypedArray<TKey, array<int|string, mixed>>
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, array<int|string, mixed>>
+
+
@@ -1444,7 +1659,7 @@
Returns a new instance of the typed array with the bool type key.
@@ -1470,6 +1685,15 @@
+
+
+ psalm-return
+
+
+
+ TypedArray<bool, TValue>
+
+
@@ -1493,7 +1717,7 @@
Returns a new instance of the typed array with the bool type value.
@@ -1519,6 +1743,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -1542,7 +1775,7 @@
Returns a new instance of the typed array with the specified class type key.
@@ -1553,7 +1786,7 @@
If you are using an object as the key, it is recommended that you implement the equals()
and hashCode() methods on the object to determine whether keys are equal or not.
-Otherwise, the === operator and spl_object_hash() function are used to determine it.
+Otherwise, the === operator and spl_object_id() function are used to determine it.
Parameters
@@ -1608,6 +1841,33 @@
TypedArray<TClass, TValue>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<TClass, TValue>
+
+
@@ -1631,7 +1891,7 @@
Returns a new instance of the typed array with the specified class type value.
@@ -1685,6 +1945,33 @@
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, TClass>
+
+
@@ -1708,7 +1995,7 @@
Returns a new instance of the typed array with the float type key.
@@ -1734,6 +2021,15 @@
TypedArray<float, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<float, TValue>
+
+
@@ -1757,7 +2053,7 @@
Returns a new instance of the typed array with the float type value.
@@ -1783,6 +2079,15 @@
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, float>
+
+
@@ -1806,7 +2111,7 @@
Returns a new instance of the typed array with the class type key that implements the specified interface.
@@ -1817,7 +2122,7 @@
If you are using an object as the key, it is recommended that you implement the equals()
and hashCode() methods on the object to determine whether keys are equal or not.
-Otherwise, the === operator and spl_object_hash() function are used to determine it.
+Otherwise, the === operator and spl_object_id() function are used to determine it.
Parameters
@@ -1872,6 +2177,33 @@
TypedArray<TInterface, TValue>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+ class-string $interface
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<TInterface, TValue>
+
+
@@ -1895,7 +2227,7 @@
Returns a new instance of the typed array with the class type value that implements the specified interface.
@@ -1949,6 +2281,33 @@
TypedArray<TKey, TInterface>
+
+
+ psalm-template
+
+
+
+
+
+
+
+ psalm-param
+
+
+
+ class-string $interface
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, TInterface>
+
+
@@ -1972,7 +2331,7 @@
Returns a new instance of the typed array with the int type key.
@@ -1998,6 +2357,15 @@
TypedArray<int|null, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<IntArrayKey, TValue>
+
+
@@ -2021,7 +2389,7 @@
Returns a new instance of the typed array with the int type value.
@@ -2047,6 +2415,15 @@
+
+
+ psalm-return
+
+
+
+
+
@@ -2070,7 +2447,7 @@
Returns a new instance of the typed array with the mixed type key.
@@ -2096,6 +2473,15 @@
TypedArray<mixed, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<mixed, TValue>
+
+
@@ -2119,7 +2505,7 @@
Returns a new instance of the typed array with the mixed type value.
@@ -2145,6 +2531,15 @@
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, mixed>
+
+
@@ -2168,7 +2563,7 @@
Returns a new instance of the typed array with the object type key.
@@ -2179,7 +2574,7 @@
If you are using an object as the key, it is recommended that you implement the equals()
and hashCode() methods on the object to determine whether keys are equal or not.
-Otherwise, the === operator and spl_object_hash() function are used to determine it.
+Otherwise, the === operator and spl_object_id() function are used to determine it.
@@ -2206,6 +2601,15 @@
TypedArray<object, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<object, TValue>
+
+
@@ -2229,7 +2633,7 @@
Returns a new instance of the typed array with the object type value.
@@ -2255,6 +2659,15 @@
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, object>
+
+
@@ -2278,7 +2691,7 @@
Returns a new instance of the typed array with the resource type key.
@@ -2304,6 +2717,15 @@
TypedArray<resource, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<resource, TValue>
+
+
@@ -2327,7 +2749,7 @@
Returns a new instance of the typed array with the resource type value.
@@ -2353,6 +2775,15 @@
TypedArray<TKey, resource>
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, resource>
+
+
@@ -2376,7 +2807,7 @@
Returns a new instance of the typed array with the string type key.
@@ -2402,6 +2833,15 @@
TypedArray<string, TValue>
+
+
+ psalm-return
+
+
+
+ TypedArray<string, TValue>
+
+
@@ -2425,7 +2865,7 @@
Returns a new instance of the typed array with the string type value.
@@ -2451,6 +2891,15 @@
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, string>
+
+
@@ -2474,7 +2923,7 @@
Returns a new instance of the typed array with the class type key that uses the specified trait.
@@ -2485,7 +2934,7 @@
If you are using an object as the key, it is recommended that you implement the equals()
and hashCode() methods on the object to determine whether keys are equal or not.
-Otherwise, the === operator and spl_object_hash() function are used to determine it.
+Otherwise, the === operator and spl_object_id() function are used to determine it.
Parameters
@@ -2522,6 +2971,33 @@
+
+
+ phpstan-return
+
+
+
+ TypedArray<object, TValue>
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<object, TValue>
+
+
@@ -2545,7 +3021,7 @@
Returns a new instance of the typed array with the class type value that uses the specified trait.
@@ -2581,6 +3057,33 @@
+
+
+ phpstan-return
+
+
+
+ TypedArray<TKey, object>
+
+
+
+
+ psalm-param
+
+
+
+
+
+
+
+ psalm-return
+
+
+
+ TypedArray<TKey, object>
+
+
@@ -2604,7 +3107,7 @@
@@ -2667,7 +3170,7 @@
@@ -2690,6 +3193,48 @@ Parameters
+
+ Tags
+
+
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ phpstan-return
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
+
+ -
+ psalm-return
+
+ -
+
+
+
+
+
Return values
int|string|null
@@ -2711,7 +3256,7 @@
@@ -2742,6 +3287,48 @@ Parameters
+
+ Tags
+
+
+
+ -
+ phpstan-param
+
+ -
+
+
+
+
+ -
+ phpstan-param
+
+ -
+
+
int|string|null $keyHashCode
+
+
+
+ -
+ psalm-param
+
+ -
+
+
+
+
+ -
+ psalm-param
+
+ -
+
+
IntArrayKey|string $keyHashCode
+
+
+
+
Return values
bool
diff --git a/laradock b/laradock
index 3a73aa6..ecdfa17 160000
--- a/laradock
+++ b/laradock
@@ -1 +1 @@
-Subproject commit 3a73aa60eeb40a807f7ed064f51d1ac12d7ce26f
+Subproject commit ecdfa174dc82771ff5effa3303b65505eb09ae8a
diff --git a/psalm.xml.dist b/psalm.xml.dist
new file mode 100644
index 0000000..3240886
--- /dev/null
+++ b/psalm.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/Enum.php b/src/Enum.php
index 097db9c..5a17eab 100644
--- a/src/Enum.php
+++ b/src/Enum.php
@@ -9,11 +9,27 @@
use LogicException;
use ReflectionClass;
+use function array_keys;
+use function array_map;
+use function array_search;
+use function assert;
+use function explode;
+use function get_called_class;
+use function in_array;
+use function is_int;
+use function ord;
+use function preg_match;
+use function sprintf;
+use function strlen;
+
+use const PHP_EOL;
+
abstract class Enum
{
/**
* @var array>
* @phpstan-var array>
+ * @psalm-var array>
*/
private static $names = [];
@@ -27,6 +43,8 @@ abstract class Enum
* @return static
*
* @phpstan-param list $arguments
+ *
+ * @psalm-param list $arguments
*/
final public static function __callStatic(string $name, array $arguments): self
{
@@ -49,10 +67,12 @@ final public static function valueOf(string $name): self
* @return array
*
* @phpstan-return list
+ *
+ * @psalm-return list
*/
final public static function values(): array
{
- return \array_map(function (string $name): self {
+ return array_map(function (string $name): self {
return self::valueOf($name);
}, self::names());
}
@@ -64,26 +84,28 @@ final public static function values(): array
* @internal
*
* @phpstan-return list
+ *
+ * @psalm-return list
*/
final public static function names(): array
{
self::validateInheritance();
- $class = \get_called_class();
+ $class = get_called_class();
if (isset(self::$names[$class])) {
return self::$names[$class];
}
self::$names[$class] = [];
$reflectionClass = new ReflectionClass($class);
$staticProperties = $reflectionClass->getStaticProperties();
- foreach (\array_keys($staticProperties) as $propertyName) {
+ foreach (array_keys($staticProperties) as $propertyName) {
$reflectionProperty = $reflectionClass->getProperty($propertyName);
$docComment = $reflectionProperty->getDocComment();
if ($docComment === false) {
continue;
}
- $lines = \explode(\PHP_EOL, $docComment);
+ $lines = explode(PHP_EOL, $docComment);
foreach ($lines as $line) {
- if (!\preg_match('/@[^\s]+/', $line, $mathces) || $mathces[0] != '@enum') {
+ if (!preg_match('/@[^\s]+/', $line, $mathces) || $mathces[0] != '@enum') {
continue;
}
self::$names[$class][] = $propertyName;
@@ -115,8 +137,9 @@ public function __toString(): string
*/
final public function ordinal(): int
{
- \assert(\is_int(\array_search($this->name, self::names())));
- return \array_search($this->name, self::names());
+ $ordinal = array_search($this->name, self::names());
+ assert(is_int($ordinal));
+ return $ordinal;
}
/**
@@ -133,9 +156,9 @@ final public function equals(object $other): bool
final public function hashCode(): int
{
$result = 17;
- $nameLength = \strlen($this->name);
+ $nameLength = strlen($this->name);
for ($i = 0; $i < $nameLength; ++$i) {
- $result = 31 * $result + \ord($this->name[$i]);
+ $result = 31 * $result + ord($this->name[$i]);
}
return $result;
}
@@ -163,7 +186,7 @@ final protected function __clone()
private static function validateInheritance(): void
{
- $reflectionClass = new ReflectionClass(\get_called_class());
+ $reflectionClass = new ReflectionClass(get_called_class());
while ($reflectionClass = $reflectionClass->getParentClass()) {
if ($reflectionClass->getName() != self::class) {
throw new LogicException('You are not allowed to inherit from the concrete enum class.');
@@ -173,8 +196,8 @@ private static function validateInheritance(): void
final private function __construct(string $name)
{
- if (!\in_array($name, self::names())) {
- throw new InvalidArgumentException(\sprintf('The name "%s" is not defined.', $name));
+ if (!in_array($name, self::names())) {
+ throw new InvalidArgumentException(sprintf('The name "%s" is not defined.', $name));
}
$this->name = $name;
}
diff --git a/src/EnumMap.php b/src/EnumMap.php
index 3bec45f..e666ef0 100644
--- a/src/EnumMap.php
+++ b/src/EnumMap.php
@@ -12,6 +12,13 @@
use Ngmy\TypedArray\TypedArray;
use Traversable;
+use function array_keys;
+use function array_reduce;
+use function class_exists;
+use function count;
+use function get_parent_class;
+use function sprintf;
+
/**
* @implements ArrayAccess
* @implements IteratorAggregate
@@ -19,21 +26,28 @@
* @see https://www.php.net/manual/en/class.countable.php
* @see https://www.php.net/manual/en/class.iteratoraggregate.php
*
- * @phpstan-template TKey
+ * @phpstan-template TKey of Enum
* @phpstan-template TValue
* @phpstan-implements ArrayAccess
* @phpstan-implements IteratorAggregate
+ *
+ * @psalm-template TKey of Enum
+ * @psalm-template TValue
+ * @template-implements ArrayAccess
+ * @template-implements IteratorAggregate
*/
class EnumMap implements ArrayAccess, Countable, IteratorAggregate
{
/**
* @var TypedArray
* @phpstan-var TypedArray
+ * @psalm-var TypedArray
*/
private $typedArray;
/**
* @var array
* @phpstan-var array
+ * @psalm-var array
*/
private $keys = [];
@@ -42,9 +56,13 @@ class EnumMap implements ArrayAccess, Countable, IteratorAggregate
*
* @return EnumMap
*
- * @phpstan-template TEnum
+ * @phpstan-template TEnum of Enum
* @phpstan-param class-string $class
- * @return EnumMap
+ * @phpstan-return EnumMap
+ *
+ * @psalm-template TEnum of Enum
+ * @psalm-param class-string $class
+ * @psalm-return EnumMap
*/
public static function new(string $class): self
{
@@ -59,6 +77,8 @@ public static function new(string $class): self
* @return EnumMap>
*
* @phpstan-return EnumMap>
+ *
+ * @psalm-return EnumMap>
*/
public function withArrayValue(): self
{
@@ -71,6 +91,8 @@ public function withArrayValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withBoolValue(): self
{
@@ -83,6 +105,8 @@ public function withBoolValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withFloatValue(): self
{
@@ -95,6 +119,8 @@ public function withFloatValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withIntValue(): self
{
@@ -107,6 +133,8 @@ public function withIntValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withMixedValue(): self
{
@@ -119,6 +147,8 @@ public function withMixedValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withObjectValue(): self
{
@@ -131,6 +161,8 @@ public function withObjectValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withResourceValue(): self
{
@@ -143,6 +175,8 @@ public function withResourceValue(): self
* @return EnumMap
*
* @phpstan-return EnumMap
+ *
+ * @psalm-return EnumMap
*/
public function withStringValue(): self
{
@@ -157,6 +191,10 @@ public function withStringValue(): self
* @phpstan-template TClass
* @phpstan-param class-string $class
* @phpstan-return EnumMap
+ *
+ * @psalm-template TClass
+ * @psalm-param class-string $class
+ * @psalm-return EnumMap
*/
public function withClassValue(string $class): self
{
@@ -171,6 +209,10 @@ public function withClassValue(string $class): self
* @phpstan-template TInterface
* @phpstan-param class-string $interface
* @phpstan-return EnumMap
+ *
+ * @psalm-template TInterface
+ * @psalm-param class-string $interface
+ * @psalm-return EnumMap
*/
public function withInterfaceValue(string $interface): self
{
@@ -183,6 +225,10 @@ public function withInterfaceValue(string $interface): self
* @return EnumMap
*
* @phpstan-param class-string $trait
+ * @phpstan-return EnumMap
+ *
+ * @psalm-param trait-string $trait
+ * @psalm-return EnumMap
*/
public function withTraitValue(string $trait): self
{
@@ -203,20 +249,27 @@ public function isEmpty(): bool
* @return array
*
* @phpstan-return array
+ *
+ * @psalm-return array
*/
public function toArray(): array
{
$array = $this->typedArray->toArray();
- return \array_reduce(\array_keys($array), function (array $carry, int $hashCode) use ($array): array {
+ return array_reduce(array_keys($array), function (array $carry, int $hashCode) use ($array): array {
$key = $this->keys[$hashCode];
$carry[$key->name()] = $array[$hashCode];
+ /** @psalm-var array $carry */
return $carry;
}, []);
}
/**
- * @param mixed $key
+ * @param Enum $key
* @see https://www.php.net/manual/en/arrayaccess.offsetexists.php
+ *
+ * @phpstan-param TKey $key
+ *
+ * @psalm-param TKey $key
*/
public function offsetExists($key): bool
{
@@ -224,11 +277,15 @@ public function offsetExists($key): bool
}
/**
- * @param mixed $key
+ * @param Enum $key
* @return mixed|null
* @see https://www.php.net/manual/en/arrayaccess.offsetget.php
*
+ * @phpstan-param TKey $key
* @phpstan-return TValue|null
+ *
+ * @psalm-param TKey $key
+ * @psalm-return TValue|null
*/
public function offsetGet($key)
{
@@ -242,6 +299,9 @@ public function offsetGet($key)
*
* @phpstan-param TKey $key
* @phpstan-param TValue $value
+ *
+ * @psalm-param TKey $key
+ * @psalm-param TValue $value
*/
public function offsetSet($key, $value): void
{
@@ -250,8 +310,12 @@ public function offsetSet($key, $value): void
}
/**
- * @param mixed $key
+ * @param Enum $key
* @see https://www.php.net/manual/en/arrayaccess.offsetunset.php
+ *
+ * @phpstan-param TKey $key
+ *
+ * @psalm-param TKey $key
*/
public function offsetUnset($key): void
{
@@ -261,10 +325,15 @@ public function offsetUnset($key): void
/**
* @see https://www.php.net/manual/en/countable.count.php
+ *
+ * @phpstan-return 0|positive-int
+ *
+ * @psalm-return 0|positive-int
*/
public function count(): int
{
- return \count($this->typedArray);
+ /** @psalm-var 0|positive-int */
+ return count($this->typedArray);
}
/**
@@ -272,6 +341,8 @@ public function count(): int
* @see https://www.php.net/manual/en/iteratoraggregate.getiterator.php
*
* @phpstan-return Traversable
+ *
+ * @psalm-return Traversable
*/
public function getIterator(): Traversable
{
@@ -280,12 +351,14 @@ public function getIterator(): Traversable
/**
* @phpstan-param class-string $class
+ *
+ * @psalm-param class-string $class
*/
private static function validateEnum(string $class): void
{
- if (!\class_exists($class) || \get_parent_class($class) != Enum::class) {
+ if (!class_exists($class) || get_parent_class($class) != Enum::class) {
throw new InvalidArgumentException(
- \sprintf('The type of the key must be the concrete enum class, "%s" given.', $class)
+ sprintf('The type of the key must be the concrete enum class, "%s" given.', $class)
);
};
}
@@ -294,6 +367,8 @@ private static function validateEnum(string $class): void
* @param TypedArray $typedArray
*
* @phpstan-param TypedArray $typedArray
+ *
+ * @psalm-param TypedArray $typedArray
*/
private function __construct(TypedArray $typedArray)
{
diff --git a/src/EnumSet.php b/src/EnumSet.php
index 46dd16e..a159981 100644
--- a/src/EnumSet.php
+++ b/src/EnumSet.php
@@ -11,6 +11,15 @@
use IteratorAggregate;
use Traversable;
+use function assert;
+use function class_exists;
+use function count;
+use function get_class;
+use function get_parent_class;
+use function method_exists;
+use function sprintf;
+use function usort;
+
/**
* @implements ArrayAccess
* @implements IteratorAggregate
@@ -18,15 +27,20 @@
* @see https://www.php.net/manual/en/class.countable.php
* @see https://www.php.net/manual/en/class.iteratoraggregate.php
*
- * @phpstan-template T
+ * @phpstan-template T of Enum
* @phpstan-implements ArrayAccess
* @phpstan-implements IteratorAggregate
+ *
+ * @psalm-template T of Enum
+ * @template-implements ArrayAccess
+ * @template-implements IteratorAggregate
*/
class EnumSet implements ArrayAccess, Countable, IteratorAggregate
{
/**
* @var EnumMap
* @phpstan-var EnumMap
+ * @psalm-var EnumMap
*/
private $enumMap;
@@ -35,9 +49,13 @@ class EnumSet implements ArrayAccess, Countable, IteratorAggregate
*
* @return EnumSet
*
- * @phpstan-template TEnum
+ * @phpstan-template TEnum of Enum
* @phpstan-param class-string $class
* @phpstan-return EnumSet
+ *
+ * @psalm-template TEnum of Enum
+ * @psalm-param class-string $class
+ * @psalm-return EnumSet
*/
public static function allOf(string $class): self
{
@@ -54,9 +72,13 @@ public static function allOf(string $class): self
*
* @return EnumSet
*
- * @phpstan-template TEnum
+ * @phpstan-template TEnum of Enum
* @phpstan-param class-string $class
* @phpstan-return EnumSet
+ *
+ * @psalm-template TEnum of Enum
+ * @psalm-param class-string $class
+ * @psalm-return EnumSet
*/
public static function noneOf(string $class): self
{
@@ -72,10 +94,14 @@ public static function noneOf(string $class): self
* @phpstan-template TEnum of Enum
* @phpstan-param TEnum $enum
* @phpstan-return EnumSet
+ *
+ * @psalm-template TEnum of Enum
+ * @psalm-param TEnum $enum
+ * @psalm-return EnumSet
*/
public static function of(Enum $enum): self
{
- $class = \get_class($enum);
+ $class = get_class($enum);
$enumSet = new self(EnumMap::new($class)->withClassValue($class));
$enumSet[] = $enum;
return $enumSet;
@@ -90,14 +116,19 @@ public static function of(Enum $enum): self
* @phpstan-param TEnum $from
* @phpstan-param TEnum $to
* @phpstan-return EnumSet
+ *
+ * @psalm-template TEnum of Enum
+ * @psalm-param TEnum $from
+ * @psalm-param TEnum $to
+ * @psalm-return EnumSet
*/
public static function range(Enum $from, Enum $to): self
{
- $classFrom = \get_class($from);
- $classTo = \get_class($to);
+ $classFrom = get_class($from);
+ $classTo = get_class($to);
if ($classFrom != $classTo) {
throw new InvalidArgumentException(
- \sprintf(
+ sprintf(
'The range enum classes must be the same class, "%s" and "%s" given.',
$classFrom,
$classTo
@@ -108,7 +139,7 @@ public static function range(Enum $from, Enum $to): self
$ordinalTo = $to->ordinal();
if ($ordinalFrom > $ordinalTo) {
throw new InvalidArgumentException(
- \sprintf(
+ sprintf(
'The range "%s" (position %s) to "%s" (position %s) is invalid.',
$classFrom,
$ordinalFrom,
@@ -119,7 +150,7 @@ public static function range(Enum $from, Enum $to): self
}
$enums = [];
$names = $classFrom::names();
- $nameCount = \count($names);
+ $nameCount = count($names);
for ($i = 0; $i < $nameCount; ++$i) {
if ($i < $ordinalFrom) {
continue;
@@ -127,7 +158,12 @@ public static function range(Enum $from, Enum $to): self
if ($i > $ordinalTo) {
break;
}
- $enums[] = $classFrom::{$names[$i]}();
+ /**
+ * @phpstan-var TEnum $enum
+ * @psalm-var TEnum $enum
+ */
+ $enum = $classFrom::{$names[$i]}();
+ $enums[] = $enum;
}
$enumSet = new self(EnumMap::new($classFrom)->withClassValue($classFrom));
foreach ($enums as $enum) {
@@ -150,25 +186,32 @@ public function isEmpty(): bool
* @return array
*
* @phpstan-return list
+ *
+ * @psalm-return list
*/
public function toArray(): array
{
/**
* @var array
* @phpstan-var list
+ * @psalm-var list
*/
$array = $this->enumMap->toArray();
- \usort($array, function (object $enum1, object $enum2): int {
- \assert(\method_exists($enum1, 'ordinal'));
- \assert(\method_exists($enum2, 'ordinal'));
+ usort($array, function (object $enum1, object $enum2): int {
+ assert(method_exists($enum1, 'ordinal'));
+ assert(method_exists($enum2, 'ordinal'));
return $enum1->ordinal() < $enum2->ordinal() ? -1 : 1;
});
return $array;
}
/**
- * @param mixed $key
+ * @param Enum $key
* @see https://www.php.net/manual/en/arrayaccess.offsetexists.php
+ *
+ * @phpstan-param T $key
+ *
+ * @psalm-param T $key
*/
public function offsetExists($key): bool
{
@@ -176,11 +219,15 @@ public function offsetExists($key): bool
}
/**
- * @param mixed $key
+ * @param Enum $key
* @return Enum|null
* @see https://www.php.net/manual/en/arrayaccess.offsetget.php
*
+ * @phpstan-param T $key
* @phpstan-return T|null
+ *
+ * @psalm-param T $key
+ * @psalm-return T|null
*/
public function offsetGet($key)
{
@@ -192,7 +239,11 @@ public function offsetGet($key)
* @param Enum $enum
* @see https://www.php.net/manual/en/arrayaccess.offsetset.php
*
- * @phpstan-param T $enum
+ * @phpstan-param T|null $key
+ * @phpstan-param T $enum
+ *
+ * @psalm-param T|null $key
+ * @psalm-param T $enum
*/
public function offsetSet($key, $enum): void
{
@@ -200,8 +251,12 @@ public function offsetSet($key, $enum): void
}
/**
- * @param mixed $key
+ * @param Enum $key
* @see https://www.php.net/manual/en/arrayaccess.offsetunset.php
+ *
+ * @phpstan-param T $key
+ *
+ * @psalm-param T $key
*/
public function offsetUnset($key): void
{
@@ -210,10 +265,15 @@ public function offsetUnset($key): void
/**
* @see https://www.php.net/manual/en/countable.count.php
+ *
+ * @phpstan-return 0|positive-int
+ *
+ * @psalm-return 0|positive-int
*/
public function count(): int
{
- return \count($this->enumMap);
+ /** @psalm-var 0|positive-int */
+ return count($this->enumMap);
}
/**
@@ -221,6 +281,8 @@ public function count(): int
* @see https://www.php.net/manual/en/iteratoraggregate.getiterator.php
*
* @phpstan-return Traversable
+ *
+ * @psalm-return Traversable
*/
public function getIterator(): Traversable
{
@@ -229,12 +291,14 @@ public function getIterator(): Traversable
/**
* @phpstan-param class-string $class
+ *
+ * @psalm-param class-string $class
*/
private static function validateEnum(string $class): void
{
- if (!\class_exists($class) || \get_parent_class($class) != Enum::class) {
+ if (!class_exists($class) || get_parent_class($class) != Enum::class) {
throw new InvalidArgumentException(
- \sprintf('The type of the value must be the concrete enum class, "%s" given.', $class)
+ sprintf('The type of the value must be the concrete enum class, "%s" given.', $class)
);
};
}
@@ -243,6 +307,8 @@ private static function validateEnum(string $class): void
* @param EnumMap $enumMap
*
* @phpstan-param EnumMap $enumMap
+ *
+ * @psalm-param EnumMap $enumMap
*/
private function __construct(EnumMap $enumMap)
{
diff --git a/tests/Data/Enum3.php b/tests/Data/Enum3.php
index eb8f5b4..4f9dfc4 100644
--- a/tests/Data/Enum3.php
+++ b/tests/Data/Enum3.php
@@ -6,6 +6,9 @@
use Ngmy\Enum\Enum;
+use function strtolower;
+use function ucwords;
+
/**
* @method static self FOO()
* @method static self BAR()
@@ -34,6 +37,6 @@ class Enum3 extends Enum
*/
public function __toString(): string
{
- return \ucwords(\strtolower($this->name()));
+ return ucwords(strtolower($this->name()));
}
}
diff --git a/tests/EnumMapTest.php b/tests/EnumMapTest.php
index 2235420..6dcb152 100644
--- a/tests/EnumMapTest.php
+++ b/tests/EnumMapTest.php
@@ -8,6 +8,13 @@
use InvalidArgumentException;
use Ngmy\Enum\Enum;
use Ngmy\Enum\EnumMap;
+use stdClass;
+
+use function assert;
+use function get_class;
+use function is_array;
+use function is_null;
+use function tmpfile;
class EnumMapTest extends TestCase
{
@@ -18,7 +25,7 @@ public function newProvider(): array
{
return [
[Data\Enum1::class],
- [\stdClass::class, new InvalidArgumentException()],
+ [stdClass::class, new InvalidArgumentException()],
['a', new InvalidArgumentException()],
];
}
@@ -30,12 +37,14 @@ public function newProvider(): array
*/
public function testNew(string $class, Exception $exception = null): void
{
- if (\is_null($exception)) {
+ if (is_null($exception)) {
$this->expectNotToPerformAssertions();
}
if ($exception instanceof Exception) {
- $this->expectException(\get_class($exception));
+ $this->expectException(get_class($exception));
}
+ // NOTE: To test that an exception is thrown
+ // @phpstan-ignore-next-line
EnumMap::new($class);
}
@@ -115,9 +124,9 @@ public function testCount(array $enums, int $expected): void
*/
public function dataProvider(): array
{
- $resource1 = \tmpfile();
- $resource2 = \tmpfile();
- $resource3 = \tmpfile();
+ $resource1 = tmpfile();
+ $resource2 = tmpfile();
+ $resource3 = tmpfile();
return [
[
@@ -246,12 +255,12 @@ public function dataProvider(): array
public function test(EnumMap $enumMap, array $keys, array $values, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
foreach ($keys as $i => $key) {
$enumMap[$key] = $values[$i];
}
- \assert(\is_array($expected));
+ assert(is_array($expected));
$this->assertEquals($expected, $enumMap->toArray());
$i = 0;
foreach ($enumMap as $name => $value) {
diff --git a/tests/EnumSetTest.php b/tests/EnumSetTest.php
index 0b07c26..96f2c8c 100644
--- a/tests/EnumSetTest.php
+++ b/tests/EnumSetTest.php
@@ -10,6 +10,10 @@
use Ngmy\Enum\EnumSet;
use stdClass;
+use function assert;
+use function get_class;
+use function is_array;
+
class EnumSetTest extends TestCase
{
/**
@@ -37,8 +41,10 @@ public function allOfProvider(): array
public function testAllOf(string $class, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
+ // NOTE: To test that an exception is thrown
+ // @phpstan-ignore-next-line
$actual = EnumSet::allOf($class);
$this->assertEquals($expected, $actual->toArray());
}
@@ -64,8 +70,10 @@ public function noneOfProvider(): array
public function testNoneOf(string $class, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
+ // NOTE: To test that an exception is thrown
+ // @phpstan-ignore-next-line
$actual = EnumSet::noneOf($class);
$this->assertEquals($expected, $actual->toArray());
}
@@ -89,7 +97,7 @@ public function ofProvider(): array
public function testOf(Enum $class, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$actual = EnumSet::of($class);
$this->assertEquals($expected, $actual->toArray());
@@ -135,7 +143,7 @@ public function rangeProvider(): array
public function testRange(Enum $from, Enum $to, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$actual = EnumSet::range($from, $to);
$this->assertEquals($expected, $actual->toArray());
@@ -242,12 +250,12 @@ public function enumSetProvider(): array
public function testEnumSet(EnumSet $enumSet, array $enums, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
foreach ($enums as $enum) {
$enumSet[] = $enum;
}
- \assert(\is_array($expected));
+ assert(is_array($expected));
$this->assertEquals($expected, $enumSet->toArray());
$i = 0;
foreach ($enumSet as $enum) {
diff --git a/tests/EnumTest.php b/tests/EnumTest.php
index 05e5046..babfd9f 100644
--- a/tests/EnumTest.php
+++ b/tests/EnumTest.php
@@ -11,6 +11,12 @@
use Ngmy\Enum\Enum;
use ReflectionClass;
+use function assert;
+use function get_class;
+use function is_string;
+use function serialize;
+use function unserialize;
+
class EnumTest extends TestCase
{
/**
@@ -40,10 +46,10 @@ public function valueOfProvider(): array
public function testValueOf(string $class, string $name, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$actual = $class::valueOf($name);
- \assert(\is_string($expected));
+ assert(is_string($expected));
$this->assertInstanceOf($expected, $actual);
}
@@ -57,10 +63,10 @@ public function testValueOf(string $class, string $name, $expected): void
public function testMagicFactoryMethod(string $class, string $name, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$actual = $class::$name();
- \assert(\is_string($expected));
+ assert(is_string($expected));
$this->assertInstanceOf($expected, $actual);
}
@@ -86,7 +92,7 @@ public function valuesProvider(): array
}
/**
- * @param Exception|array $expected
+ * @param array|Exception $expected
* @dataProvider valuesProvider
*
* @phpstan-param class-string $class
@@ -95,7 +101,7 @@ public function valuesProvider(): array
public function testValues(string $class, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$this->assertEquals($expected, $class::values());
}
@@ -130,7 +136,7 @@ public function namesProvider(): array
}
/**
- * @param Exception|array $expected
+ * @param array|Exception $expected
* @dataProvider namesProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -141,7 +147,7 @@ public function namesProvider(): array
public function testNames(string $class, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$fromReflection = $class::names();
$fromCache = $class::names();
@@ -292,7 +298,7 @@ public function getInstanceProvider(): array
public function testGetInstance(string $class, $value, $expected): void
{
if ($expected instanceof Exception) {
- $this->expectException(\get_class($expected));
+ $this->expectException(get_class($expected));
}
$this->assertEquals($expected, $class::getInstance($value));
}
@@ -329,9 +335,9 @@ public function testSetter(): void
public function testUnserialize(): void
{
$foo = Data\Enum1::FOO();
- $serializedFoo = \serialize($foo);
+ $serializedFoo = serialize($foo);
$this->expectException(BadMethodCallException::class);
- \unserialize($serializedFoo);
+ unserialize($serializedFoo);
}
public function testClone(): void