2222
2323namespace ElementaryFramework \Annotations ;
2424
25+ use ElementaryFramework \Annotations \Exceptions \AnnotationException ;
26+
2527/**
2628 * This class manages the retrieval of Annotations from source code files
2729 */
@@ -75,14 +77,14 @@ class AnnotationManager
7577 'internal ' => false ,
7678 'license ' => false ,
7779 'link ' => false ,
78- 'method ' => 'ElementaryFramework\Annotations\standard \MethodAnnotation ' ,
80+ 'method ' => 'ElementaryFramework\Annotations\Standard \MethodAnnotation ' ,
7981 'name ' => false ,
8082 '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 ' ,
8688 'see ' => false ,
8789 'since ' => false ,
8890 'source ' => false ,
@@ -92,11 +94,11 @@ class AnnotationManager
9294 'todo ' => false ,
9395 'tutorial ' => false ,
9496 'throws ' => false ,
95- 'type ' => 'ElementaryFramework\Annotations\standard \TypeAnnotation ' ,
97+ 'type ' => 'ElementaryFramework\Annotations\Standard \TypeAnnotation ' ,
9698 'usage ' => 'ElementaryFramework\Annotations\UsageAnnotation ' ,
9799 'stop ' => 'ElementaryFramework\Annotations\StopAnnotation ' ,
98100 'uses ' => false ,
99- 'var ' => 'ElementaryFramework\Annotations\standard \VarAnnotation ' ,
101+ 'var ' => 'ElementaryFramework\Annotations\Standard \VarAnnotation ' ,
100102 'version ' => false ,
101103 );
102104
@@ -155,7 +157,7 @@ class AnnotationManager
155157 *
156158 * @param string $cacheSeed only needed if using more than one AnnotationManager in the same application
157159 */
158- public function __construct ($ cacheSeed = '' )
160+ public function __construct (string $ cacheSeed = '' )
159161 {
160162 $ this ->_cacheSeed = $ cacheSeed ;
161163 $ this ->_usageAnnotation = new UsageAnnotation ();
@@ -185,14 +187,15 @@ public function getParser()
185187 * Member-names in the returned array have the following format: Class, Class::method or Class::$member
186188 *
187189 * @param string $path the path of the source-code file from which to obtain annotation-data.
190+ *
188191 * @return AnnotationFile
189192 *
190193 * @throws AnnotationException if cache is not configured
191194 *
192195 * @see $files
193196 * @see $cache
194197 */
195- protected function getAnnotationFile ($ path )
198+ protected function getAnnotationFile (string $ path ): AnnotationFile
196199 {
197200 if (!isset ($ this ->files [$ path ])) {
198201 if ($ this ->cache === null ) {
@@ -231,7 +234,7 @@ protected function getAnnotationFile($path)
231234 *
232235 * @see $registry
233236 */
234- public function resolveName ($ name )
237+ public function resolveName (string $ name )
235238 {
236239 if (\strpos ($ name , '\\' ) !== false ) {
237240 return $ name . $ this ->suffix ; // annotation class-name is fully qualified
@@ -258,9 +261,10 @@ public function resolveName($name)
258261 * @param string $member_name Optional member name, e.g. "method" or "$property"
259262 *
260263 * @return IAnnotation[] array of IAnnotation objects for the given class/member/name
264+ *
261265 * @throws AnnotationException for bad annotations
262266 */
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
264268 {
265269 $ key = $ class_name . ($ member_name ? ':: ' . $ member_name : '' );
266270
@@ -366,7 +370,7 @@ protected function getAnnotations($class_name, $member_type = self::MEMBER_CLASS
366370 *
367371 * @return bool whether class or trait has the specified member
368372 */
369- protected function classHasMember ($ className , $ memberType , $ memberName )
373+ protected function classHasMember (string $ className , string $ memberType , string $ memberName ): bool
370374 {
371375 if ($ memberType === self ::MEMBER_METHOD ) {
372376 return \method_exists ($ className , $ memberName );
@@ -387,7 +391,7 @@ protected function classHasMember($className, $memberType, $memberName)
387391 *
388392 * @throws AnnotationException if a constraint is violated.
389393 */
390- protected function applyConstraints (array $ annotations , $ member )
394+ protected function applyConstraints (array $ annotations , string $ member ): array
391395 {
392396 $ result = array ();
393397 $ annotationCount = \count ($ annotations );
@@ -431,7 +435,7 @@ protected function applyConstraints(array $annotations, $member)
431435 *
432436 * @return array The filtered array of annotation objects - may return an empty array
433437 */
434- protected function filterAnnotations (array $ annotations , $ type )
438+ protected function filterAnnotations (array $ annotations , string $ type ): array
435439 {
436440 if (\substr ($ type , 0 , 1 ) === '@ ' ) {
437441 $ type = $ this ->resolveName (\substr ($ type , 1 ));
@@ -456,10 +460,12 @@ protected function filterAnnotations(array $annotations, $type)
456460 * Obtain the UsageAnnotation for a given Annotation class
457461 *
458462 * @param string $class The Annotation type class-name
463+ *
459464 * @return UsageAnnotation
465+ *
460466 * @throws AnnotationException if the given class-name is invalid; if the annotation-type has no defined usage
461467 */
462- public function getUsage ($ class )
468+ public function getUsage (string $ class ): UsageAnnotation
463469 {
464470 if ($ class === $ this ->registry ['usage ' ]) {
465471 return $ this ->_usageAnnotation ;
@@ -496,9 +502,10 @@ public function getUsage($class)
496502 * Alternatively, prefixing with "@" invokes name-resolution (allowing you to query by annotation name.)
497503 *
498504 * @return Annotation[] Annotation instances
505+ *
499506 * @throws AnnotationException if a given class-name is undefined
500507 */
501- public function getClassAnnotations ($ class , $ type = null )
508+ public function getClassAnnotations ($ class , string $ type = null ): array
502509 {
503510 if ($ class instanceof \ReflectionClass) {
504511 $ class = $ class ->getName ();
@@ -534,9 +541,10 @@ public function getClassAnnotations($class, $type = null)
534541 * Alternatively, prefixing with "@" invokes name-resolution (allowing you to query by annotation name.)
535542 *
536543 * @throws AnnotationException for undefined method or class-name
544+ *
537545 * @return IAnnotation[] list of Annotation objects
538546 */
539- public function getMethodAnnotations ($ class , $ method = null , $ type = null )
547+ public function getMethodAnnotations ($ class , string $ method = null , string $ type = null ): array
540548 {
541549 if ($ class instanceof \ReflectionClass) {
542550 $ class = $ class ->getName ();
@@ -576,7 +584,7 @@ public function getMethodAnnotations($class, $method = null, $type = null)
576584 *
577585 * @throws AnnotationException for undefined class-name
578586 */
579- public function getPropertyAnnotations ($ class , $ property = null , $ type = null )
587+ public function getPropertyAnnotations ($ class , string $ property = null , string $ type = null ): array
580588 {
581589 if ($ class instanceof \ReflectionClass) {
582590 $ class = $ class ->getName ();
0 commit comments