Skip to content

Commit dd161ac

Browse files
PedroTrollertacman
andauthored
release (#180)
* Allow Symfony 6.2 (#177) * test: fix phpstan error (#179) * feat: remove support of versions of twig with security notices (#178) * refactor: fix phpstan error Co-authored-by: Tac Tacelosky <[email protected]>
1 parent c5cbd60 commit dd161ac

File tree

15 files changed

+54
-13
lines changed

15 files changed

+54
-13
lines changed

Diff for: .php-cs-fixer.dist.php

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
->disable('method_chaining_indentation')
3434
->disable('no_break_comment')
3535
->disable('no_superfluous_phpdoc_tags')
36+
->disable('phpdoc_to_comment')
3637
->getRules()
3738
);
3839

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
"symfony/http-foundation": "^5.4 || ^6.0",
2525
"symfony/http-kernel": "^5.4 || ^6.0",
2626
"symfony/validator": "^5.4 || ^6.0",
27-
"twig/twig": "^2.14.11 || ^3.3.8"
27+
"twig/twig": "^2.15.3 || ^3.4.3"
2828
},
2929
"require-dev": {
3030
"beberlei/assert": "^3.3",
3131
"fakerphp/faker": "^1.19",
3232
"friends-of-phpspec/phpspec-code-coverage": "^6.1",
33-
"friendsofphp/php-cs-fixer": "^3.8",
33+
"friendsofphp/php-cs-fixer": "^3.13",
3434
"pedrotroller/php-cs-custom-fixer": "^2.28",
3535
"phpspec/phpspec": "^7.2",
3636
"phpspec/prophecy": "^1.15",
37-
"phpstan/phpstan": "^1.7",
37+
"phpstan/phpstan": "^1.9",
3838
"symfony/twig-bridge": "^5.4 || ^6.0",
3939
"symfony/var-dumper": "^5.4 || ^6.0"
4040
},

Diff for: spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryRegistrationPassSpec.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ function it_is_initializable()
1919
$this->shouldHaveType(DictionaryRegistrationPass::class);
2020
}
2121

22-
function it_registers_dictionaries(ContainerBuilder $container, Definition $dictionaries, Definition $definition)
23-
{
22+
function it_registers_dictionaries(
23+
ContainerBuilder $container,
24+
Definition $dictionaries,
25+
Definition $definition
26+
) {
2427
$tags = ['foo' => [], 'bar' => [], 'baz' => []];
2528

2629
$container->getDefinition(Collection::class)->willReturn($dictionaries);

Diff for: src/Knp/DictionaryBundle/Dictionary.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* @template E
13+
*
1314
* @extends IteratorAggregate<mixed, E>
1415
* @extends ArrayAccess<mixed, E>
1516
*/

Diff for: src/Knp/DictionaryBundle/Dictionary/Collection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function offsetExists($offset): bool
4848
}
4949

5050
/**
51-
* @throws DictionaryNotFoundException
52-
*
5351
* @return Dictionary<mixed>
5452
* {@inheritdoc}
53+
*
54+
* @throws DictionaryNotFoundException
5555
*/
5656
public function offsetGet($offset): Dictionary
5757
{

Diff for: src/Knp/DictionaryBundle/Dictionary/Combined.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* @template E
11+
*
1112
* @extends Wrapper<E>
1213
*/
1314
final class Combined extends Wrapper

Diff for: src/Knp/DictionaryBundle/Dictionary/Invokable.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @template E
14+
*
1415
* @implements Dictionary<E>
1516
*/
1617
final class Invokable implements Dictionary

Diff for: src/Knp/DictionaryBundle/Dictionary/Iterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* @template E
11+
*
1112
* @extends Wrapper<E>
1213
*/
1314
final class Iterator extends Wrapper

Diff for: src/Knp/DictionaryBundle/Dictionary/Simple.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* @template E
13+
*
1314
* @implements Dictionary<E>
1415
*/
1516
final class Simple implements Dictionary

Diff for: src/Knp/DictionaryBundle/Dictionary/Traceable.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* @template E of mixed
13+
*
1314
* @implements Dictionary<E>
1415
*/
1516
final class Traceable implements Dictionary

Diff for: src/Knp/DictionaryBundle/Dictionary/Wrapper.php

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

1010
/**
1111
* @template E
12+
*
1213
* @implements Dictionary<E>
1314
*/
1415
abstract class Wrapper implements Dictionary

Diff for: src/Knp/DictionaryBundle/Validator/Constraints/Dictionary.php

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

1010
/**
1111
* @Annotation
12+
*
1213
* @Target({"PROPERTY", "METHOD"})
1314
*/
1415
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]

Diff for: src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Knp\DictionaryBundle\Validator\Constraints;
66

7+
use Exception;
78
use Knp\DictionaryBundle\Dictionary\Collection;
89
use Symfony\Component\Validator\ConstraintValidator;
910

@@ -42,6 +43,17 @@ private function varToString($var): string
4243
;
4344
}
4445

45-
return (string) $var;
46+
if (\is_object($var) && method_exists($var, '__toString')) {
47+
return $var->__toString();
48+
}
49+
50+
if (settype($var, 'string')) {
51+
/**
52+
* @var string $var
53+
*/
54+
return $var;
55+
}
56+
57+
throw new Exception('Unable to transform var to string.');
4658
}
4759
}

Diff for: src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator/SymfonyCompatibilityTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
default:
1515
throw new Exception('knplabs/dictionary-bundle is not compatible with the current version of symfony/validator: '.$version);
1616

17+
case '6.2':
1718
case '6.1':
1819
case '6.0':
1920
trait SymfonyCompatibilityTrait

Diff for: src/Knp/DictionaryBundle/ValueTransformer/Constant.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace Knp\DictionaryBundle\ValueTransformer;
66

7+
use Exception;
78
use Knp\DictionaryBundle\ValueTransformer;
89
use ReflectionClass;
910

1011
final class Constant implements ValueTransformer
1112
{
12-
private string $pattern = '/^(?P<class>.*)::(?P<constant>.*)$/';
13+
private const PATTERN = '/^(?P<class>.*)::(?P<constant>.*)$/';
1314

1415
public function supports($value): bool
1516
{
@@ -19,7 +20,7 @@ public function supports($value): bool
1920

2021
$matches = [];
2122

22-
if (0 === preg_match($this->pattern, $value, $matches)) {
23+
if (null === $matches = $this->extract($value)) {
2324
return false;
2425
}
2526

@@ -36,12 +37,27 @@ public function supports($value): bool
3637

3738
public function transform($value)
3839
{
39-
$matches = [];
40-
41-
preg_match($this->pattern, $value, $matches);
40+
if (null === $matches = $this->extract($value)) {
41+
throw new Exception("Unable to resolve constant {$value}.");
42+
}
4243

4344
return (new ReflectionClass($matches['class']))
4445
->getConstant($matches['constant'])
4546
;
4647
}
48+
49+
/**
50+
* @return ?array{class: class-string, constant: string}
51+
*/
52+
private function extract(string $value): ?array
53+
{
54+
if (preg_match(self::PATTERN, $value, $matches)) {
55+
/**
56+
* @var array{class: class-string, constant: string} $matches
57+
*/
58+
return $matches;
59+
}
60+
61+
return null;
62+
}
4763
}

0 commit comments

Comments
 (0)