1 | <?php |
||
4 | class StringHelper |
||
5 | { |
||
6 | protected $string; |
||
7 | |||
8 | /** |
||
9 | * StringHelper constructor. Accepts and stores a string. |
||
10 | * |
||
11 | * @throws \InvalidArgumentException if not initialized with a string |
||
12 | * |
||
13 | * @param string $string The string needing help |
||
14 | */ |
||
15 | 77 | public function __construct($string) |
|
23 | |||
24 | 24 | public function __toString() |
|
28 | |||
29 | /** |
||
30 | * Given a delimited string, returns a copy of the string with chunks defined by the delimiter affected by a given |
||
31 | * function. |
||
32 | * |
||
33 | * The supplied function must be callable and must accept a string as its only required parameter |
||
34 | * |
||
35 | * @param callable $function The function to be called against the delimited chunks; must be callable and must |
||
36 | * accept a string as its only parameter |
||
37 | * @param string[] $delimiters One or more strings delimiting the chunks |
||
|
|||
38 | * |
||
39 | * @return string A delimited string with chunks affected by the supplied function |
||
40 | */ |
||
41 | 35 | public function affectChunks(callable $function, ...$delimiters) |
|
61 | |||
62 | /** |
||
63 | * Determines whether the string starts with a given string. |
||
64 | * |
||
65 | * @param string $string A string the string may or may not start with |
||
66 | * |
||
67 | * @return bool Returns true if the string starts with the given string |
||
68 | * Returns false if the string does not start with the given string |
||
69 | */ |
||
70 | 26 | public function startsWith($string) |
|
78 | |||
79 | /** |
||
80 | * Given a string, collapses any repetition at the start of the string into a single instance of the given string. |
||
81 | * If the given string does not exist at the start of the string, returns an unmodified string. |
||
82 | * |
||
83 | * For example, if the StringHelper was constructed with "ffoo", StringHelper::collapseStartingRepetition("f") will |
||
84 | * return "foo". If the StringHelper was constructed with "foo", StringHelper::collapseStartingRepetition("b") will |
||
85 | * also return "foo". |
||
86 | * |
||
87 | * @param string $string A string the string may or may not start with, with or without repetition |
||
88 | * |
||
89 | * @return string Returns a potentially modified string with a repeating, starting string collapsed into |
||
90 | * a single instance of the string |
||
91 | */ |
||
92 | 8 | public function collapseStartingRepetition($string) |
|
107 | } |
||
108 |
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.