22
22
23
23
namespace ElementaryFramework \Annotations ;
24
24
25
+ use ElementaryFramework \Annotations \Exceptions \AnnotationException ;
26
+
25
27
/**
26
28
* This class manages the retrieval of Annotations from source code files
27
29
*/
@@ -75,14 +77,14 @@ class AnnotationManager
75
77
'internal ' => false ,
76
78
'license ' => false ,
77
79
'link ' => false ,
78
- 'method ' => 'ElementaryFramework\Annotations\standard \MethodAnnotation ' ,
80
+ 'method ' => 'ElementaryFramework\Annotations\Standard \MethodAnnotation ' ,
79
81
'name ' => false ,
80
82
'package ' => false ,
81
- 'param ' => 'ElementaryFramework\Annotations\standard \ParamAnnotation ' ,
82
- 'property ' => 'ElementaryFramework\Annotations\standard \PropertyAnnotation ' ,
83
- 'property-read ' => 'ElementaryFramework\Annotations\standard \PropertyReadAnnotation ' ,
84
- 'property-write ' => 'ElementaryFramework\Annotations\standard \PropertyWriteAnnotation ' ,
85
- 'return ' => 'ElementaryFramework\Annotations\standard \ReturnAnnotation ' ,
83
+ 'param ' => 'ElementaryFramework\Annotations\Standard \ParamAnnotation ' ,
84
+ 'property ' => 'ElementaryFramework\Annotations\Standard \PropertyAnnotation ' ,
85
+ 'property-read ' => 'ElementaryFramework\Annotations\Standard \PropertyReadAnnotation ' ,
86
+ 'property-write ' => 'ElementaryFramework\Annotations\Standard \PropertyWriteAnnotation ' ,
87
+ 'return ' => 'ElementaryFramework\Annotations\Standard \ReturnAnnotation ' ,
86
88
'see ' => false ,
87
89
'since ' => false ,
88
90
'source ' => false ,
@@ -92,11 +94,11 @@ class AnnotationManager
92
94
'todo ' => false ,
93
95
'tutorial ' => false ,
94
96
'throws ' => false ,
95
- 'type ' => 'ElementaryFramework\Annotations\standard \TypeAnnotation ' ,
97
+ 'type ' => 'ElementaryFramework\Annotations\Standard \TypeAnnotation ' ,
96
98
'usage ' => 'ElementaryFramework\Annotations\UsageAnnotation ' ,
97
99
'stop ' => 'ElementaryFramework\Annotations\StopAnnotation ' ,
98
100
'uses ' => false ,
99
- 'var ' => 'ElementaryFramework\Annotations\standard \VarAnnotation ' ,
101
+ 'var ' => 'ElementaryFramework\Annotations\Standard \VarAnnotation ' ,
100
102
'version ' => false ,
101
103
);
102
104
@@ -155,7 +157,7 @@ class AnnotationManager
155
157
*
156
158
* @param string $cacheSeed only needed if using more than one AnnotationManager in the same application
157
159
*/
158
- public function __construct ($ cacheSeed = '' )
160
+ public function __construct (string $ cacheSeed = '' )
159
161
{
160
162
$ this ->_cacheSeed = $ cacheSeed ;
161
163
$ this ->_usageAnnotation = new UsageAnnotation ();
@@ -185,14 +187,15 @@ public function getParser()
185
187
* Member-names in the returned array have the following format: Class, Class::method or Class::$member
186
188
*
187
189
* @param string $path the path of the source-code file from which to obtain annotation-data.
190
+ *
188
191
* @return AnnotationFile
189
192
*
190
193
* @throws AnnotationException if cache is not configured
191
194
*
192
195
* @see $files
193
196
* @see $cache
194
197
*/
195
- protected function getAnnotationFile ($ path )
198
+ protected function getAnnotationFile (string $ path ): AnnotationFile
196
199
{
197
200
if (!isset ($ this ->files [$ path ])) {
198
201
if ($ this ->cache === null ) {
@@ -231,7 +234,7 @@ protected function getAnnotationFile($path)
231
234
*
232
235
* @see $registry
233
236
*/
234
- public function resolveName ($ name )
237
+ public function resolveName (string $ name )
235
238
{
236
239
if (\strpos ($ name , '\\' ) !== false ) {
237
240
return $ name . $ this ->suffix ; // annotation class-name is fully qualified
@@ -258,9 +261,10 @@ public function resolveName($name)
258
261
* @param string $member_name Optional member name, e.g. "method" or "$property"
259
262
*
260
263
* @return IAnnotation[] array of IAnnotation objects for the given class/member/name
264
+ *
261
265
* @throws AnnotationException for bad annotations
262
266
*/
263
- protected function getAnnotations ($ class_name , $ member_type = self ::MEMBER_CLASS , $ member_name = null )
267
+ protected function getAnnotations (string $ class_name , string $ member_type = self ::MEMBER_CLASS , string $ member_name = null ): array
264
268
{
265
269
$ key = $ class_name . ($ member_name ? ':: ' . $ member_name : '' );
266
270
@@ -366,7 +370,7 @@ protected function getAnnotations($class_name, $member_type = self::MEMBER_CLASS
366
370
*
367
371
* @return bool whether class or trait has the specified member
368
372
*/
369
- protected function classHasMember ($ className , $ memberType , $ memberName )
373
+ protected function classHasMember (string $ className , string $ memberType , string $ memberName ): bool
370
374
{
371
375
if ($ memberType === self ::MEMBER_METHOD ) {
372
376
return \method_exists ($ className , $ memberName );
@@ -387,7 +391,7 @@ protected function classHasMember($className, $memberType, $memberName)
387
391
*
388
392
* @throws AnnotationException if a constraint is violated.
389
393
*/
390
- protected function applyConstraints (array $ annotations , $ member )
394
+ protected function applyConstraints (array $ annotations , string $ member ): array
391
395
{
392
396
$ result = array ();
393
397
$ annotationCount = \count ($ annotations );
@@ -431,7 +435,7 @@ protected function applyConstraints(array $annotations, $member)
431
435
*
432
436
* @return array The filtered array of annotation objects - may return an empty array
433
437
*/
434
- protected function filterAnnotations (array $ annotations , $ type )
438
+ protected function filterAnnotations (array $ annotations , string $ type ): array
435
439
{
436
440
if (\substr ($ type , 0 , 1 ) === '@ ' ) {
437
441
$ type = $ this ->resolveName (\substr ($ type , 1 ));
@@ -456,10 +460,12 @@ protected function filterAnnotations(array $annotations, $type)
456
460
* Obtain the UsageAnnotation for a given Annotation class
457
461
*
458
462
* @param string $class The Annotation type class-name
463
+ *
459
464
* @return UsageAnnotation
465
+ *
460
466
* @throws AnnotationException if the given class-name is invalid; if the annotation-type has no defined usage
461
467
*/
462
- public function getUsage ($ class )
468
+ public function getUsage (string $ class ): UsageAnnotation
463
469
{
464
470
if ($ class === $ this ->registry ['usage ' ]) {
465
471
return $ this ->_usageAnnotation ;
@@ -496,9 +502,10 @@ public function getUsage($class)
496
502
* Alternatively, prefixing with "@" invokes name-resolution (allowing you to query by annotation name.)
497
503
*
498
504
* @return Annotation[] Annotation instances
505
+ *
499
506
* @throws AnnotationException if a given class-name is undefined
500
507
*/
501
- public function getClassAnnotations ($ class , $ type = null )
508
+ public function getClassAnnotations ($ class , string $ type = null ): array
502
509
{
503
510
if ($ class instanceof \ReflectionClass) {
504
511
$ class = $ class ->getName ();
@@ -534,9 +541,10 @@ public function getClassAnnotations($class, $type = null)
534
541
* Alternatively, prefixing with "@" invokes name-resolution (allowing you to query by annotation name.)
535
542
*
536
543
* @throws AnnotationException for undefined method or class-name
544
+ *
537
545
* @return IAnnotation[] list of Annotation objects
538
546
*/
539
- public function getMethodAnnotations ($ class , $ method = null , $ type = null )
547
+ public function getMethodAnnotations ($ class , string $ method = null , string $ type = null ): array
540
548
{
541
549
if ($ class instanceof \ReflectionClass) {
542
550
$ class = $ class ->getName ();
@@ -576,7 +584,7 @@ public function getMethodAnnotations($class, $method = null, $type = null)
576
584
*
577
585
* @throws AnnotationException for undefined class-name
578
586
*/
579
- public function getPropertyAnnotations ($ class , $ property = null , $ type = null )
587
+ public function getPropertyAnnotations ($ class , string $ property = null , string $ type = null ): array
580
588
{
581
589
if ($ class instanceof \ReflectionClass) {
582
590
$ class = $ class ->getName ();
0 commit comments