Skip to content

Commit 7dabfb1

Browse files
committed
Add psalm
1 parent 00e1917 commit 7dabfb1

File tree

9 files changed

+63
-13
lines changed

9 files changed

+63
-13
lines changed

.github/workflows/shepherd.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Shepherd
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
schedule:
9+
- cron: "0 17 * * *"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-18.04
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Install dependencies
19+
run: composer install --prefer-dist --no-progress --no-suggest
20+
21+
- name: Run Psalm
22+
run: vendor/bin/psalm --show-info=false --stats --output-format=github --shepherd --threads=$(nproc)

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
"phpstan/phpstan-phpunit": "0.12.10",
2626
"phpstan/phpstan-strict-rules": "0.12.4",
2727
"phpunit/phpunit": "^9.0",
28+
"psalm/plugin-phpunit": "^0.12.2",
2829
"simpod/php-coveralls-mirror": "^3.0",
29-
"thecodingmachine/phpstan-safe-rule": "^1.0"
30+
"thecodingmachine/phpstan-safe-rule": "^1.0",
31+
"vimeo/psalm": "^3.16"
3032
},
3133
"autoload": {
3234
"psr-4": {

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
totallyTyped="true"
5+
resolveFromConfigFile="true"
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+
<plugins>
16+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin" />
17+
</plugins>
18+
</psalm>

src/Builder/FieldBuilder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
class FieldBuilder
1111
{
12-
/** @var mixed[] */
13-
private $parameters;
12+
/** @var array<string, mixed|array<string|mixed>> */
13+
private $parameters = [];
1414

1515
final private function __construct(string $name, Type $type)
1616
{
@@ -51,6 +51,8 @@ public function addArgument(string $name, Type $type, ?string $description = nul
5151
}
5252

5353
/**
54+
* @see ResolveInfo
55+
*
5456
* @param callable(mixed, array<mixed>, mixed, ResolveInfo) : mixed $resolver
5557
*
5658
* @return static

src/Builder/ObjectBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class ObjectBuilder extends TypeBuilder
1515
/** @var callable|mixed[][] */
1616
private $fields = [];
1717

18-
/** @var callable(mixed, array<mixed>, mixed, ResolveInfo) : mixed */
19-
private $fieldResolver;
18+
/** @var callable(mixed, array<mixed>, mixed, ResolveInfo) : mixed|null */
19+
private $fieldResolver = null;
2020

2121
/**
2222
* @return static

src/Builder/TypeBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ abstract class TypeBuilder
1515
/** @var string */
1616
private $name;
1717

18-
/** @var string */
19-
private $description;
18+
/** @var string|null */
19+
private $description = null;
2020

2121
final protected function __construct(string $name)
2222
{

src/Builder/UnionBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class UnionBuilder extends TypeBuilder
1212
/** @var callable(object, mixed, ResolveInfo)|null */
1313
private $resolveType;
1414

15-
/** @var ObjectType[] */
16-
private $types;
15+
/** @var ObjectType[]|null */
16+
private $types = null;
1717

1818
/**
1919
* @return static

src/Error/FormattedError.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class FormattedError extends \GraphQL\Error\FormattedError
1414
*/
1515
public static function createFromException(Throwable $exception, int $debug = DebugFlag::NONE, $internalErrorMessage = null): array
1616
{
17+
/** @var array<string, array<string, mixed>> $arrayError */
1718
$arrayError = parent::createFromException($exception, $debug, $internalErrorMessage);
1819

1920
if ($exception instanceof \GraphQL\Error\Error && $exception->getPrevious() instanceof Error) {

src/Type/DateTimeType.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
use GraphQL\Language\AST\StringValueNode;
1212
use GraphQL\Type\Definition\CustomScalarType;
1313
use GraphQL\Utils\Utils;
14+
use InvalidArgumentException;
1415
use SimPod\GraphQLUtils\Exception\InvalidArgument;
1516

1617
use function assert;
18+
use function is_string;
1719
use function Safe\preg_match;
1820
use function Safe\substr;
1921
use function strpos;
@@ -59,6 +61,10 @@ public function serialize($value): string
5961
*/
6062
public function parseValue($value): DateTimeImmutable
6163
{
64+
if (! is_string($value)) {
65+
throw new InvalidArgumentException();
66+
}
67+
6268
if (! $this->validateDatetime($value)) {
6369
throw InvalidArgument::valueNotIso8601Compliant($value);
6470
}
@@ -67,18 +73,17 @@ public function parseValue($value): DateTimeImmutable
6773
}
6874

6975
/**
70-
* @param Node $node
7176
* @param mixed[]|null $variables
7277
*
7378
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
7479
*/
75-
public function parseLiteral($node, ?array $variables = null): ?DateTimeImmutable
80+
public function parseLiteral(Node $valueNode, ?array $variables = null): ?DateTimeImmutable
7681
{
77-
if (! $node instanceof StringValueNode) {
82+
if (! $valueNode instanceof StringValueNode) {
7883
return null;
7984
}
8085

81-
return $this->parseValue($node->value);
86+
return $this->parseValue($valueNode->value);
8287
}
8388

8489
private function validateDatetime(string $value): bool

0 commit comments

Comments
 (0)