Skip to content

Commit 9ae791e

Browse files
authored
Merge pull request #16106 from phalcon/reflection-refactor
2 parents 9dddf58 + 40cef77 commit 9ae791e

File tree

6 files changed

+52
-64
lines changed

6 files changed

+52
-64
lines changed

CHANGELOG-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Changed
44
- Changed `Phalcon\Logger\Adapter\Stream::process` to open the log file, check for locks, write contents and close the stream [#16072](https://github.com/phalcon/cphalcon/issues/16072)
55
- Changed getters and setters from shorthand format to full methods [#16102](https://github.com/phalcon/cphalcon/issues/16102)
6+
- Changed return types to `array` in `Phalcon\Annotations\Reflection` class methods [#16106](https://github.com/phalcon/cphalcon/issues/16106)
67

78
## Fixed
89
- Fixed and improved return type of `object` & `?object` [#16023](https://github.com/phalcon/cphalcon/issues/16023)

phalcon/Annotations/Reflection.zep

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,47 @@ namespace Phalcon\Annotations;
3131
class Reflection
3232
{
3333
/**
34-
* @var array
35-
* TODO: Make always array
34+
* @var Collection|null
3635
*/
37-
protected classAnnotations;
36+
protected classAnnotations = null;
3837

3938
/**
4039
* @var array
41-
* TODO: Make always array
4240
*/
43-
protected constantAnnotations;
41+
protected constantAnnotations = [];
4442

4543
/**
4644
* @var array
47-
* TODO: Make always array
4845
*/
49-
protected propertyAnnotations;
46+
protected propertyAnnotations = [];
5047

5148
/**
5249
* @var array
53-
* TODO: Make always array
5450
*/
55-
protected methodAnnotations;
51+
protected methodAnnotations = [];
5652

5753
/**
5854
* @var array
5955
*/
6056
protected reflectionData = [];
6157

62-
/**
63-
* Phalcon\Annotations\Reflection constructor
64-
*/
6558
public function __construct(array reflectionData = [])
6659
{
6760
let this->reflectionData = reflectionData;
6861
}
6962

7063
/**
7164
* Returns the annotations found in the class docblock
65+
*
66+
* @return Collection|null
7267
*/
73-
public function getClassAnnotations() -> <Collection> | bool
68+
public function getClassAnnotations() -> <Collection> | null
7469
{
7570
var reflectionClass;
7671

7772
if this->classAnnotations === null {
7873
if fetch reflectionClass, this->reflectionData["class"] {
7974
let this->classAnnotations = new Collection(reflectionClass);
80-
} else {
81-
let this->classAnnotations = false;
8275
}
8376
}
8477

@@ -87,83 +80,65 @@ class Reflection
8780

8881
/**
8982
* Returns the annotations found in the constants' docblocks
83+
*
84+
* @return Collection[]
9085
*/
91-
public function getConstantsAnnotations() -> <Collection[]> | bool
86+
public function getConstantsAnnotations() -> <Collection[]>
9287
{
9388
var reflectionConstants, constant, reflectionConstant;
9489

95-
if this->constantAnnotations === null {
96-
if fetch reflectionConstants, this->reflectionData["constants"] {
97-
if count(reflectionConstants) {
98-
let this->constantAnnotations = [];
99-
100-
for constant, reflectionConstant in reflectionConstants {
101-
let this->constantAnnotations[constant] = new Collection(
102-
reflectionConstant
103-
);
104-
}
105-
106-
return this->constantAnnotations;
90+
if fetch reflectionConstants, this->reflectionData["constants"] {
91+
if typeof reflectionConstants === "array" && count(reflectionConstants) > 0 {
92+
for constant, reflectionConstant in reflectionConstants {
93+
let this->constantAnnotations[constant] = new Collection(
94+
reflectionConstant
95+
);
10796
}
10897
}
109-
110-
let this->constantAnnotations = false;
11198
}
11299

113100
return this->constantAnnotations;
114101
}
115102

116103
/**
117104
* Returns the annotations found in the properties' docblocks
105+
*
106+
* @return Collection[]
118107
*/
119-
public function getPropertiesAnnotations() -> <Collection[]> | bool
108+
public function getPropertiesAnnotations() -> <Collection[]>
120109
{
121110
var reflectionProperties, property, reflectionProperty;
122111

123-
if this->propertyAnnotations === null {
124-
if fetch reflectionProperties, this->reflectionData["properties"] {
125-
if count(reflectionProperties) {
126-
let this->propertyAnnotations = [];
127-
128-
for property, reflectionProperty in reflectionProperties {
129-
let this->propertyAnnotations[property] = new Collection(
130-
reflectionProperty
131-
);
132-
}
133-
134-
return this->propertyAnnotations;
112+
if fetch reflectionProperties, this->reflectionData["properties"] {
113+
if typeof reflectionProperties === "array" && count(reflectionProperties) > 0 {
114+
for property, reflectionProperty in reflectionProperties {
115+
let this->propertyAnnotations[property] = new Collection(
116+
reflectionProperty
117+
);
135118
}
136119
}
137-
138-
let this->propertyAnnotations = false;
139120
}
140121

141122
return this->propertyAnnotations;
142123
}
143124

144125
/**
145126
* Returns the annotations found in the methods' docblocks
127+
*
128+
* @return Collection[]
146129
*/
147-
public function getMethodsAnnotations() -> <Collection[]> | bool
130+
public function getMethodsAnnotations() -> <Collection[]>
148131
{
149132
var reflectionMethods, methodName, reflectionMethod;
150133

151-
if this->methodAnnotations === null {
152-
if fetch reflectionMethods, this->reflectionData["methods"] {
153-
if count(reflectionMethods) {
154-
let this->methodAnnotations = [];
155-
156-
for methodName, reflectionMethod in reflectionMethods {
157-
let this->methodAnnotations[methodName] = new Collection(
158-
reflectionMethod
159-
);
160-
}
161-
162-
return this->methodAnnotations;
134+
if fetch reflectionMethods, this->reflectionData["methods"] {
135+
if typeof reflectionMethods === "array" && count(reflectionMethods) > 0 {
136+
for methodName, reflectionMethod in reflectionMethods {
137+
let this->methodAnnotations[methodName] = new Collection(
138+
reflectionMethod
139+
);
163140
}
164141
}
165-
166-
let this->methodAnnotations = false;
167142
}
168143

169144
return this->methodAnnotations;
@@ -172,6 +147,8 @@ class Reflection
172147
/**
173148
* Returns the raw parsing intermediate definitions used to construct the
174149
* reflection
150+
*
151+
* @return array
175152
*/
176153
public function getReflectionData() -> array
177154
{

tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testEmptyReflection(UnitTester $I)
3939
{
4040
$reflection = new Reflection();
4141

42-
$I->assertFalse(
42+
$I->assertNull(
4343
$reflection->getClassAnnotations()
4444
);
4545
}

tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function testEmptyReflection(UnitTester $I)
4040
{
4141
$reflection = new Reflection();
4242

43-
$I->assertFalse(
43+
$I->assertIsArray(
44+
$reflection->getMethodsAnnotations()
45+
);
46+
$I->assertIsEmpty(
4447
$reflection->getMethodsAnnotations()
4548
);
4649
}

tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public function testEmptyReflection(UnitTester $I)
4040
{
4141
$reflection = new Reflection();
4242

43-
$I->assertFalse(
43+
$I->assertIsArray(
44+
$reflection->getPropertiesAnnotations()
45+
);
46+
$I->assertIsEmpty(
4447
$reflection->getPropertiesAnnotations()
4548
);
4649
}

tests/unit/Annotations/Reflection/GetReflectionDataCest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Phalcon\Tests\Unit\Annotations\Reflection;
1515

16+
use Phalcon\Annotations\Reflection;
1617
use UnitTester;
1718

1819
class GetReflectionDataCest
@@ -27,6 +28,9 @@ public function annotationsReflectionGetReflectionData(UnitTester $I)
2728
{
2829
$I->wantToTest('Annotations\Reflection - getReflectionData()');
2930

30-
$I->skipTest('Need implementation');
31+
$reflection = new Reflection();
32+
33+
$I->assertIsArray($reflection->getReflectionData());
34+
$I->assertIsEmpty($reflection->getReflectionData());
3135
}
3236
}

0 commit comments

Comments
 (0)