1 | <?php |
||
12 | class Parser |
||
13 | { |
||
14 | /** |
||
15 | * Normalize a string trimming trailing '/' |
||
16 | * and replacing remained '/' with '-' |
||
17 | * |
||
18 | * Example: |
||
19 | * - ///first//second///// => first-second |
||
20 | * |
||
21 | * @param string $name the string to normalize |
||
22 | * @return string |
||
23 | */ |
||
24 | public static function normalize($name) |
||
29 | |||
30 | /** |
||
31 | * Match $data returning false if $conditions are not sotisfied. |
||
32 | * Return true if all conditions are met |
||
33 | * |
||
34 | * @param array $data an array of data |
||
35 | * @param array $conditions an array if filter vars |
||
36 | * @return bool |
||
37 | */ |
||
38 | public static function match(array $data, array $conditions = array()) |
||
55 | |||
56 | /** |
||
57 | * Match require |
||
58 | * Check if $data contains all required keys with not empty values. |
||
59 | * It returns false if some reuired keys is missing |
||
60 | * |
||
61 | * @param array $data an array of data |
||
62 | * @param array $require an array if required keys |
||
63 | * @return bool |
||
64 | */ |
||
65 | protected static function matchRequire(array $data, array $require = array()) |
||
74 | |||
75 | /** |
||
76 | * Check if a key is present in array and it's value is not empty or match $matchValue value |
||
77 | * $key can be a point separated string to traversing the array |
||
78 | * |
||
79 | * Examples: |
||
80 | * |
||
81 | * ``` |
||
82 | * $data = [ |
||
83 | * 'name1' => [ |
||
84 | * 'name2' => 'value', |
||
85 | * 'name3' => null |
||
86 | * ] |
||
87 | * ]; |
||
88 | * |
||
89 | * Parser::hasKey($data, 'name1'); // return true |
||
90 | * Parser::hasKey($data, 'name1.name2'); // return true |
||
91 | * Parser::hasKey($data, 'name2'); // return false |
||
92 | * Parser::hasKey($data, 'name1.name3'); // return false |
||
93 | * Parser::hasKey($data', name1.name4'); // return false |
||
94 | * Parser::hasKey($data, 'name1.name2', '/alu/'); // return true |
||
95 | * Parser::hasKey($data, 'name1.name2', '/^alu/'); // return false |
||
96 | * ``` |
||
97 | * @param array $data an array to check |
||
98 | * @param string $key the key name |
||
99 | * @param string $matchPattern a regexp used to match value |
||
|
|||
100 | * @return bool |
||
101 | */ |
||
102 | public static function hasKey(array $data, $key, $matchPattern = null) |
||
117 | |||
118 | /** |
||
119 | * Match grep |
||
120 | * Check if $grep keys exist in $data and their value match $grep values |
||
121 | * $grep is an array as |
||
122 | * |
||
123 | * ``` |
||
124 | * [ |
||
125 | * 'grep_key' => 'grep_value', |
||
126 | * 'grep_key2.grep_key3' => 'grep_value2' |
||
127 | * ] |
||
128 | * ``` |
||
129 | * |
||
130 | * @param array $data an array of data |
||
131 | * @param array $grep |
||
132 | * @return bool |
||
133 | */ |
||
134 | protected static function matchGrep(array $data, array $grep = array()) |
||
148 | |||
149 | /** |
||
150 | * Given a string or an array of string |
||
151 | * it builds the regexp pattern to use in self::matchGrep() |
||
152 | * |
||
153 | * Example: |
||
154 | * ``` |
||
155 | * $data = ['one', 'two', 'three']; |
||
156 | * ``` |
||
157 | * will produce the pattern `/((^|\s|\W)one\b)|((^|\s|\W)two\b)|((^|\s|\W)three\b)/i` |
||
158 | * |
||
159 | * @param array|string $data |
||
160 | * @return string |
||
161 | */ |
||
162 | private static function grepPattern($data) |
||
183 | } |
||
184 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.