[TASK] Add more fixers for php-cs-fixer
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / ClassReflection.php
1 <?php
2 namespace TYPO3\CMS\Extbase\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 ReflectionClass
19 */
20 class ClassReflection extends \ReflectionClass
21 {
22 /**
23 * @var DocCommentParser Holds an instance of the doc comment parser for this class
24 */
25 protected $docCommentParser;
26
27 /**
28 * Replacement for the original getMethods() method which makes sure
29 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
30 * original ReflectionMethod instances.
31 *
32 * @param int|NULL $filter A filter mask
33 * @return MethodReflection[] Method reflection objects of the methods in this class
34 */
35 public function getMethods($filter = null)
36 {
37 $extendedMethods = [];
38 $methods = $filter === null ? parent::getMethods() : parent::getMethods($filter);
39 foreach ($methods as $method) {
40 $extendedMethods[] = new MethodReflection($this->getName(), $method->getName());
41 }
42 return $extendedMethods;
43 }
44
45 /**
46 * Replacement for the original getMethod() method which makes sure
47 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
48 * original ReflectionMethod instances.
49 *
50 * @param string $name
51 * @return MethodReflection Method reflection object of the named method
52 */
53 public function getMethod($name)
54 {
55 $parentMethod = parent::getMethod($name);
56 if (!is_object($parentMethod)) {
57 return $parentMethod;
58 }
59 return new MethodReflection($this->getName(), $parentMethod->getName());
60 }
61
62 /**
63 * Replacement for the original getConstructor() method which makes sure
64 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
65 * original ReflectionMethod instances.
66 *
67 * @return MethodReflection Method reflection object of the constructor method
68 */
69 public function getConstructor()
70 {
71 $parentConstructor = parent::getConstructor();
72 if (!is_object($parentConstructor)) {
73 return $parentConstructor;
74 }
75 return new MethodReflection($this->getName(), $parentConstructor->getName());
76 }
77
78 /**
79 * Replacement for the original getProperties() method which makes sure
80 * that \TYPO3\CMS\Extbase\Reflection\PropertyReflection objects are returned instead of the
81 * original ReflectionProperty instances.
82 *
83 * @param int|NULL $filter A filter mask
84 * @return PropertyReflection[] Property reflection objects of the properties in this class
85 */
86 public function getProperties($filter = null)
87 {
88 $extendedProperties = [];
89 $properties = $filter === null ? parent::getProperties() : parent::getProperties($filter);
90 foreach ($properties as $property) {
91 $extendedProperties[] = new PropertyReflection($this->getName(), $property->getName());
92 }
93 return $extendedProperties;
94 }
95
96 /**
97 * Replacement for the original getProperty() method which makes sure
98 * that a \TYPO3\CMS\Extbase\Reflection\PropertyReflection object is returned instead of the
99 * original ReflectionProperty instance.
100 *
101 * @param string $name Name of the property
102 * @return PropertyReflection Property reflection object of the specified property in this class
103 */
104 public function getProperty($name)
105 {
106 return new PropertyReflection($this->getName(), $name);
107 }
108
109 /**
110 * Replacement for the original getInterfaces() method which makes sure
111 * that \TYPO3\CMS\Extbase\Reflection\ClassReflection objects are returned instead of the
112 * original ReflectionClass instances.
113 *
114 * @return ClassReflection[] Class reflection objects of the properties in this class
115 */
116 public function getInterfaces()
117 {
118 $extendedInterfaces = [];
119 $interfaces = parent::getInterfaces();
120 foreach ($interfaces as $interface) {
121 $extendedInterfaces[] = new self($interface->getName());
122 }
123 return $extendedInterfaces;
124 }
125
126 /**
127 * Replacement for the original getParentClass() method which makes sure
128 * that a \TYPO3\CMS\Extbase\Reflection\ClassReflection object is returned instead of the
129 * original ReflectionClass instance.
130 *
131 * @return ClassReflection Reflection of the parent class - if any
132 */
133 public function getParentClass()
134 {
135 $parentClass = parent::getParentClass();
136 return $parentClass === false ? false : new self($parentClass->getName());
137 }
138
139 /**
140 * Checks if the doc comment of this method is tagged with
141 * the specified tag
142 *
143 * @param string $tag Tag name to check for
144 * @return bool TRUE if such a tag has been defined, otherwise FALSE
145 */
146 public function isTaggedWith($tag)
147 {
148 $result = $this->getDocCommentParser()->isTaggedWith($tag);
149 return $result;
150 }
151
152 /**
153 * Returns an array of tags and their values
154 *
155 * @return array Tags and values
156 */
157 public function getTagsValues()
158 {
159 return $this->getDocCommentParser()->getTagsValues();
160 }
161
162 /**
163 * Returns the values of the specified tag
164 *
165 * @param string $tag
166 * @return array Values of the given tag
167 */
168 public function getTagValues($tag)
169 {
170 return $this->getDocCommentParser()->getTagValues($tag);
171 }
172
173 /**
174 * Returns an instance of the doc comment parser and
175 * runs the parse() method.
176 *
177 * @return DocCommentParser
178 */
179 protected function getDocCommentParser()
180 {
181 if (!is_object($this->docCommentParser)) {
182 $this->docCommentParser = new DocCommentParser();
183 $this->docCommentParser->parseDocComment($this->getDocComment());
184 }
185 return $this->docCommentParser;
186 }
187 }