Skip to content

Commit ec07e3c

Browse files
committed
Add basic phpstan level 1 config/ci
1 parent f7cf6cc commit ec07e3c

File tree

6 files changed

+69
-8
lines changed

6 files changed

+69
-8
lines changed

.github/workflows/phpstan.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "PHPStan"
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
env:
8+
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
9+
10+
jobs:
11+
tests:
12+
name: "PHPStan"
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: "Checkout"
18+
uses: "actions/checkout@v2"
19+
20+
- name: "Install PHP"
21+
uses: "shivammathur/setup-php@v2"
22+
with:
23+
coverage: "none"
24+
extensions: "intl, zip"
25+
ini-values: "memory_limit=-1"
26+
php-version: "7.4"
27+
28+
- name: "Update dependencies"
29+
run: "composer update ${{ env.COMPOSER_FLAGS }}"
30+
31+
- name: Run PHPStan
32+
run: |
33+
composer require --dev phpstan/phpstan:^0.12.93 marc-mabe/php-enum-phpstan ${{ env.COMPOSER_FLAGS }}
34+
vendor/bin/phpstan analyse

phpstan-baseline.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^PHPDoc tag @throws with type JsonSchema\\\\Exception\\\\ExceptionInterface is not subtype of Throwable$#"
5+
count: 1
6+
path: src/JsonSchema/Constraints/ConstraintInterface.php
7+
8+
-
9+
message: "#^Access to an undefined property object\\:\\:\\$properties\\.$#"
10+
count: 3
11+
path: src/JsonSchema/SchemaStorage.php
12+

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 2
3+
paths:
4+
- ./src/
5+
ignoreErrors: []
6+
7+
includes:
8+
- phpstan-baseline.neon
9+
- vendor/marc-mabe/php-enum-phpstan/extension.neon

src/JsonSchema/Constraints/Constraint.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null,
8787
protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null,
8888
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
8989
{
90+
/** @var ObjectConstraint $validator */
9091
$validator = $this->factory->createInstanceFor('object');
9192
$validator->check($value, $schema, $path, $properties, $additionalProperties, $patternProperties, $appliedDefaults);
9293

@@ -119,6 +120,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null,
119120
*/
120121
protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
121122
{
123+
/** @var UndefinedConstraint $validator */
122124
$validator = $this->factory->createInstanceFor('undefined');
123125

124126
$validator->check($value, $this->factory->getSchemaStorage()->resolveRefSchema($schema), $path, $i, $fromDefault);

src/JsonSchema/Constraints/Factory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ public function setConstraintClass($name, $class)
185185
* @throws InvalidArgumentException if is not possible create the constraint instance
186186
*
187187
* @return ConstraintInterface|ObjectConstraint
188+
* @phpstan-return ConstraintInterface&BaseConstraint
188189
*/
189190
public function createInstanceFor($constraintName)
190191
{
@@ -202,7 +203,8 @@ public function createInstanceFor($constraintName)
202203
/**
203204
* Get the error context
204205
*
205-
* @return string
206+
* @return int
207+
* @phpstan-return Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION
206208
*/
207209
public function getErrorContext()
208210
{
@@ -212,7 +214,8 @@ public function getErrorContext()
212214
/**
213215
* Set the error context
214216
*
215-
* @param string $validationContext
217+
* @param int $errorContext
218+
* @phpstan-param Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION $errorContext
216219
*/
217220
public function setErrorContext($errorContext)
218221
{

src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ public function check(&$value = null, $schema = null, JsonPointer $path = null,
8181
* of $isValid to true, if at least one $type mateches the type of $value or the value
8282
* passed as $isValid is already true.
8383
*
84-
* @param mixed $value Value to validate
85-
* @param array $type TypeConstraints to check against
86-
* @param array $validTypesWording An array of wordings of the valid types of the array $type
87-
* @param bool $isValid The current validation value
88-
* @param $path
84+
* @param mixed $value Value to validate
85+
* @param array $type TypeConstraints to check against
86+
* @param array $validTypesWording An array of wordings of the valid types of the array $type
87+
* @param bool $isValid The current validation value
88+
* @param ?JsonPointer $path
89+
* @param bool $coerce
8990
*/
9091
protected function validateTypesArray(&$value, array $type, &$validTypesWording, &$isValid, $path, $coerce = false)
9192
{
@@ -239,7 +240,7 @@ protected function validateType(&$value, $type, $coerce = false)
239240
/**
240241
* Converts a value to boolean. For example, "true" becomes true.
241242
*
242-
* @param $value The value to convert to boolean
243+
* @param mixed $value The value to convert to boolean
243244
*
244245
* @return bool|mixed
245246
*/

0 commit comments

Comments
 (0)