Completed
Pull Request — master (#43)
by Jiří
24:00
created

ArrayListingReplacer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 0 13 3
1
<?php
2
3
4
namespace Spatie\Php7to5\NodeVisitors;
5
6
7
use PhpParser\Node;
8
use PhpParser\NodeVisitorAbstract;
9
10
/**
11
 * Class ArrayListingReplacer
12
 * @package Spatie\Php7to5\NodeVisitors
13
 * @author Jiri Vrba <[email protected]>
14
 *
15
 * Replaces [$a, $b, $c] = ['a', 'b', 'c'] with list()
16
 */
17
class ArrayListingReplacer extends NodeVisitorAbstract
18
{
19
	/**
20
	 * {@inheritdoc}
21
	 */
22
	public function leaveNode(Node $node)
23
	{
24
		if ($node instanceof Node\Expr\Assign)
25
		{
26
			if ($node->var instanceof Node\Expr\Array_)
27
			{
28
				return new Node\Expr\Assign(
29
					new Node\Expr\List_($node->var->items),
30
					$node->expr
31
				);
32
			}
33
		}
34
	}
35
}