PropertyReflection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 0
loc 79
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isTaggedWith() 0 5 1
A getTagsValues() 0 4 1
A getTagValues() 0 4 1
A getValue() 0 14 4
A getDocCommentParser() 0 8 2
1
<?php
2
namespace Romm\ConfigurationObject\Legacy\Reflection;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
/**
18
 * Extended version of the ReflectionProperty
19
 */
20
class PropertyReflection extends \ReflectionProperty
21
{
22
    /**
23
     * @var DocCommentParser An instance of the doc comment parser
24
     */
25
    protected $docCommentParser;
26
27
    /**
28
     * Checks if the doc comment of this property is tagged with
29
     * the specified tag
30
     *
31
     * @param string $tag Tag name to check for
32
     * @return bool TRUE if such a tag has been defined, otherwise FALSE
33
     */
34
    public function isTaggedWith($tag)
35
    {
36
        $result = $this->getDocCommentParser()->isTaggedWith($tag);
37
        return $result;
38
    }
39
40
    /**
41
     * Returns an array of tags and their values
42
     *
43
     * @return array Tags and values
44
     */
45
    public function getTagsValues()
46
    {
47
        return $this->getDocCommentParser()->getTagsValues();
48
    }
49
50
    /**
51
     * Returns the values of the specified tag
52
     *
53
     * @param string $tag
54
     * @return array Values of the given tag
55
     */
56
    public function getTagValues($tag)
57
    {
58
        return $this->getDocCommentParser()->getTagValues($tag);
59
    }
60
61
    /**
62
     * Returns the value of the reflected property - even if it is protected.
63
     *
64
     * @param object $object Instance of the declaring class \TYPO3\CMS\Extbase\Reflection to read the value from
65
     * @return mixed Value of the property
66
     * @throws Exception
67
     * @todo Maybe support private properties as well, as of PHP 5.3.0 we can do
68
     */
69
    public function getValue($object = null)
70
    {
71
        if (!is_object($object)) {
72
            throw new Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
73
        }
74
        if ($this->isPublic()) {
75
            return parent::getValue($object);
76
        }
77
        if ($this->isPrivate()) {
78
            throw new Exception('Cannot return value of private property "' . $this->name . '.', 1210859206);
79
        }
80
        parent::setAccessible(true);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setAccessible() instead of getValue()). Are you sure this is correct? If so, you might want to change this to $this->setAccessible().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
81
        return parent::getValue($object);
82
    }
83
84
    /**
85
     * Returns an instance of the doc comment parser and
86
     * runs the parse() method.
87
     *
88
     * @return DocCommentParser
89
     */
90
    protected function getDocCommentParser()
91
    {
92
        if (!is_object($this->docCommentParser)) {
93
            $this->docCommentParser = new DocCommentParser();
94
            $this->docCommentParser->parseDocComment($this->getDocComment());
95
        }
96
        return $this->docCommentParser;
97
    }
98
}
99