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

FormTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isFormType() 0 9 2
A isKnownNode() 0 10 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