Skip to content

Commit c1bf71e

Browse files
authored
Reduce the indentation (#25)
* Reduce the indentation * Reduce the indentation
1 parent 4cc3e57 commit c1bf71e

File tree

4 files changed

+72
-64
lines changed

4 files changed

+72
-64
lines changed

src/Visitor/Php/Symfony/ContainerAwareTrans.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@ public function beforeTraverse(array $nodes)
2727

2828
public function enterNode(Node $node)
2929
{
30-
if ($node instanceof Node\Expr\MethodCall) {
31-
if (!is_string($node->name)) {
32-
return;
33-
}
34-
$name = $node->name;
35-
36-
//If $this->get('translator')->trans('foobar')
37-
if ('trans' === $name) {
38-
$label = $this->getStringArgument($node, 0);
39-
$domain = $this->getStringArgument($node, 2);
40-
41-
$source = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'), ['domain' => $domain]);
42-
$this->collection->addLocation($source);
43-
}
30+
if (!$node instanceof Node\Expr\MethodCall) {
31+
return;
32+
}
33+
34+
if (!is_string($node->name)) {
35+
return;
36+
}
37+
$name = $node->name;
38+
39+
//If $this->get('translator')->trans('foobar')
40+
if ('trans' === $name) {
41+
$label = $this->getStringArgument($node, 0);
42+
$domain = $this->getStringArgument($node, 2);
43+
44+
$source = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'), ['domain' => $domain]);
45+
$this->collection->addLocation($source);
4446
}
4547
}
4648

src/Visitor/Php/Symfony/ContainerAwareTransChoice.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@ public function beforeTraverse(array $nodes)
2727

2828
public function enterNode(Node $node)
2929
{
30-
if ($node instanceof Node\Expr\MethodCall) {
31-
if (!is_string($node->name)) {
32-
return;
33-
}
34-
$name = $node->name;
35-
36-
//If $this->get('translator')->trans('foobar')
37-
if ('transChoice' === $name) {
38-
$label = $this->getStringArgument($node, 0);
39-
$domain = $this->getStringArgument($node, 3);
40-
41-
$source = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'), ['domain' => $domain]);
42-
$this->collection->addLocation($source);
43-
}
30+
if (!$node instanceof Node\Expr\MethodCall) {
31+
return;
32+
}
33+
34+
if (!is_string($node->name)) {
35+
return;
36+
}
37+
$name = $node->name;
38+
39+
//If $this->get('translator')->trans('foobar')
40+
if ('transChoice' === $name) {
41+
$label = $this->getStringArgument($node, 0);
42+
$domain = $this->getStringArgument($node, 3);
43+
44+
$source = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'), ['domain' => $domain]);
45+
$this->collection->addLocation($source);
4446
}
4547
}
4648

src/Visitor/Php/Symfony/FlashMessage.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,28 @@ public function beforeTraverse(array $nodes)
2727

2828
public function enterNode(Node $node)
2929
{
30-
if ($node instanceof Node\Expr\MethodCall) {
31-
if (!is_string($node->name)) {
32-
return;
33-
}
30+
if (!$node instanceof Node\Expr\MethodCall) {
31+
return;
32+
}
33+
34+
if (!is_string($node->name)) {
35+
return;
36+
}
3437

35-
$name = $node->name;
36-
$caller = $node->var;
37-
// $caller might be "Node\Expr\New_"
38-
$callerName = isset($caller->name) ? $caller->name : '';
39-
40-
/*
41-
* Make sure the caller is from a variable named "this" or a function called "getFlashbag"
42-
*/
43-
//If $this->addFlash() or xxx->getFlashbag()->add()
44-
if (('addFlash' === $name && $callerName === 'this' && $caller instanceof Node\Expr\Variable) ||
45-
('add' === $name && $callerName === 'getFlashBag' && $caller instanceof Node\Expr\MethodCall)
46-
) {
47-
if (null !== $label = $this->getStringArgument($node, 1)) {
48-
$this->collection->addLocation(new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine')));
49-
}
38+
$name = $node->name;
39+
$caller = $node->var;
40+
// $caller might be "Node\Expr\New_"
41+
$callerName = isset($caller->name) ? $caller->name : '';
42+
43+
/*
44+
* Make sure the caller is from a variable named "this" or a function called "getFlashbag"
45+
*/
46+
//If $this->addFlash() or xxx->getFlashbag()->add()
47+
if (('addFlash' === $name && $callerName === 'this' && $caller instanceof Node\Expr\Variable) ||
48+
('add' === $name && $callerName === 'getFlashBag' && $caller instanceof Node\Expr\MethodCall)
49+
) {
50+
if (null !== $label = $this->getStringArgument($node, 1)) {
51+
$this->collection->addLocation(new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine')));
5052
}
5153
}
5254
}

src/Visitor/Php/Symfony/FormTypeLabelExplicit.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,30 @@ public function enterNode(Node $node)
3737
// is provided statically or through another function.
3838
// I don't see any disadvantages now to simply parsing arrays and JMSTranslationBundle has
3939
// been doing it like this for quite some time without major problems.
40-
if ($node instanceof Node\Expr\Array_) {
41-
foreach ($node->items as $item) {
42-
if (!$item->key instanceof Node\Scalar\String_) {
43-
continue;
44-
}
40+
if (!$node instanceof Node\Expr\Array_) {
41+
return;
42+
}
4543

46-
if ($item->key->value !== 'label') {
47-
continue;
48-
}
44+
foreach ($node->items as $item) {
45+
if (!$item->key instanceof Node\Scalar\String_) {
46+
continue;
47+
}
4948

50-
if (!$item->value instanceof Node\Scalar\String_) {
51-
continue;
52-
}
49+
if ($item->key->value !== 'label') {
50+
continue;
51+
}
5352

54-
$label = $item->value->value;
55-
if (empty($label)) {
56-
continue;
57-
}
53+
if (!$item->value instanceof Node\Scalar\String_) {
54+
continue;
55+
}
5856

59-
$sl = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'));
60-
$this->collection->addLocation($sl);
57+
$label = $item->value->value;
58+
if (empty($label)) {
59+
continue;
6160
}
61+
62+
$sl = new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'));
63+
$this->collection->addLocation($sl);
6264
}
6365
}
6466

0 commit comments

Comments
 (0)