1 | <?php |
||
14 | class PHPDocClass |
||
15 | { |
||
16 | /** |
||
17 | * @param string $className |
||
18 | * @return Method[] |
||
19 | */ |
||
20 | 4 | public static function staticMethods(string $className): array |
|
21 | { |
||
22 | 4 | $classDoc = self::docComment($className); |
|
23 | |||
24 | 3 | preg_match_all( |
|
25 | 3 | '/^[* ]+@method(?>\hstatic) ?([a-zA-Z0-9_\-\$\\\ ]*) (\w+)\(([a-zA-Z0-9_\-$,\\\ ]*)\) ?(.*)$/im', |
|
26 | 3 | $classDoc, |
|
27 | 3 | $staticMethodsOfDoc, |
|
28 | 3 | PREG_SET_ORDER |
|
29 | ); |
||
30 | |||
31 | 3 | return self::createMethods($staticMethodsOfDoc, true); |
|
|
|||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param string $className |
||
36 | * @return Method[] |
||
37 | */ |
||
38 | 4 | public static function methods(string $className): array |
|
39 | { |
||
40 | 4 | $classDoc = self::docComment($className); |
|
41 | |||
42 | 3 | preg_match_all( |
|
43 | 3 | '/^[* ]+@method(?!.*static )([a-zA-Z0-9_\-\$\\\ ]*) (\w+)\(([a-zA-Z0-9_\-$,\\\ ]*)\) ?(.*)$/mi', |
|
44 | 3 | $classDoc, |
|
45 | 3 | $staticMethodsOfDoc, |
|
46 | 3 | PREG_SET_ORDER |
|
47 | ); |
||
48 | |||
49 | 3 | return self::createMethods($staticMethodsOfDoc, false); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $className |
||
54 | * @return string |
||
55 | */ |
||
56 | 8 | private static function docComment(string $className): string |
|
62 | |||
63 | /** |
||
64 | * @param array $methodsOfDoc |
||
65 | * @param bool $areStatics |
||
66 | * @return array |
||
67 | */ |
||
68 | 6 | private static function createMethods(array $methodsOfDoc, bool $areStatics): array |
|
87 | |||
88 | /** |
||
89 | * @param string $stringParams |
||
90 | * @return array |
||
91 | */ |
||
92 | 4 | private static function parseParams(string $stringParams): array |
|
110 | } |
||
111 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.