Skip to content

Commit bfd940c

Browse files
author
Robin de Graaf
committed
Add psalm
1 parent 5029e4a commit bfd940c

File tree

7 files changed

+45
-7
lines changed

7 files changed

+45
-7
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ jobs:
3232

3333
- name: Run test suite
3434
run: vendor/bin/phpunit tests
35+
36+
- name: Run static analysis
37+
run: vendor/bin/psalm

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
.DS_Store
12
.idea
23
composer.lock
34
vendor
4-
coverage
5+
coverage

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Parable PHP DI
22

3+
## 0.3.2
4+
5+
- Add static analysis using psalm.
6+
37
## 0.3.1
48

59
_Fixes_

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ dependencies:
44
--no-plugins \
55
--no-scripts
66

7+
psalm:
8+
vendor/bin/psalm --clear-cache
9+
vendor/bin/psalm
10+
711
tests: dependencies
812
vendor/bin/phpunit --verbose tests
913

@@ -13,3 +17,7 @@ coverage: dependencies
1317

1418
tests-clean:
1519
vendor/bin/phpunit --verbose tests
20+
21+
coverage-clean:
22+
rm -rf ./coverage
23+
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html ./coverage tests

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"php": ">=8.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^9.0"
19+
"phpunit/phpunit": "^9.0",
20+
"vimeo/psalm": "^4.6"
2021
},
2122
"autoload": {
2223
"psr-4": {

psalm.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
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+
16+
<issueHandlers>
17+
<UnresolvableInclude errorLevel="suppress" />
18+
</issueHandlers>
19+
</psalm>

src/Container.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Container
1515

1616
protected array $instances = [];
1717

18-
/** @var string[][] */
18+
/** @var bool[][] */
1919
protected array $relationships = [];
2020

2121
/** @var string[] */
@@ -98,7 +98,7 @@ protected function createInstance(string $name, int $useStoredDependencies): obj
9898
try {
9999
$dependencies = $this->getDependenciesFor($name, $useStoredDependencies);
100100
} catch (Throwable $t) {
101-
throw new ContainerException($t->getMessage(), $t->getCode(), $t);
101+
throw new ContainerException($t->getMessage(), (int)$t->getCode(), $t);
102102
}
103103

104104
return new $name(...$dependencies);
@@ -146,14 +146,14 @@ public function getDependenciesFor(
146146
'Could not create instance for class `%s`.',
147147
$name
148148
),
149-
$t->getCode(),
149+
(int)$t->getCode(),
150150
$t
151151
);
152152
}
153153

154154
$constructor = $reflection->getConstructor();
155155

156-
if (!$constructor) {
156+
if ($constructor === null) {
157157
return [];
158158
}
159159

@@ -172,7 +172,9 @@ public function getDependenciesFor(
172172
$class = null;
173173

174174
if ($parameter->getType() instanceof ReflectionNamedType && $builtIn === false) {
175-
$class = new ReflectionClass($parameter->getType()->getName());
175+
/** @var ReflectionNamedType $type */
176+
$type = $parameter->getType();
177+
$class = new ReflectionClass($type->getName());
176178
}
177179

178180
if ($class === null) {

0 commit comments

Comments
 (0)