Completed
Push — master ( 3785c8...e3dbba )
by Konstantinos
03:58
created

ModelEqualityOperator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compile() 0 10 1
A equalModels() 0 3 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
    public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
15
    {
16
        parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function compile(\Twig_Compiler $compiler)
23
    {
24
        $compiler
25
            ->raw('( \BZIon\Twig\ModelEqualityOperator::equalModels((')
26
            ->subcompile($this->getNode('left'))
27
            ->raw('),(')
28
            ->subcompile($this->getNode('right'))
29
            ->raw(')) )')
30
        ;
31
    }
32
33
    /**
34
     * Checks if $a and $b represent the same object
35
     *
36
     * Used as a helper function, since there might be syntax errors when older
37
     * PHP versions try to parse this: (new Model())->isSameAs($b)
38
     *
39
     * @param \Model $a
40
     * @param \Model $b
41
     *
42
     * @return bool
43
     */
44
    public static function equalModels(\Model $a, \Model $b) {
45
        return $a->isSameAs($b);
46
    }
47
}
48