Skip to content

Commit e260c33

Browse files
committed
Cleanup code and ci scripts
Upgrade to the latest psalm Use psalm/phar fix some static analisys issues.
1 parent 9dc0f90 commit e260c33

File tree

9 files changed

+66
-24
lines changed

9 files changed

+66
-24
lines changed

.github/workflows/push.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jobs:
177177
matrix:
178178
operating-system:
179179
- ubuntu-latest
180-
php-versions: ['7.2']
180+
php-versions: ['7.3']
181181
env:
182182
extensions: mbstring
183183
key: cache-v1 # can be any string, change to clear the extension cache.
@@ -207,7 +207,6 @@ jobs:
207207
with:
208208
php-version: ${{ matrix.php-versions }}
209209
extensions: ${{ env.extensions }}
210-
tools: psalm
211210
ini-values: memory_limit=2G, display_errors=On, error_reporting=-1
212211

213212
- name: Get composer cache directory
@@ -225,7 +224,7 @@ jobs:
225224
run: composer install --no-interaction --prefer-dist --optimize-autoloader
226225

227226
- name: Run psalm
228-
run: psalm --output-format=github
227+
run: vendor/bin/psalm.phar
229228

230229
bc_check:
231230
name: BC Check

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ phpstan:
2525

2626
.PHONY: psalm
2727
psalm:
28-
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/psalm
28+
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.3 vendor/bin/psalm.phar
2929

3030
.PHONY: test
3131
test:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"phpdocumentor/reflection-common": "^2.0"
1515
},
1616
"require-dev": {
17-
"ext-tokenizer": "*"
17+
"ext-tokenizer": "*",
18+
"psalm/phar": "^4.8"
1819
},
1920
"autoload": {
2021
"psr-4": {

composer.lock

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phive.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
33
<phar name="phpunit" version="^8.4" installed="8.4.3" location="./tools/phpunit" copy="true"/>
4-
<phar name="psalm" version="^3.7.2" installed="3.16" location="./tools/psalm" copy="true"/>
54
</phive>

phpstan.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
parameters:
22
level: max
3-
4-
ignoreErrors:
5-
# Bug in PHPStan? The error is "expects A, A given"
6-
- '#Parameter \#1 \$tokens of method phpDocumentor\\Reflection\\Types\\ContextFactory::parse#'
7-
# ArrayIterator::current can return null if iterated even if ArrayIterator::valid isn't checked before

psalm.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
</projectFiles>
1414

1515
<issueHandlers>
16+
<UnnecessaryVarAnnotation>
17+
<errorLevel type="info">
18+
<file name="src/Types/ContextFactory.php"/>
19+
</errorLevel>
20+
</UnnecessaryVarAnnotation>
21+
<UnusedMethodCall>
22+
<errorLevel type="suppress">
23+
<referencedMethod name="phpDocumentor\Reflection\Types\AggregatedType::add"/>
24+
</errorLevel>
25+
</UnusedMethodCall>
1626
<DocblockTypeContradiction>
1727
<errorLevel type="info">
1828
<!-- ArrayIterator::current can return null if iterated even if ArrayIterator::valid isn't checked before -->

src/TypeResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,15 @@ public function addKeyword(string $keyword, string $typeClassName) : void
348348
);
349349
}
350350

351-
if (!in_array(Type::class, class_implements($typeClassName), true)) {
351+
$interfaces = class_implements($typeClassName);
352+
if ($interfaces === false) {
353+
throw new InvalidArgumentException(
354+
'The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class'
355+
. ' but we could not find the class ' . $typeClassName
356+
);
357+
}
358+
359+
if (!in_array(Type::class, $interfaces, true)) {
352360
throw new InvalidArgumentException(
353361
'The class "' . $typeClassName . '" must implement the interface "phpDocumentor\Reflection\Type"'
354362
);

src/Types/ContextFactory.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,18 @@ private function createFromReflectionParameter(ReflectionParameter $parameter) :
108108
throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName());
109109
}
110110

111-
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
112-
/** @var ReflectionClass<object> $class */
113-
114111
return $this->createFromReflectionClass($class);
115112
}
116113

117114
private function createFromReflectionMethod(ReflectionMethod $method) : Context
118115
{
119-
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
120-
/** @var ReflectionClass<object> $class */
121116
$class = $method->getDeclaringClass();
122117

123118
return $this->createFromReflectionClass($class);
124119
}
125120

126121
private function createFromReflectionProperty(ReflectionProperty $property) : Context
127122
{
128-
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
129-
/** @var ReflectionClass<object> $class */
130123
$class = $property->getDeclaringClass();
131124

132125
return $this->createFromReflectionClass($class);
@@ -135,14 +128,14 @@ private function createFromReflectionProperty(ReflectionProperty $property) : Co
135128
private function createFromReflectionClassConstant(ReflectionClassConstant $constant) : Context
136129
{
137130
//phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable
138-
/** @var ReflectionClass<object> $class */
131+
/** @phpstan-var ReflectionClass<object> $class */
139132
$class = $constant->getDeclaringClass();
140133

141134
return $this->createFromReflectionClass($class);
142135
}
143136

144137
/**
145-
* @param ReflectionClass<object> $class
138+
* @phpstan-param ReflectionClass<object> $class
146139
*/
147140
private function createFromReflectionClass(ReflectionClass $class) : Context
148141
{

0 commit comments

Comments
 (0)