Skip to content

Commit

Permalink
release (#180)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
PedroTroller and tacman authored Nov 7, 2022
1 parent c5cbd60 commit dd161ac
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 13 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
->disable('method_chaining_indentation')
->disable('no_break_comment')
->disable('no_superfluous_phpdoc_tags')
->disable('phpdoc_to_comment')
->getRules()
);

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"twig/twig": "^2.14.11 || ^3.3.8"
"twig/twig": "^2.15.3 || ^3.4.3"
},
"require-dev": {
"beberlei/assert": "^3.3",
"fakerphp/faker": "^1.19",
"friends-of-phpspec/phpspec-code-coverage": "^6.1",
"friendsofphp/php-cs-fixer": "^3.8",
"friendsofphp/php-cs-fixer": "^3.13",
"pedrotroller/php-cs-custom-fixer": "^2.28",
"phpspec/phpspec": "^7.2",
"phpspec/prophecy": "^1.15",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan": "^1.9",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/var-dumper": "^5.4 || ^6.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ function it_is_initializable()
$this->shouldHaveType(DictionaryRegistrationPass::class);
}

function it_registers_dictionaries(ContainerBuilder $container, Definition $dictionaries, Definition $definition)
{
function it_registers_dictionaries(
ContainerBuilder $container,
Definition $dictionaries,
Definition $definition
) {
$tags = ['foo' => [], 'bar' => [], 'baz' => []];

$container->getDefinition(Collection::class)->willReturn($dictionaries);
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* @template E
*
* @extends IteratorAggregate<mixed, E>
* @extends ArrayAccess<mixed, E>
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Knp/DictionaryBundle/Dictionary/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function offsetExists($offset): bool
}

/**
* @throws DictionaryNotFoundException
*
* @return Dictionary<mixed>
* {@inheritdoc}
*
* @throws DictionaryNotFoundException
*/
public function offsetGet($offset): Dictionary
{
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Combined.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @template E
*
* @extends Wrapper<E>
*/
final class Combined extends Wrapper
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Invokable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @template E
*
* @implements Dictionary<E>
*/
final class Invokable implements Dictionary
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @template E
*
* @extends Wrapper<E>
*/
final class Iterator extends Wrapper
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* @template E
*
* @implements Dictionary<E>
*/
final class Simple implements Dictionary
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Traceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* @template E of mixed
*
* @implements Dictionary<E>
*/
final class Traceable implements Dictionary
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* @template E
*
* @implements Dictionary<E>
*/
abstract class Wrapper implements Dictionary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* @Annotation
*
* @Target({"PROPERTY", "METHOD"})
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Knp\DictionaryBundle\Validator\Constraints;

use Exception;
use Knp\DictionaryBundle\Dictionary\Collection;
use Symfony\Component\Validator\ConstraintValidator;

Expand Down Expand Up @@ -42,6 +43,17 @@ private function varToString($var): string
;
}

return (string) $var;
if (\is_object($var) && method_exists($var, '__toString')) {
return $var->__toString();
}

if (settype($var, 'string')) {
/**
* @var string $var
*/
return $var;
}

throw new Exception('Unable to transform var to string.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
default:
throw new Exception('knplabs/dictionary-bundle is not compatible with the current version of symfony/validator: '.$version);

case '6.2':
case '6.1':
case '6.0':
trait SymfonyCompatibilityTrait
Expand Down
26 changes: 21 additions & 5 deletions src/Knp/DictionaryBundle/ValueTransformer/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Knp\DictionaryBundle\ValueTransformer;

use Exception;
use Knp\DictionaryBundle\ValueTransformer;
use ReflectionClass;

final class Constant implements ValueTransformer
{
private string $pattern = '/^(?P<class>.*)::(?P<constant>.*)$/';
private const PATTERN = '/^(?P<class>.*)::(?P<constant>.*)$/';

public function supports($value): bool
{
Expand All @@ -19,7 +20,7 @@ public function supports($value): bool

$matches = [];

if (0 === preg_match($this->pattern, $value, $matches)) {
if (null === $matches = $this->extract($value)) {
return false;
}

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

public function transform($value)
{
$matches = [];

preg_match($this->pattern, $value, $matches);
if (null === $matches = $this->extract($value)) {
throw new Exception("Unable to resolve constant {$value}.");
}

return (new ReflectionClass($matches['class']))
->getConstant($matches['constant'])
;
}

/**
* @return ?array{class: class-string, constant: string}
*/
private function extract(string $value): ?array
{
if (preg_match(self::PATTERN, $value, $matches)) {
/**
* @var array{class: class-string, constant: string} $matches
*/
return $matches;
}

return null;
}
}

0 comments on commit dd161ac

Please sign in to comment.