Skip to content

Commit e7c2ec2

Browse files
Jakob Linskesederjaylinski
authored andcommitted
Fix PHPStan errors up to level 5
1 parent 23a3be6 commit e7c2ec2

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
php: [7.4, 8.0]
15+
php: ['7.4', '8.0']
1616

1717
runs-on: ubuntu-latest
1818
name: PHP@${{ matrix.php }}
@@ -32,3 +32,6 @@ jobs:
3232

3333
- name: Lint code
3434
run: composer run-script lint
35+
36+
- name: Analyse code
37+
run: composer run-script analyse

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [7.3, 7.4, 8.0]
16+
php: ['7.3', '7.4', '8.0']
1717

1818
runs-on: ubuntu-latest
1919
name: PHP@${{ matrix.php }}

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "^8.0 || ^9.0",
29-
"friendsofphp/php-cs-fixer": "^2.16"
29+
"friendsofphp/php-cs-fixer": "^2.16",
30+
"phpstan/phpstan": "^1.2"
3031
},
3132
"scripts": {
3233
"test": "phpunit",
3334
"coverage": "phpunit --coverage-clover coverage.xml",
3435
"lint": "php-cs-fixer fix -v --dry-run",
35-
"fix": "php-cs-fixer fix -v"
36+
"fix": "php-cs-fixer fix -v",
37+
"analyse": "phpstan analyse src --level 5"
3638
}
3739
}

src/Binding.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ abstract class Binding
1010
protected $property;
1111

1212
/**
13-
* @var string
13+
* @var ?string
1414
*/
1515
protected $jsonField;
1616

1717
/**
18-
* @var string
18+
* @var ?string
1919
*/
2020
protected $type;
2121

@@ -27,10 +27,10 @@ abstract class Binding
2727
/**
2828
* FieldBinding constructor.
2929
*
30-
* @param string $property the property to bind to
31-
* @param string $jsonField the json field
32-
* @param string $type the desired type of the property
33-
* @param bool $isRequired defines if the field value is required during decoding
30+
* @param string $property the property to bind to
31+
* @param ?string $jsonField the json field
32+
* @param ?string $type the desired type of the property
33+
* @param bool $isRequired defines if the field value is required during decoding
3434
*/
3535
public function __construct($property, $jsonField, $type, $isRequired = false)
3636
{
@@ -42,8 +42,6 @@ public function __construct($property, $jsonField, $type, $isRequired = false)
4242

4343
/**
4444
* validates the given binding data.
45-
*
46-
* @param mixed $jsonData
4745
*/
4846
public function validate(array $jsonData): bool
4947
{
@@ -69,7 +67,7 @@ public function jsonField(): string
6967
/**
7068
* executes the defined binding method on the class instance.
7169
*
72-
* @param mixed $jsonData
70+
* @param ?array $jsonData
7371
* @param Property $property the class instance to bind to
7472
*
7573
* @return mixed

src/Bindings/CallbackBinding.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class CallbackBinding extends Binding
1616

1717
/**
1818
* CallbackBinding constructor.
19-
*
20-
* @param string $property
21-
* @param Closure $callback
2219
*/
2320
public function __construct(string $property, Closure $callback)
2421
{

src/JsonDecoder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function ($element) use ($classType) {
103103
/**
104104
* decodes the given array data into an instance of the given class type.
105105
*
106-
* @param $jsonArrayData array
107-
* @param $classType string
106+
* @param array $jsonArrayData
107+
* @param string $classType
108108
*
109109
* @return mixed an instance of $classType
110110
*/
@@ -207,7 +207,7 @@ private function parseJson(string $json, string $root = null)
207207
*
208208
* @return array the list of generated bindings
209209
*
210-
* @throws ReflectionException
210+
* @throws \ReflectionException
211211
*/
212212
private function scan(string $class)
213213
{
@@ -243,6 +243,9 @@ private function scan(string $class)
243243
private function createTransformer(string $class, array $bindings): Transformer
244244
{
245245
return new class($class, $bindings) implements Transformer {
246+
private $class;
247+
private $bindings;
248+
246249
public function __construct($class, $bindings)
247250
{
248251
$this->class = $class;

src/Property.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Property
1818
private $propertyName;
1919

2020
/**
21-
* @var ReflectionProperty
21+
* @var ?ReflectionProperty
2222
*/
2323
private $property;
2424

@@ -28,7 +28,7 @@ class Property
2828
* @param mixed $instance the class instance the property lives in
2929
* @param string $propertyName the name of the property
3030
*
31-
* @return static
31+
* @return self
3232
*/
3333
public static function create($instance, string $propertyName)
3434
{
@@ -39,7 +39,7 @@ public static function create($instance, string $propertyName)
3939
} catch (Exception $ignored) {
4040
}
4141

42-
return new static($instance, $propertyName, $property);
42+
return new self($instance, $propertyName, $property);
4343
}
4444

4545
private function __construct($instance, string $propertyName, ReflectionProperty $property = null)

0 commit comments

Comments
 (0)