1 | <?php |
||
51 | class ConvertKeyValuePairsToArray |
||
52 | { |
||
53 | /** |
||
54 | * convert a line containing key value pairs into an array |
||
55 | * |
||
56 | * @param mixed $data |
||
57 | * the data to convert |
||
58 | * @param string $kvSeparator |
||
59 | * the separator between keys and values |
||
60 | * @param string $valueSeparator |
||
61 | * the separator between values and the next key |
||
62 | * @return mixed |
||
63 | * will return the same time that $data was |
||
64 | */ |
||
65 | public function __invoke($data, $kvSeparator, $valueSeparator) |
||
69 | |||
70 | /** |
||
71 | * convert a line containing key value pairs into an array |
||
72 | * |
||
73 | * @param mixed $data |
||
74 | * the data to convert |
||
75 | * @param string $kvSeparator |
||
76 | * the separator between keys and values |
||
77 | * @param string $valueSeparator |
||
78 | * the separator between values and the next key |
||
79 | * @return mixed |
||
80 | * will return the same time that $data was |
||
81 | */ |
||
82 | public static function from($data, $kvSeparator, $valueSeparator) |
||
87 | |||
88 | /** |
||
89 | * convert a line containing key value pairs into an array |
||
90 | * |
||
91 | * @param Traversable|array $data |
||
92 | * the data to convert |
||
93 | * @param string $kvSeparator |
||
94 | * the separator between keys and values |
||
95 | * @param string $valueSeparator |
||
96 | * the separator between values and the next key |
||
97 | * @return mixed |
||
98 | * will return the same time that $data was |
||
99 | */ |
||
100 | private static function fromTraversable($data, $kvSeparator, $valueSeparator) |
||
113 | |||
114 | /** |
||
115 | * convert a line containing key value pairs into an array |
||
116 | * |
||
117 | * @param string $data |
||
118 | * the data to convert |
||
119 | * @param string $kvSeparator |
||
120 | * the separator between keys and values |
||
121 | * @param string $valueSeparator |
||
122 | * the separator between values and the next key |
||
123 | * @return string |
||
|
|||
124 | * will return the same time that $data was |
||
125 | */ |
||
126 | private static function fromString($data, $kvSeparator, $valueSeparator) |
||
134 | |||
135 | /** |
||
136 | * called when we have a data type that we cannot convert |
||
137 | * |
||
138 | * @param mixed $data |
||
139 | * the data to convert |
||
140 | * @return void |
||
141 | * @throws E4xx_UnsupportedType |
||
142 | */ |
||
143 | private static function nothingMatchesTheInputType($data) |
||
147 | |||
148 | /** |
||
149 | * lookup map of how to convert which data type |
||
150 | * |
||
151 | * @var array |
||
152 | */ |
||
153 | private static $dispatchMap = [ |
||
154 | 'String' => 'fromString', |
||
155 | 'Traversable' => 'fromTraversable', |
||
156 | ]; |
||
157 | } |
||
158 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.