Conditions | 6 |
Paths | 10 |
Total Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Tests | 18 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
46 | 99 | public function convert() |
|
47 | { |
||
48 | 99 | $parsed = $this->sqlParser->parse($this->sql); |
|
49 | |||
50 | 99 | if (false === $parsed) { |
|
51 | 3 | throw new \Exception('SQL query is not valid'); |
|
52 | } |
||
53 | |||
54 | 96 | $results = []; |
|
55 | 96 | foreach ($parsed as $section => $data) { |
|
56 | 96 | if ($this->converterFactory->canCreate($section)) { |
|
57 | 96 | $converter = $this->converterFactory->create($section); |
|
58 | 96 | $results = array_merge($results, $converter->convert($data)); |
|
59 | } |
||
60 | } |
||
61 | |||
62 | $table = current(array_filter($results, function ($item) { |
||
63 | 96 | return 'table' === $item['name']; |
|
64 | 96 | })); |
|
65 | 96 | unset($results[array_search($table, $results)]); |
|
66 | 96 | array_unshift($results, $table); |
|
67 | |||
68 | 96 | foreach ($results as $function) { |
|
69 | 96 | $args = isset($function['args']) ? $function['args'] : []; |
|
70 | 96 | $this->generator->addFunction($function['name'], $args); |
|
71 | } |
||
72 | |||
73 | 96 | $this->generator->addFunction('get'); |
|
74 | |||
75 | 96 | return $this->generator->generate(); |
|
76 | } |
||
77 | } |
||
78 |