Completed
Push — 2.x-dev-kit ( 6f250c )
by
unknown
02:44
created

TwigTemplate14::getAttribute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
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
16
abstract class TwigTemplate14 extends \Twig_Template
17
{
18
    /**
19
     * @var \Sonata\CacheBundle\Invalidation\Recorder
20
     */
21
    protected static $recorder;
22
23
    /**
24
     * @static
25
     *
26
     * @param \Sonata\Cache\Invalidation\Recorder $recorder
27
     */
28
    public static function attachRecorder(Recorder $recorder)
29
    {
30
        self::$recorder = $recorder;
0 ignored issues
show
Documentation Bug introduced by
$recorder is of type object<Sonata\Cache\Invalidation\Recorder>, but the property $recorder was declared to be of type object<Sonata\CacheBundle\Invalidation\Recorder>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

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