Skip to content

Commit e46d7c4

Browse files
authored
Run basic psalm step in CI (#1062)
1 parent a57544f commit e46d7c4

21 files changed

+154
-9
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ phpbench.json export-ignore
1616
phpstan.neon.dist export-ignore
1717
phpstan-baseline.neon export-ignore
1818
phpunit.xml.dist export-ignore
19+
psalm.xml.dist export-ignore
20+
psalm-baseline.xml export-ignore

.github/workflows/static-analysis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,29 @@ jobs:
3434

3535
- name: "Run a static analysis with phpstan/phpstan"
3636
run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr"
37+
38+
static-analysis-psalm:
39+
name: "Static Analysis with Psalm"
40+
runs-on: "ubuntu-20.04"
41+
42+
strategy:
43+
matrix:
44+
php-version:
45+
- "8.1"
46+
47+
steps:
48+
- name: "Checkout code"
49+
uses: "actions/checkout@v2"
50+
51+
- name: "Install PHP"
52+
uses: "shivammathur/setup-php@v2"
53+
with:
54+
coverage: "none"
55+
php-version: "${{ matrix.php-version }}"
56+
tools: "cs2pr"
57+
58+
- name: "Install dependencies with Composer"
59+
uses: "ramsey/composer-install@v2"
60+
61+
- name: "Run a static analysis with vimeo/psalm"
62+
run: "vendor/bin/psalm --output-format=github --shepherd"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
composer.lock
44
composer.phar
55
phpstan.neon
6+
psalm.xml
67
vendor
78
.idea

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![CI](https://github.com/webonyx/graphql-php/workflows/CI/badge.svg)](https://github.com/webonyx/graphql-php/actions?query=workflow:CI+branch:master)
44
[![Coverage Status](https://codecov.io/gh/webonyx/graphql-php/branch/master/graph/badge.svg)](https://codecov.io/gh/webonyx/graphql-php/branch/master)
55
[![Latest Stable Version](https://poser.pugx.org/webonyx/graphql-php/version)](https://packagist.org/packages/webonyx/graphql-php)
6+
[![Shepherd Type](https://shepherd.dev/github/webonyx/graphql-php/coverage.svg)](ttps://shepherd.dev/github/webonyx/graphql-php)
67

78
This is a PHP implementation of the GraphQL [specification](https://github.com/graphql/graphql-spec)
89
based on the [reference implementation in JavaScript](https://github.com/graphql/graphql-js).

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
"phpstan/phpstan-phpunit": "^1",
2727
"phpstan/phpstan-strict-rules": "^1",
2828
"phpunit/phpunit": "^9.5",
29+
"psalm/plugin-phpunit": "^0.16.1",
2930
"psr/http-message": "^1",
3031
"react/promise": "^2",
3132
"symfony/polyfill-php81": "^1.23",
3233
"symfony/var-exporter": "^5.3",
33-
"thecodingmachine/safe": "^1.3"
34+
"thecodingmachine/safe": "^1.3",
35+
"vimeo/psalm": "^4.19"
3436
},
3537
"suggest": {
3638
"psr/http-message": "To use standard GraphQL server",
@@ -50,6 +52,7 @@
5052
},
5153
"config": {
5254
"allow-plugins": {
55+
"composer/package-versions-deprecated": true,
5356
"ergebnis/composer-normalize": true,
5457
"phpstan/extension-installer": true
5558
},

psalm-baseline.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.19.0@a2ad69ae4f5ab1f7d225a8dc4e2ec2d9415ed599">
3+
<file src="src/Language/Lexer.php">
4+
<InvalidParamDefault occurrences="1">
5+
<code>ParserOptions</code>
6+
</InvalidParamDefault>
7+
<InvalidTypeImport occurrences="1">
8+
<code>ParserOptions from Parser</code>
9+
</InvalidTypeImport>
10+
</file>
11+
<file src="src/Language/Parser.php">
12+
<UndefinedDocblockClass occurrences="5">
13+
<code>ParserOptions</code>
14+
<code>ParserOptions</code>
15+
<code>ParserOptions</code>
16+
<code>ParserOptions</code>
17+
<code>array{string, ParserOptions}</code>
18+
</UndefinedDocblockClass>
19+
</file>
20+
<file src="src/Language/Visitor.php">
21+
<EmptyArrayAccess occurrences="1">
22+
<code>$path[count($path) - 1]</code>
23+
</EmptyArrayAccess>
24+
</file>
25+
<file src="src/Type/Definition/FieldDefinition.php">
26+
<UndefinedDocblockClass occurrences="5">
27+
<code>$this-&gt;config</code>
28+
<code>ComplexityFn|null</code>
29+
<code>FieldDefinitionConfig</code>
30+
<code>FieldsConfig</code>
31+
<code>array</code>
32+
</UndefinedDocblockClass>
33+
</file>
34+
<file src="src/Type/Definition/InterfaceType.php">
35+
<InvalidTypeImport occurrences="1">
36+
<code>FieldsConfig from FieldDefinition</code>
37+
</InvalidTypeImport>
38+
</file>
39+
<file src="src/Type/Definition/UnresolvedFieldDefinition.php">
40+
<InvalidTypeImport occurrences="1">
41+
<code>UnnamedFieldDefinitionConfig from FieldDefinition</code>
42+
</InvalidTypeImport>
43+
</file>
44+
<file src="src/Utils/ASTDefinitionBuilder.php">
45+
<InvalidTypeImport occurrences="1">
46+
<code>UnnamedFieldDefinitionConfig from FieldDefinition</code>
47+
</InvalidTypeImport>
48+
</file>
49+
<file src="src/Utils/BuildClientSchema.php">
50+
<InvalidTypeImport occurrences="1">
51+
<code>UnnamedFieldDefinitionConfig from FieldDefinition</code>
52+
</InvalidTypeImport>
53+
</file>
54+
</files>

psalm.xml.dist

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

src/Error/FormattedError.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* It converts PHP exceptions to [spec-compliant errors](https://facebook.github.io/graphql/#sec-Errors)
3434
* and provides tools for error debugging.
3535
*
36+
* @see ExecutionResult
37+
*
3638
* @phpstan-import-type SerializableError from ExecutionResult
3739
* @phpstan-import-type ErrorFormatter from ExecutionResult
3840
*/

src/Error/Warning.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* Also, it is possible to override warning handler (which is **trigger_error()** by default).
1515
*
1616
* @phpstan-type WarningHandler callable(string $errorMessage, int $warningId, ?int $messageLevel): void
17+
*
18+
* @see https://github.com/vimeo/psalm/issues/7527
19+
* @psalm-type WarningHandler callable(string, int, int|null): void
1720
*/
1821
final class Warning
1922
{

src/Executor/ExecutionResult.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Could be converted to [spec-compliant](https://facebook.github.io/graphql/#sec-Response-Format)
2020
* serializable array using `toArray()`.
2121
*
22+
* @see Throwable
23+
*
2224
* @phpstan-type SerializableError array{
2325
* message: string,
2426
* locations?: array<int, array{line: int, column: int}>,
@@ -33,6 +35,9 @@
3335
* }
3436
* @phpstan-type ErrorFormatter callable(Throwable): SerializableError
3537
* @phpstan-type ErrorsHandler callable(array<Error> $errors, ErrorFormatter $formatter): SerializableErrors
38+
*
39+
* @see https://github.com/vimeo/psalm/issues/6928
40+
* @psalm-type ErrorsHandler callable(Error[], ErrorFormatter): SerializableErrors
3641
*/
3742
class ExecutionResult implements JsonSerializable
3843
{

0 commit comments

Comments
 (0)