Skip to content

Commit

Permalink
Add psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
devvoh committed Mar 11, 2021
1 parent 5029e4a commit bfd940c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Expand Up @@ -32,3 +32,6 @@ jobs:

- name: Run test suite
run: vendor/bin/phpunit tests

- name: Run static analysis
run: vendor/bin/psalm
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
.DS_Store
.idea
composer.lock
vendor
coverage
coverage
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Parable PHP DI

## 0.3.2

- Add static analysis using psalm.

## 0.3.1

_Fixes_
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Expand Up @@ -4,6 +4,10 @@ dependencies:
--no-plugins \
--no-scripts

psalm:
vendor/bin/psalm --clear-cache
vendor/bin/psalm

tests: dependencies
vendor/bin/phpunit --verbose tests

Expand All @@ -13,3 +17,7 @@ coverage: dependencies

tests-clean:
vendor/bin/phpunit --verbose tests

coverage-clean:
rm -rf ./coverage
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html ./coverage tests
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -16,7 +16,8 @@
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "^4.6"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 19 additions & 0 deletions psalm.xml
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<UnresolvableInclude errorLevel="suppress" />
</issueHandlers>
</psalm>
12 changes: 7 additions & 5 deletions src/Container.php
Expand Up @@ -15,7 +15,7 @@ class Container

protected array $instances = [];

/** @var string[][] */
/** @var bool[][] */
protected array $relationships = [];

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

return new $name(...$dependencies);
Expand Down Expand Up @@ -146,14 +146,14 @@ public function getDependenciesFor(
'Could not create instance for class `%s`.',
$name
),
$t->getCode(),
(int)$t->getCode(),
$t
);
}

$constructor = $reflection->getConstructor();

if (!$constructor) {
if ($constructor === null) {
return [];
}

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

if ($parameter->getType() instanceof ReflectionNamedType && $builtIn === false) {
$class = new ReflectionClass($parameter->getType()->getName());
/** @var ReflectionNamedType $type */
$type = $parameter->getType();
$class = new ReflectionClass($type->getName());
}

if ($class === null) {
Expand Down

0 comments on commit bfd940c

Please sign in to comment.