Completed
Pull Request — master (#158)
by Grégoire
01:23
created

TwigTemplate::getAttribute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 6
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[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 Sonata\CacheBundle\Twig;
13
14
use Sonata\Cache\Invalidation\Recorder;
15
use Twig\Template;
16
17
abstract class TwigTemplate extends Template
18
{
19
    /**
20
     * @var \Sonata\CacheBundle\Invalidation\Recorder
21
     */
22
    protected static $recorder;
23
24
    /**
25
     * @static
26
     *
27
     * @param \Sonata\Cache\Invalidation\Recorder $recorder
28
     */
29
    public static function attachRecorder(Recorder $recorder)
30
    {
31
        self::$recorder = $recorder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $recorder of type object<Sonata\Cache\Invalidation\Recorder> is incompatible with the declared type object<Sonata\CacheBundle\Invalidation\Recorder> of property $recorder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * @param mixed  $object
36
     * @param string $item
37
     * @param array  $arguments
38
     * @param string $type
39
     * @param bool   $isDefinedTest
40
     * @param bool   $ignoreStrictCheck
41
     *
42
     * @return mixed
43
     */
44
    protected function getAttribute($object, $item, array $arguments = [], $type = \Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
45
    {
46
        $attribute = parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest);
47
48
        if (self::$recorder && is_object($object)) {
49
            self::$recorder->add($object);
50
        }
51
52
        return $attribute;
53
    }
54
}
55