|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Manage php doc |
|
5
|
|
|
* |
|
6
|
|
|
* @category lib |
|
7
|
|
|
* @author Judicaël Paquet <[email protected]> |
|
8
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
|
9
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
|
10
|
|
|
* @version Release: 1.0.0 |
|
11
|
|
|
* @filesource https://github.com/las93/venus2 |
|
12
|
|
|
* @link https://github.com/las93 |
|
13
|
|
|
* @since 1.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace Venus\lib; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This class manage the php doc |
|
19
|
|
|
* |
|
20
|
|
|
* @category lib |
|
21
|
|
|
* @author Judicaël Paquet <[email protected]> |
|
22
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
|
23
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
|
24
|
|
|
* @version Release: 1.0.0 |
|
25
|
|
|
* @filesource https://github.com/las93/venus2 |
|
26
|
|
|
* @link https://github.com/las93 |
|
27
|
|
|
* @since 1.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
class PhpDoc |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* add the namespace |
|
33
|
|
|
* |
|
34
|
|
|
* @access public |
|
35
|
|
|
* @param mixed $sClassName class name |
|
36
|
|
|
* @param string $sMethodName method name |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function getPhpDocOfMethod($sClassName, string $sMethodName) : array |
|
40
|
|
|
{ |
|
41
|
|
|
$oReflectionClass = new \ReflectionClass($sClassName); |
|
42
|
|
|
$oReflectionMethod = $oReflectionClass->getMethod($sMethodName); |
|
43
|
|
|
$sCommentPhpDoc = $oReflectionMethod->getDocComment(); |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* parse this PhpDoc @cache(param=1,param=2) |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
preg_match_all('/@([a-zA-Z0-9_-]+)[ \t]*\(([^\)]+)\)/', $sCommentPhpDoc, $aMatchs, PREG_SET_ORDER); |
|
50
|
|
|
$aParams = array(); |
|
51
|
|
|
|
|
52
|
|
|
foreach ($aMatchs as $aOneMatch) { |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$aParams[$aOneMatch[1]] = array(); |
|
55
|
|
|
|
|
56
|
|
|
foreach (explode(',', $aOneMatch[2]) as $sValue) { |
|
57
|
|
|
|
|
58
|
|
|
$aFinalExplode = explode('=', $sValue); |
|
59
|
|
|
|
|
60
|
|
|
if (preg_match('/^".+"$/', $aFinalExplode[1]) || preg_match("/^'.+'$/", $aFinalExplode[1])) { |
|
61
|
|
|
|
|
62
|
|
|
$aFinalExplode[1] = substr($aFinalExplode[1], 1); |
|
63
|
|
|
$aFinalExplode[1] = substr($aFinalExplode[1], 0, -1); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$aParams[$aOneMatch[1]][$aFinalExplode[0]] = $aFinalExplode[1]; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* parse this PhpDoc @param string $title ... |
|
72
|
|
|
*/ |
|
73
|
|
|
|
|
74
|
|
|
preg_match_all('/@([a-zA-Z0-9_-]+)[ \t]*([^\r\n]+)/', $sCommentPhpDoc, $aMatchs, PREG_SET_ORDER); |
|
75
|
|
|
$aParams = array(); |
|
76
|
|
|
|
|
77
|
|
|
foreach ($aMatchs as $aOneMatch) { |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
if ($aOneMatch[1] == 'param') { |
|
80
|
|
|
|
|
81
|
|
|
if (!isset($aParams['param'])) { $aParams['param'] = array(); } |
|
82
|
|
|
|
|
83
|
|
|
$iIndex = count($aParams['param']); |
|
84
|
|
|
|
|
85
|
|
|
if (!isset($aParams['param'][$iIndex])) { $aParams['param'][$iIndex] = array(); } |
|
86
|
|
|
|
|
87
|
|
View Code Duplication |
foreach (explode(' ', $aOneMatch[2]) as $sValue) { |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$aParams['param'][$iIndex][] = $sValue; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
else { |
|
93
|
|
|
|
|
94
|
|
|
$aParams[$aOneMatch[1]] = array(); |
|
95
|
|
|
|
|
96
|
|
View Code Duplication |
foreach (explode(' ', $aOneMatch[2]) as $sValue) { |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$aParams[$aOneMatch[1]][] = $sValue; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $aParams; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.