ModelEqualityOperator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compile() 0 9 1
A equalModels() 0 4 1
1
<?php
2
3
namespace BZIon\Twig;
4
5
/**
6
 * A twig operator to test if two models are the same (they are of the same type
7
 * and have the same ID)
8
 */
9
class ModelEqualityOperator extends \Twig_Node_Expression
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 1
    public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
15
    {
16 1
        parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
17 1
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 1
    public function compile(\Twig_Compiler $compiler)
23
    {
24
        $compiler
25 1
            ->raw('( \BZIon\Twig\ModelEqualityOperator::equalModels((')
26 1
            ->subcompile($this->getNode('left'))
27 1
            ->raw('),(')
28 1
            ->subcompile($this->getNode('right'))
29 1
            ->raw(')) )');
30 1
    }
31
32
    /**
33
     * Checks if $a and $b represent the same object
34
     *
35
     * Used as a helper function, since there might be syntax errors when older
36
     * PHP versions try to parse this: (new Model())->isSameAs($b)
37
     *
38
     * @param \Model $a
39
     * @param \Model $b
40
     *
41
     * @return bool
42
     */
43 1
    public static function equalModels(\Model $a, \Model $b)
44
    {
45 1
        return $a->isSameAs($b);
46
    }
47
}
48