Skip to content

Commit 54a7adb

Browse files
committed
Make php7.4 the minimum requirement, update dependencies, add psalm
1 parent 24c3f59 commit 54a7adb

9 files changed

+55
-15
lines changed

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: php
22

33
php:
4-
- "7.2"
5-
- "7.3"
6-
- "7.4snapshot"
4+
- "7.4"
75
- "nightly"
86

97
matrix:
@@ -12,6 +10,7 @@ matrix:
1210

1311
script:
1412
- composer tests
13+
- composer psalm
1514

1615
install:
1716
- travis_retry composer install --no-interaction --prefer-source

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"scn/hydrator-property-values": "Provides a set of easy-to-use property callbacks"
1414
},
1515
"require": {
16-
"php": "^7.2|^7.3|^7.4"
16+
"php": "^7.4|^8.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^8.2",
20-
"infection/infection": "^0.13.4"
19+
"phpunit/phpunit": "^9.4",
20+
"vimeo/psalm": "^3.17"
2121
},
2222
"autoload": {
2323
"psr-0": {
@@ -31,6 +31,7 @@
3131
},
3232
"scripts": {
3333
"tests": "@php vendor/bin/phpunit tests/",
34+
"psalm": "@php vendor/bin/psalm --no-suggestions --show-info=true --long-progress --stats",
3435
"coverage": "@php vendor/bin/phpunit tests/ --coverage-html build/coverage"
3536
}
3637
}

psalm.xml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="2"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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+
</psalm>

src/Scn/Hydrator/Configuration/ExtractorConfigInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66

77
interface ExtractorConfigInterface
88
{
9+
/**
10+
* @return array<array-key, callable>
11+
*/
912
public function getExtractorProperties(): array;
1013
}

src/Scn/Hydrator/Configuration/GenericExtractorConfig.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ final class GenericExtractorConfig implements ExtractorConfigInterface
88
{
99

1010
/**
11-
* @var array
11+
* @var array<array-key, callable>
1212
*/
13-
private $properties;
13+
private array $properties;
1414

15+
/**
16+
* @param array<array-key, callable> $propertyMapping
17+
*/
1518
public function __construct(array $propertyMapping)
1619
{
1720
$this->properties = $propertyMapping;
1821
}
1922

23+
/**
24+
* @return array<array-key, callable>
25+
*/
2026
public function getExtractorProperties(): array
2127
{
2228
return $this->properties;

src/Scn/Hydrator/Configuration/GenericHydratorConfig.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ final class GenericHydratorConfig implements HydratorConfigInterface
88
{
99

1010
/**
11-
* @var array
11+
* @var array<array-key, callable>
1212
*/
13-
private $properties;
13+
private array $properties;
1414

15+
/**
16+
* @param array<array-key, callable> $propertyMapping
17+
*/
1518
public function __construct(array $propertyMapping)
1619
{
1720
$this->properties = $propertyMapping;
1821
}
1922

23+
/**
24+
* @return array<array-key, callable>
25+
*/
2026
public function getHydratorProperties(): array
2127
{
2228
return $this->properties;

src/Scn/Hydrator/Configuration/HydratorConfigInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66

77
interface HydratorConfigInterface
88
{
9+
/**
10+
* @return array<array-key, callable>
11+
*/
912
public function getHydratorProperties(): array;
1013
}

src/Scn/Hydrator/Hydrator.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ final class Hydrator implements HydratorInterface
1212
{
1313

1414
public const NO_STRICT_KEYS = 0b00000001;
15-
public const IGNORE_KEYS = 0b00000010;
16-
public const DEFAULT = 0b00000000;
15+
public const IGNORE_KEYS = 0b00000010;
16+
public const DEFAULT = 0b00000000;
1717

18+
/**
19+
* @param callable $callback
20+
* @param object $entity
21+
* @param mixed ...$args
22+
*
23+
* @return mixed
24+
*/
1825
private function invoke(callable $callback, object $entity, ...$args)
1926
{
2027
if ($callback instanceof \Closure) {
21-
$callback = $callback->bindTo($entity, $entity);
28+
$callback = $callback->bindTo($entity, $entity) ?: $callback;
2229
}
2330

2431
return call_user_func_array($callback, $args);
@@ -33,7 +40,7 @@ public function hydrate(
3340
$hydratorProperties = $config->getHydratorProperties();
3441

3542
if ($flags & static::IGNORE_KEYS) {
36-
$data = array_combine(array_keys($hydratorProperties),$data);
43+
$data = array_combine(array_keys($hydratorProperties), $data);
3744
}
3845

3946
if (~$flags & static::NO_STRICT_KEYS) {
@@ -54,6 +61,7 @@ public function extract(ExtractorConfigInterface $config, object $entity): array
5461
$data = [];
5562

5663
foreach ($config->getExtractorProperties() as $propertyName => $get) {
64+
/** @psalm-suppress MixedAssignment */
5765
$data[$propertyName] = $this->invoke($get, $entity, $propertyName);
5866
}
5967

src/Scn/Hydrator/HydratorInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
interface HydratorInterface
1111
{
12-
1312
public function hydrate(HydratorConfigInterface $config, object $entity, array $data, int $flags = 0): void;
1413

1514
public function extract(ExtractorConfigInterface $config, object $entity): array;

0 commit comments

Comments
 (0)