Skip to content

Commit

Permalink
Merge pull request #2 from Jeckel-Lab/feature/fix-psalm-error
Browse files Browse the repository at this point in the history
Fix psalm errors
  • Loading branch information
jeckel authored Jul 6, 2021
2 parents 8424795 + 5f8b48f commit 7416761
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 172 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/vendor/
/composer.lock
/.phpcs-cache
/.phpcs-cache
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

70 changes: 0 additions & 70 deletions .idea/identity-contract.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

67 changes: 0 additions & 67 deletions .idea/php.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ grumphp:
threads: 1
triggered_by: ['php']
show_info: true
phpstan:
configuration: phpstan.neon
use_grumphp_paths: true
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
checkGenericClassInNonGenericObjectType: false
level: 8
paths:
- src

15 changes: 9 additions & 6 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
My custom rule set that checks my code...
Jeckel-Lab/Identity-Contract PHPMD RuleSet
</description>

<rule ref="rulesets/cleancode.xml">
<exclude name="IfStatementAssignment" />
<exclude name="StaticAccess" />
</rule>

<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
</rule>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions">
<value>id</value>
</property>
</properties>
</rule>
</ruleset>
12 changes: 7 additions & 5 deletions src/IdentityAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class IdentityAbstract implements Equality, Identity
*/
final public function __construct($id)
{
/** @psalm-suppress UnusedMethodCall */
$this->validate($id);

$this->id = $id;
Expand Down Expand Up @@ -68,14 +69,15 @@ 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)
&& $object instanceof self
&& \get_class($this) === \get_class($object)
&& $this->id === $object->id;
}

/**
Expand Down

0 comments on commit 7416761

Please sign in to comment.