Skip to content

Commit c62810a

Browse files
committed
update dependencies
1 parent b291259 commit c62810a

12 files changed

+52
-76
lines changed

composer-unused.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ComposerUnused\ComposerUnused\Configuration\Configuration;
6+
use ComposerUnused\ComposerUnused\Configuration\NamedFilter;
7+
8+
return static function (Configuration $config): Configuration {
9+
return $config
10+
->addNamedFilter(NamedFilter::fromString('symfony/yaml'));
11+
};

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"symfony/property-access": "^4.4|^5.4|^6.0",
4343
"symfony/property-info": "^4.4|^5.4|^6.0",
4444

45-
"doctrine/persistence": "^1.3|^2.0",
45+
"doctrine/persistence": "^1.3|^2.0|^3.0",
4646
"webmozart/assert": "^1.9"
4747
},
4848
"require-dev": {
@@ -73,7 +73,7 @@
7373
"scripts": {
7474
"check": [
7575
"@crc",
76-
"@unuse",
76+
"@unused",
7777
"@cs-fix",
7878
"@cs-check",
7979
"@phpstan",
@@ -85,7 +85,7 @@
8585
"phpunit": "phpunit --colors=always",
8686
"cs-check": "phpcs -s",
8787
"cs-fix": "phpcbf",
88-
"unuse": "composer unused --excludeDir=vendor --excludeDir=var --excludeDir=node_modules --ansi"
88+
"unused": "vendor/bin/composer-unused"
8989
},
9090
"extra": {
9191
"branch-alias": {

phpstan-baseline.neon

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,6 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:getValue\\(\\) expects array\\|object, mixed given\\.$#"
5-
count: 1
6-
path: src/Form/DataTransformer/ObjectToIdTransformer.php
7-
8-
-
9-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:isReadable\\(\\) expects array\\|object, mixed given\\.$#"
10-
count: 1
11-
path: src/Form/DataTransformer/ObjectToIdTransformer.php
12-
13-
-
14-
message: "#^Parameter \\#4 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
15-
count: 1
16-
path: src/Form/DataTransformer/ObjectToIdTransformer.php
17-
18-
-
19-
message: "#^Return type \\(mixed\\) of method Shapecode\\\\Bundle\\\\HiddenEntityTypeBundle\\\\Form\\\\DataTransformer\\\\ObjectToIdTransformer\\:\\:transform\\(\\) should be covariant with return type \\(string\\|null\\) of method Symfony\\\\Component\\\\Form\\\\DataTransformerInterface\\<object,string\\>\\:\\:transform\\(\\)$#"
20-
count: 2
21-
path: src/Form/DataTransformer/ObjectToIdTransformer.php
22-
23-
-
24-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
25-
count: 1
26-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
27-
28-
-
29-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:getValue\\(\\) expects array\\|object, mixed given\\.$#"
30-
count: 1
31-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
32-
33-
-
34-
message: "#^Parameter \\#1 \\$objectOrArray of method Symfony\\\\Component\\\\PropertyAccess\\\\PropertyAccessor\\:\\:isReadable\\(\\) expects array\\|object, mixed given\\.$#"
35-
count: 1
36-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
37-
38-
-
39-
message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#"
40-
count: 1
41-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
42-
43-
-
44-
message: "#^Parameter \\#4 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
45-
count: 1
46-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
47-
48-
-
49-
message: "#^Return type \\(mixed\\) of method Shapecode\\\\Bundle\\\\HiddenEntityTypeBundle\\\\Form\\\\DataTransformer\\\\ObjectsToIdTransformer\\:\\:transform\\(\\) should be covariant with return type \\(string\\|null\\) of method Symfony\\\\Component\\\\Form\\\\DataTransformerInterface\\<array\\<object\\>,string\\>\\:\\:transform\\(\\)$#"
50-
count: 2
51-
path: src/Form/DataTransformer/ObjectsToIdTransformer.php
52-
53-
-
54-
message: "#^PHPDoc tag @param for parameter \\$class contains unresolvable type\\.$#"
4+
message: "#^Method Shapecode\\\\Bundle\\\\HiddenEntityTypeBundle\\\\Form\\\\DataTransformer\\\\Transformer\\:\\:getRepository\\(\\) return type with generic interface Doctrine\\\\Persistence\\\\ObjectRepository does not specify its types\\: T$#"
555
count: 1
566
path: src/Form/DataTransformer/Transformer.php
57-
58-
-
59-
message: "#^PHPDoc tag @var for variable \\$class contains unresolvable type\\.$#"
60-
count: 1
61-
path: src/Form/Type/HiddenObjectType.php
62-

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ includes:
1010
- phpstan-baseline.neon
1111

1212
parameters:
13-
checkMissingIterableValueType: false
14-
checkGenericClassInNonGenericObjectType: false
1513
level: max
1614
paths:
1715
- src

src/Form/DataTransformer/ObjectToIdTransformer.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
namespace Shapecode\Bundle\HiddenEntityTypeBundle\Form\DataTransformer;
66

7+
use LogicException;
78
use Symfony\Component\Form\Exception\TransformationFailedException;
89
use Symfony\Component\PropertyAccess\PropertyAccess;
910
use Webmozart\Assert\Assert;
1011

12+
use function is_numeric;
13+
use function is_string;
1114
use function sprintf;
1215

1316
/**
@@ -16,9 +19,9 @@
1619
class ObjectToIdTransformer extends Transformer
1720
{
1821
/**
19-
* @param object|mixed $entity
22+
* @phpstan-param object|null $entity
2023
*
21-
* @return mixed|string
24+
* @phpstan-return string|null
2225
*/
2326
public function transform($entity)
2427
{
@@ -35,11 +38,23 @@ public function transform($entity)
3538
return null;
3639
}
3740

38-
return $accessor->getValue($entity, $property);
41+
$value = $accessor->getValue($entity, $property);
42+
43+
if ($value === null) {
44+
return null;
45+
}
46+
47+
if (! is_string($value) && ! is_numeric($value)) {
48+
throw new LogicException('id hast to be string or integer', 1653564596059);
49+
}
50+
51+
return (string) $value;
3952
}
4053

4154
/**
42-
* @param string|mixed $id
55+
* @phpstan-param string|null $id
56+
*
57+
* @phpstan-return object|null
4358
*/
4459
public function reverseTransform($id): ?object
4560
{

src/Form/DataTransformer/ObjectsToIdTransformer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
class ObjectsToIdTransformer extends Transformer
2020
{
2121
/**
22-
* @param object[]|mixed $entity
22+
* @phpstan-param object[]|null $entity
2323
*
24-
* @return string|mixed
24+
* @phpstan-return string|null
2525
*/
2626
public function transform($entity)
2727
{
@@ -48,9 +48,9 @@ public function transform($entity)
4848
}
4949

5050
/**
51-
* @param string|mixed $id
51+
* @phpstan-param string|null $id
5252
*
53-
* @return object[]
53+
* @phpstan-return object[]
5454
*/
5555
public function reverseTransform($id): array
5656
{

src/Form/DataTransformer/Transformer.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
use Doctrine\Persistence\ManagerRegistry;
88
use Doctrine\Persistence\ObjectRepository;
9+
use InvalidArgumentException;
910
use Symfony\Component\Form\DataTransformerInterface;
1011
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
1112
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1213
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
13-
use Webmozart\Assert\Assert;
1414

15+
use function class_exists;
1516
use function in_array;
1617
use function sprintf;
1718

@@ -30,14 +31,16 @@ abstract class Transformer implements DataTransformerInterface
3031
protected string $property;
3132

3233
/**
33-
* @param string<class-string> $class
34+
* @param class-string $class
3435
*/
3536
public function __construct(
3637
ManagerRegistry $registry,
3738
string $class,
3839
string $property = 'id'
3940
) {
40-
Assert::classExists($class);
41+
if (! class_exists($class)) {
42+
throw new InvalidArgumentException(sprintf('Expected an existing class name. Got: "%s"', $class));
43+
}
4144

4245
$this->registry = $registry;
4346
$this->class = $class;

src/Form/Type/HiddenObjectType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
3131
{
3232
$transformerClassName = $options['multiple'] === true ? ObjectsToIdTransformer::class : ObjectToIdTransformer::class;
3333

34-
/** @var string<class-string> $class */
34+
/** @phpstan-var class-string $class */
3535
$class = $options['class'];
3636

3737
$property = $options['property'];

tests/Form/DataTransformer/ObjectToIdTransformerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function testInvalidArray(): void
120120
$this->expectException(InvalidArgumentException::class);
121121
$this->expectExceptionMessage('Expected an instance of Shapecode\Bundle\HiddenEntityTypeBundle\Tests\Model\TestObject. Got: array');
122122

123+
// @phpstan-ignore-next-line
123124
$transformer->transform([$object]);
124125
}
125126

@@ -130,6 +131,7 @@ public function testInvalidClass(): void
130131
$this->expectException(InvalidArgumentException::class);
131132
$this->expectExceptionMessage('Expected an existing class name. Got: "FakeClass"');
132133

134+
// @phpstan-ignore-next-line
133135
new ObjectToIdTransformer($registry, 'FakeClass', 'name');
134136
}
135137
}

tests/Form/DataTransformer/ObjectsToIdTransformerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function testInvalidArray(): void
107107
$this->expectException(InvalidArgumentException::class);
108108
$this->expectExceptionMessage('Expected an iterable. Got: Shapecode\Bundle\HiddenEntityTypeBundle\Tests\Model\TestFormModel');
109109

110+
// @phpstan-ignore-next-line
110111
$transformer->transform($object);
111112
}
112113
}

0 commit comments

Comments
 (0)