Skip to content

Commit

Permalink
Bugfix 131 (#1) (#133)
Browse files Browse the repository at this point in the history
* fixed FormTypeLabelImplicit visitor to not crash when constant is used as option key #131
  • Loading branch information
tkleinhakisa authored and Nyholm committed Dec 7, 2019
1 parent fcdb0dd commit 0a40152
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Visitor/Php/Symfony/FormTypeLabelImplicit.php
Expand Up @@ -49,11 +49,11 @@ public function enterNode(Node $node)
if (count($node->args) >= 3) {
if ($node->args[2]->value instanceof Node\Expr\Array_) {
foreach ($node->args[2]->value->items as $item) {
if (isset($item->key) && 'label' === $item->key->value) {
if (isset($item->key) && $item->key instanceof Node\Scalar\String_ && 'label' === $item->key->value) {
$skipLabel = true;
}

if (isset($item->key) && 'translation_domain' === $item->key->value) {
if (isset($item->key) && $item->key instanceof Node\Scalar\String_ && 'translation_domain' === $item->key->value) {
if ($item->value instanceof Node\Scalar\String_) {
$domain = $item->value->value;
} elseif ($item->value instanceof Node\Expr\ConstFetch && 'false' === $item->value->name->toString()) {
Expand Down
Expand Up @@ -24,7 +24,7 @@ public function testExtract()
{
$collection = $this->getSourceLocations(new FormTypeLabelImplicit(), Resources\Php\Symfony\ImplicitLabelType::class);

$this->assertCount(4, $collection, print_r($collection, true));
$this->assertCount(5, $collection, print_r($collection, true));
$this->assertEquals('find1', $collection->get(0)->getMessage());
$this->assertEquals('bigger_find2', $collection->get(1)->getMessage());
$this->assertEquals('camelFind3', $collection->get(2)->getMessage());
Expand Down
9 changes: 7 additions & 2 deletions tests/Resources/Php/Symfony/ImplicitLabelType.php
Expand Up @@ -4,6 +4,8 @@

class ImplicitLabelType
{
const ISSUE_131 = 'issue_131';

public function buildForm(FormBuilderInterface $builder, array $options)
{
$var = 'test';
Expand All @@ -15,10 +17,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add(function () { return 'skip3'; });
// Symfony will throw an error I guess, but at least extractions skip it
$builder->add('');

//issue87: support for Ignore annotation
$generateOptions = function() { return ['label' => false]; };
$builder->add('issue87-willBeAdded', null, $generateOptions);
$builder->add(/** @Ignore */'issue87-shouldNotBeAdded', null, $generateOptions);

//issue131: support for constant as option key
$builder->add('issue_131', null, [self::ISSUE_131 => true]);
}
}
}

0 comments on commit 0a40152

Please sign in to comment.