Skip to content

Commit 9a2bd56

Browse files
Bernhard Schmittmficzel
authored andcommitted
Adjust Neos.Flow Reflection subcontext
1 parent a353a69 commit 9a2bd56

File tree

9 files changed

+252
-85
lines changed

9 files changed

+252
-85
lines changed

Neos.Flow/Classes/Reflection/ClassReflection.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/**
1717
* Extended version of the ReflectionClass
1818
*
19+
* @extends \ReflectionClass<object>
1920
* @Flow\Proxy(false)
2021
*/
2122
class ClassReflection extends \ReflectionClass
@@ -39,7 +40,7 @@ static function ($className) use ($classNameOrObject) {
3940
}
4041

4142
/**
42-
* @var DocCommentParser Holds an instance of the doc comment parser for this class
43+
* @var ?DocCommentParser Holds an instance of the doc comment parser for this class
4344
*/
4445
protected $docCommentParser;
4546

@@ -48,12 +49,14 @@ static function ($className) use ($classNameOrObject) {
4849
* that MethodReflection objects are returned instead of the
4950
* original ReflectionMethod instances.
5051
*
51-
* @return MethodReflection Method reflection object of the constructor method
52+
* @return ?MethodReflection Method reflection object of the constructor method
5253
*/
53-
public function getConstructor(): MethodReflection
54+
public function getConstructor(): ?MethodReflection
5455
{
5556
$parentConstructor = parent::getConstructor();
56-
return (!is_object($parentConstructor)) ? $parentConstructor : new MethodReflection($this->getName(), $parentConstructor->getName());
57+
return $parentConstructor === null
58+
? $parentConstructor
59+
: new MethodReflection($this->getName(), $parentConstructor->getName());
5760
}
5861

5962
/**
@@ -165,7 +168,7 @@ public function isTaggedWith($tag)
165168
/**
166169
* Returns an array of tags and their values
167170
*
168-
* @return array Tags and values
171+
* @return array<string,array<int,string>> Tags and values
169172
*/
170173
public function getTagsValues()
171174
{
@@ -175,7 +178,7 @@ public function getTagsValues()
175178
/**
176179
* Returns the values of the specified tag
177180
* @param string $tag
178-
* @return array Values of the given tag
181+
* @return array<int,string> Values of the given tag
179182
*/
180183
public function getTagValues($tag)
181184
{
@@ -205,7 +208,7 @@ public function newInstanceWithoutConstructor(): object
205208
{
206209
$instance = parent::newInstanceWithoutConstructor();
207210

208-
if (method_exists($instance, '__wakeup') && is_callable([$instance, '__wakeup'])) {
211+
if (method_exists($instance, '__wakeup')) {
209212
$instance->__wakeup();
210213
}
211214

@@ -221,8 +224,11 @@ public function newInstanceWithoutConstructor(): object
221224
protected function getDocCommentParser()
222225
{
223226
if (!is_object($this->docCommentParser)) {
224-
$this->docCommentParser = new DocCommentParser;
225-
$this->docCommentParser->parseDocComment($this->getDocComment());
227+
$this->docCommentParser = new DocCommentParser();
228+
$docComment = $this->getDocComment();
229+
if ($docComment) {
230+
$this->docCommentParser->parseDocComment($docComment);
231+
}
226232
}
227233
return $this->docCommentParser;
228234
}

Neos.Flow/Classes/Reflection/ClassSchema.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ class ClassSchema
5454
/**
5555
* Properties of the class which need to be persisted
5656
*
57-
* @var array
57+
* @var array<string,array{
58+
* type: string,
59+
* elementType: ?string,
60+
* nullable: bool,
61+
* lazy: bool,
62+
* transient: bool,
63+
* }>
5864
*/
5965
protected $properties = [];
6066

6167
/**
6268
* The properties forming the identity of an object
6369
*
64-
* @var array
70+
* @var array<string,string>
6571
*/
6672
protected $identityProperties = [];
6773

@@ -137,7 +143,13 @@ public function addProperty($name, $type, $lazy = false, $transient = false)
137143
* hasProperty($propertyName) before!
138144
*
139145
* @param string $propertyName
140-
* @return array
146+
* @return array{
147+
* type: string,
148+
* elementType: ?string,
149+
* nullable: bool,
150+
* lazy: bool,
151+
* transient: bool,
152+
* }
141153
*/
142154
public function getProperty($propertyName)
143155
{
@@ -147,7 +159,13 @@ public function getProperty($propertyName)
147159
/**
148160
* Returns all properties defined in this schema
149161
*
150-
* @return array
162+
* @return array<string,array{
163+
* type: string,
164+
* elementType: ?string,
165+
* nullable: bool,
166+
* lazy: bool,
167+
* transient: bool,
168+
* }>
151169
*/
152170
public function getProperties()
153171
{
@@ -198,7 +216,7 @@ public function getModelType()
198216
/**
199217
* Set the class name of the repository managing an entity.
200218
*
201-
* @param string $repositoryClassName
219+
* @param ?string $repositoryClassName
202220
* @return void
203221
* @throws Exception\ClassSchemaConstraintViolationException
204222
*/
@@ -211,7 +229,7 @@ public function setRepositoryClassName($repositoryClassName)
211229
}
212230

213231
/**
214-
* @return string
232+
* @return ?string
215233
*/
216234
public function getRepositoryClassName()
217235
{
@@ -300,7 +318,7 @@ public function markAsIdentityProperty($propertyName)
300318
/**
301319
* Gets the properties (names and types) forming the identity of an object.
302320
*
303-
* @return array
321+
* @return array<string,string>
304322
* @see markAsIdentityProperty()
305323
*/
306324
public function getIdentityProperties()

Neos.Flow/Classes/Reflection/DocCommentParser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DocCommentParser
2828

2929
/**
3030
* An array of tag names and their values (multiple values are possible)
31-
* @var array
31+
* @var array<string,array<int,string>>
3232
*/
3333
protected $tags = [];
3434

@@ -47,9 +47,9 @@ public function parseDocComment($docComment)
4747

4848
$lines = explode(chr(10), $docComment);
4949
foreach ($lines as $line) {
50-
$line = trim(preg_replace('/\*\/$/', '', $line));
50+
$line = trim(preg_replace('/\*\/$/', '', $line) ?: '');
5151
if ($line !== '' && strpos($line, '* @') !== false) {
52-
$this->parseTag(substr($line, strpos($line, '@')));
52+
$this->parseTag(substr($line, strpos($line, '@') ?: 0));
5353
} elseif (count($this->tags) === 0) {
5454
$this->description .= preg_replace('/\s*\\/?[\\\\*]*\s?(.*)$/', '$1', $line) . chr(10);
5555
}
@@ -60,7 +60,7 @@ public function parseDocComment($docComment)
6060
/**
6161
* Returns the tags which have been previously parsed
6262
*
63-
* @return array Array of tag names and their (multiple) values
63+
* @return array<string,array<int,string>> Array of tag names and their (multiple) values
6464
*/
6565
public function getTagsValues()
6666
{
@@ -73,7 +73,7 @@ public function getTagsValues()
7373
* available.
7474
*
7575
* @param string $tagName The tag name to retrieve the values for
76-
* @return array The tag's values
76+
* @return array<int,string> The tag's values
7777
* @throws Exception
7878
*/
7979
public function getTagValues($tagName)
@@ -116,7 +116,7 @@ protected function parseTag($line)
116116
{
117117
$tagAndValue = [];
118118
if (preg_match('/@[A-Za-z0-9\\\\]+\\\\([A-Za-z0-9]+)(?:\\((.*)\\))?$/', $line, $tagAndValue) === 0) {
119-
$tagAndValue = preg_split('/\s/', $line, 2);
119+
$tagAndValue = preg_split('/\s/', $line, 2) ?: [];
120120
} else {
121121
array_shift($tagAndValue);
122122
}

Neos.Flow/Classes/Reflection/MethodReflection.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class MethodReflection extends \ReflectionMethod
2222
{
2323
/**
24-
* @var DocCommentParser An instance of the doc comment parser
24+
* @var ?DocCommentParser An instance of the doc comment parser
2525
*/
2626
protected $docCommentParser;
2727

@@ -66,7 +66,7 @@ public function isTaggedWith($tag)
6666
/**
6767
* Returns an array of tags and their values
6868
*
69-
* @return array Tags and values
69+
* @return array<string,array<int,string>> Tags and values
7070
*/
7171
public function getTagsValues()
7272
{
@@ -77,7 +77,7 @@ public function getTagsValues()
7777
* Returns the values of the specified tag
7878
*
7979
* @param string $tag Tag name to check for
80-
* @return array Values of the given tag
80+
* @return array<int,string> Values of the given tag
8181
*/
8282
public function getTagValues($tag)
8383
{
@@ -99,9 +99,6 @@ public function getDescription()
9999
*/
100100
public function getDeclaredReturnType()
101101
{
102-
if (!is_callable([$this, 'getReturnType'])) {
103-
return null;
104-
}
105102
$type = $this->getReturnType();
106103
return $type !== null ? ltrim((string)$type, '?') : null;
107104
}
@@ -111,9 +108,6 @@ public function getDeclaredReturnType()
111108
*/
112109
public function isDeclaredReturnTypeNullable()
113110
{
114-
if (!is_callable([$this, 'getReturnType'])) {
115-
return false;
116-
}
117111
$type = $this->getReturnType();
118112
return $type !== null && $type->allowsNull();
119113
}
@@ -127,8 +121,11 @@ public function isDeclaredReturnTypeNullable()
127121
protected function getDocCommentParser()
128122
{
129123
if (!is_object($this->docCommentParser)) {
130-
$this->docCommentParser = new DocCommentParser;
131-
$this->docCommentParser->parseDocComment($this->getDocComment());
124+
$this->docCommentParser = new DocCommentParser();
125+
$docComment = $this->getDocComment();
126+
if ($docComment) {
127+
$this->docCommentParser->parseDocComment($docComment);
128+
}
132129
}
133130
return $this->docCommentParser;
134131
}

Neos.Flow/Classes/Reflection/ParameterReflection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ class ParameterReflection extends \ReflectionParameter
2828
/**
2929
* Returns the declaring class
3030
*
31-
* @return ClassReflection The declaring class
31+
* @return ?ClassReflection The declaring class
3232
*/
33-
public function getDeclaringClass(): ClassReflection
33+
public function getDeclaringClass(): ?ClassReflection
3434
{
35-
return new ClassReflection(parent::getDeclaringClass()->getName());
35+
$reflectionClass = parent::getDeclaringClass();
36+
return $reflectionClass ? new ClassReflection($reflectionClass->getName()) : null;
3637
}
3738

3839
/**

Neos.Flow/Classes/Reflection/PropertyReflection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class PropertyReflection extends \ReflectionProperty
2222
{
2323
/**
24-
* @var DocCommentParser An instance of the doc comment parser
24+
* @var ?DocCommentParser An instance of the doc comment parser
2525
*/
2626
protected $docCommentParser;
2727

@@ -58,7 +58,7 @@ public function getDeclaringClass(): ClassReflection
5858
/**
5959
* Returns an array of tags and their values
6060
*
61-
* @return array Tags and values
61+
* @return array<string,array<int,string>> Tags and values
6262
*/
6363
public function getTagsValues()
6464
{
@@ -69,7 +69,7 @@ public function getTagsValues()
6969
* Returns the values of the specified tag
7070
*
7171
* @param string $tag
72-
* @return array Values of the given tag
72+
* @return array<int,string> Values of the given tag
7373
*/
7474
public function getTagValues($tag)
7575
{
@@ -137,8 +137,11 @@ public function setValue($object = null, $value = null): void
137137
protected function getDocCommentParser()
138138
{
139139
if (!is_object($this->docCommentParser)) {
140-
$this->docCommentParser = new DocCommentParser;
141-
$this->docCommentParser->parseDocComment($this->getDocComment());
140+
$this->docCommentParser = new DocCommentParser();
141+
$docComment = $this->getDocComment();
142+
if ($docComment) {
143+
$this->docCommentParser->parseDocComment($docComment);
144+
}
142145
}
143146
return $this->docCommentParser;
144147
}

0 commit comments

Comments
 (0)