Debian Codegraph @

includes/libs/DebugInfo/AnnotationReader.php

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\DebugInfo;
4
5 /**
6 * Utility class for reading doc comment annotations
7 *
8 * @since 1.40
9 */
10 class AnnotationReader {
11 /** @var bool[] */
12 private static $cache = [];
13
14 /**
15 * Determine whether a ReflectionProperty has a specified annotation
16 *
17 * @param \ReflectionProperty $property
18 * @param string $annotationName
19 * @return bool
20 */
21 public static function propertyHasAnnotation(
22 \ReflectionProperty $property,
23 string $annotationName
24 ) {
25 $cacheKey = "$annotationName@{$property->class}::{$property->name}";
26 if ( !isset( self::$cache[$cacheKey] ) ) {
27 $comment = $property->getDocComment();
28 if ( $comment === false ) {
29 self::$cache[$cacheKey] = false;
30 } else {
31 $encAnnotation = preg_quote( $annotationName, '!' );
32 self::$cache[$cacheKey] =
33 (bool)preg_match( "!^[ \t]*(/\*\*|\*)[ \t]*@$encAnnotation\b!im", $comment );
34 }
35 }
36 return self::$cache[$cacheKey];
37 }
38 }