Completed
Push — master ( ba40ee...261a9c )
by Tobias
02:47
created

FormTrait::isKnownNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Extractor\Visitor\Php\Symfony;
13
14
use PhpParser\Node;
15
use PhpParser\Node\Stmt;
16
17
trait FormTrait
18
{
19
    private $isFormType = false;
20
21
    private $arrayNodeVisited = [];
22
23
    /**
24
     * Check if this node is a form type.
25
     *
26
     * @param Node $node
27
     *
28
     * @return bool
29
     */
30 21
    private function isFormType(Node $node)
31
    {
32
        // only Traverse *Type
33 21
        if ($node instanceof Stmt\Class_) {
34 21
            $this->isFormType = 'Type' === substr($node->name, -4);
35
        }
36
37 21
        return $this->isFormType;
38
    }
39
40
    /**
41
     * Check if a node have been visited.
42
     *
43
     * @param Node $node
44
     *
45
     * @return bool
46
     */
47 5
    private function isKnownNode(Node $node)
48
    {
49 5
        $hash = spl_object_hash($node);
50 5
        if (isset($this->arrayNodeVisited[$hash])) {
51 3
            return true;
52
        }
53 5
        $this->arrayNodeVisited[$hash] = true;
54
55 5
        return false;
56
    }
57
}
58