Skip to content

Commit 325be80

Browse files
committed
Fix Psalm issues
1 parent d9ca2ea commit 325be80

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

.github/workflows/tests.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ jobs:
2020
- php-version: '7.4'
2121
- php-version: '8.0'
2222
- php-version: '8.1'
23+
24+
#CS
2325
- php-version: '8.1'
2426
description: 'with Coding Standards'
2527
coding-standards: true
2628

29+
#Static Analysis (min PHP version)
30+
- php-version: '7.2'
31+
description: 'with Static Analysis'
32+
static-analysis: true
33+
2734
name: PHP ${{ matrix.php-version }} ${{ matrix.description }}
2835

2936
runs-on: 'ubuntu-latest'
@@ -61,7 +68,7 @@ jobs:
6168
run: composer update --no-interaction --no-progress ${{ matrix.composer-flags }}
6269

6370
- name: Run PHPUnit
64-
if: matrix.coding-standards != true
71+
if: matrix.coding-standards != true && matrix.static-analysis != true
6572
run: php vendor/phpunit/phpunit/phpunit
6673

6774
- name: Run PHP CS Fixer
@@ -77,3 +84,7 @@ jobs:
7784
- name: Check license year
7885
if: matrix.coding-standards
7986
run: cat LICENSE |grep -E "\(c\) ([0-9]+\-)*`date +%G`"
87+
88+
- name: Run Psalm
89+
if: matrix.static-analysis
90+
run: php vendor/bin/psalm --stats --output-format=github

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'ordered_imports' => true,
3535
'phpdoc_order' => true,
3636
'protected_to_private' => false,
37+
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']],
3738
])
3839
->setFinder($finder)
3940
;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"fakerphp/faker": "^1.9",
2929
"friendsofphp/php-cs-fixer": "^3.0",
3030
"phpunit/phpunit": "^8.4",
31-
"symfony/cache": "*"
31+
"symfony/cache": "*",
32+
"vimeo/psalm": "^4.23"
3233
},
3334
"extra": {
3435
"branch-alias": {

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="2"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src"/>
11+
<ignoreFiles>
12+
<directory name="vendor"/>
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/Exception/EntityNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class EntityNotFoundException extends \Exception implements ExceptionInterface
1717
{
18-
public static function fromClassNameAndIdentifier($className, array $id)
18+
public static function fromClassNameAndIdentifier(string $className, array $id): self
1919
{
2020
$ids = [];
2121

src/RefetchManager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public function getObject(object $object): object
5454
return $newObject;
5555
}
5656

57-
public function getCollectionFromCriteria(Criteria $criteria, $class): Collection
57+
/**
58+
* @psalm-param class-string $class
59+
*/
60+
public function getCollectionFromCriteria(Criteria $criteria, string $class): Collection
5861
{
5962
return $this->entityManager->getRepository($class)->matching($criteria);
6063
}
@@ -71,6 +74,7 @@ protected function getObjectMetadata(object $object): ClassMetadata
7174

7275
protected function getIdentifierFlattener(): IdentifierFlattener
7376
{
77+
/** @psalm-suppress InvalidArgument */
7478
return new IdentifierFlattener($this->entityManager->getUnitOfWork(), $this->entityManager->getMetadataFactory());
7579
}
7680
}

src/SnapshotManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ final class SnapshotManager
2323
*/
2424
private $entityManager;
2525

26+
/**
27+
* @var array|null
28+
*/
2629
private $snapshot;
2730

2831
public static function create(EntityManagerInterface $entityManager): self
@@ -53,6 +56,7 @@ public function clear(): void
5356

5457
$identityMap = $this->entityManager->getUnitOfWork()->getIdentityMap();
5558
foreach ($identityMap as $class => $objects) {
59+
/** @var object $object */
5660
foreach ($objects as $id => $object) {
5761
if (!\array_key_exists($class, $this->snapshot) || !\array_key_exists($id, $this->snapshot[$class])) {
5862
$this->entityManager->detach($object);

0 commit comments

Comments
 (0)