From 54f2d481e825ccfb0558124ddf2f7ef8cc437b38 Mon Sep 17 00:00:00 2001 From: Julien Mercier-Rojas Date: Tue, 6 Jul 2021 11:54:29 +0200 Subject: [PATCH 1/5] Fix psalm errors --- .idea/identity-contract.iml | 1 + .idea/php.xml | 21 +++++++++++++++++++++ src/IdentityAbstract.php | 11 ++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.idea/identity-contract.iml b/.idea/identity-contract.iml index d9e7361..37ec3d1 100644 --- a/.idea/identity-contract.iml +++ b/.idea/identity-contract.iml @@ -63,6 +63,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index a9e2697..ac0502d 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,15 @@ + + + + + + + + + + @@ -61,7 +71,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/IdentityAbstract.php b/src/IdentityAbstract.php index 9b5232c..32b527b 100644 --- a/src/IdentityAbstract.php +++ b/src/IdentityAbstract.php @@ -32,6 +32,7 @@ abstract class IdentityAbstract implements Equality, Identity */ final public function __construct($id) { + /** @psalm-suppress UnusedMethodCall */ $this->validate($id); $this->id = $id; @@ -68,14 +69,14 @@ public function jsonSerialize() } /** - * @param mixed $id + * @param mixed $object * @return bool */ - public function equals($id): bool + public function equals($object): bool { - return is_object($id) - && \get_class($this) === \get_class($id) - && $this->id === $id->id; + return is_object($object) + && \get_class($this) === \get_class($object) + && $this->id === $object->id; } /** From c0a8cce981ade7c735f51da587364269f6cc87ff Mon Sep 17 00:00:00 2001 From: Julien Mercier-Rojas Date: Tue, 6 Jul 2021 12:00:52 +0200 Subject: [PATCH 2/5] Add phpstan checks --- .idea/identity-contract.iml | 1 + .idea/php.xml | 6 ++++++ composer.json | 3 ++- grumphp.yml | 3 +++ phpstan.neon | 6 ++++++ ruleset.xml | 15 +++++++++------ src/IdentityAbstract.php | 1 + 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 phpstan.neon diff --git a/.idea/identity-contract.iml b/.idea/identity-contract.iml index 37ec3d1..fe611b6 100644 --- a/.idea/identity-contract.iml +++ b/.idea/identity-contract.iml @@ -64,6 +64,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index ac0502d..d8dd240 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -72,9 +72,15 @@ + + + + + + diff --git a/composer.json b/composer.json index 40923e9..52ff764 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "vimeo/psalm": "^4.3", "squizlabs/php_codesniffer": "^3.5", "phpmd/phpmd": "^2.8", - "phpro/grumphp": "^0.19 || ^1.2.0" + "phpro/grumphp": "^0.19 || ^1.2.0", + "phpstan/phpstan": "^0.12.91" }, "suggest": { "vimeo/psalm": "Using psalm with this 'contract' will enable immutability and strong typing verification" diff --git a/grumphp.yml b/grumphp.yml index e0b6345..44fd8b5 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -13,3 +13,6 @@ grumphp: threads: 1 triggered_by: ['php'] show_info: true + phpstan: + configuration: phpstan.neon + use_grumphp_paths: true diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..436a067 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + checkGenericClassInNonGenericObjectType: false + level: 8 + paths: + - src + diff --git a/ruleset.xml b/ruleset.xml index e9e31e1..33f4e47 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -7,18 +7,21 @@ xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd"> - My custom rule set that checks my code... + Jeckel-Lab/Identity-Contract PHPMD RuleSet - - - - - + + + + + id + + + diff --git a/src/IdentityAbstract.php b/src/IdentityAbstract.php index 32b527b..3e63018 100644 --- a/src/IdentityAbstract.php +++ b/src/IdentityAbstract.php @@ -75,6 +75,7 @@ public function jsonSerialize() public function equals($object): bool { return is_object($object) + && $object instanceof self && \get_class($this) === \get_class($object) && $this->id === $object->id; } From e062d77eea4b63aafa02469928d8d6e62b17c7d3 Mon Sep 17 00:00:00 2001 From: Julien Mercier-Rojas Date: Tue, 6 Jul 2021 12:01:51 +0200 Subject: [PATCH 3/5] Add phpstan to github actions --- .github/workflows/validate.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ccd019a..0ebf353 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -62,3 +62,5 @@ jobs: run: composer install $COMPOSER_FLAGS --no-interaction --prefer-dist --dev - name: Psalm run: ./vendor/bin/psalm + - name: PHPStan + run: ./vendor/bin/phpstan -c phpstan.neon From 9493295ad2541b29900624c0b23f949d86870763 Mon Sep 17 00:00:00 2001 From: Julien Mercier-Rojas Date: Tue, 6 Jul 2021 12:02:35 +0200 Subject: [PATCH 4/5] Update ignore rules --- .gitignore | 3 +- .idea/.gitignore | 8 ---- .idea/identity-contract.iml | 72 ---------------------------- .idea/modules.xml | 8 ---- .idea/php.xml | 94 ------------------------------------- .idea/vcs.xml | 6 --- 6 files changed, 2 insertions(+), 189 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/identity-contract.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index c1ea462..fb2fcd8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea/ /vendor/ /composer.lock -/.phpcs-cache \ No newline at end of file +/.phpcs-cache diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/identity-contract.iml b/.idea/identity-contract.iml deleted file mode 100644 index fe611b6..0000000 --- a/.idea/identity-contract.iml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index f89592f..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index d8dd240..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 5f8b48f7ad08513f4070f429e248dfc81874d5d6 Mon Sep 17 00:00:00 2001 From: Julien Mercier-Rojas Date: Tue, 6 Jul 2021 12:12:40 +0200 Subject: [PATCH 5/5] Fix build --- .github/workflows/validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 0ebf353..0c412d3 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -63,4 +63,4 @@ jobs: - name: Psalm run: ./vendor/bin/psalm - name: PHPStan - run: ./vendor/bin/phpstan -c phpstan.neon + run: ./vendor/bin/phpstan