| Total Complexity | 9 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Nord\Lumen\Elasticsearch\Parsers; |
||
| 3 | class AbstractStringParser |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $separator = ';'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $delimiter = ':'; |
||
| 14 | |||
| 15 | |||
| 16 | /** |
||
| 17 | * Configuration constructor. |
||
| 18 | * |
||
| 19 | * @param array $config |
||
| 20 | */ |
||
| 21 | public function __construct(array $config = []) |
||
| 22 | { |
||
| 23 | $this->configure($config); |
||
| 24 | } |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $string |
||
| 29 | * |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | public function parse(string $string) |
||
| 33 | { |
||
| 34 | $array = []; |
||
| 35 | |||
| 36 | foreach ($this->splitItems($string) as $item) { |
||
| 37 | $array[] = $this->splitItem($item); |
||
| 38 | } |
||
| 39 | |||
| 40 | return $array; |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * @param array $config |
||
| 46 | */ |
||
| 47 | protected function configure(array $config) |
||
| 48 | { |
||
| 49 | if (isset($config['separator'])) { |
||
| 50 | $this->separator = $config['separator']; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (isset($config['delimiter'])) { |
||
| 54 | $this->delimiter = $config['delimiter']; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $string |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | protected function splitItems($string) |
||
| 67 | } |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * @param string $string |
||
| 72 | * |
||
| 73 | * @return array |
||
| 74 | */ |
||
| 75 | protected function splitItem($string) |
||
| 80 |