14 $this->statements = [];
17 $this->statements[$i] = clone $statement;
44 foreach ($result as $stmt)
46 if (is_array($stmt) && isset($stmt[
'if']))
48 $code .= str_repeat(
"\t", $level) .
'if (' . implode(
' && ', $stmt[
'if']) .
")\n";
49 $code .= str_repeat(
"\t", $level) .
"{\n";
51 $code .= str_repeat(
"\t", $level) .
"}\n";
55 $stmt = trim($stmt,
"\n\t");
56 $stmt = preg_replace(
"/\\n\\t+/",
"\n", $stmt);
57 $code .= str_repeat(
"\t", $level) . str_replace(
"\n\$",
"\n" . str_repeat(
"\t", $level) .
'$', $stmt) .
"\n";
70 $this->makeCodeTree($this->statements, $this->tree);
83 protected function makeCodeTree(array $updaterSteps, &$result)
85 foreach ($updaterSteps as $i => $statement)
87 if (empty($statement->conditions))
89 $result[] = $statement->formatBodyLines(0);
90 unset($updaterSteps[$i]);
97 foreach ($updaterSteps as $i => $statement)
102 foreach ($statement->conditions as $condition)
104 $predicate = $condition->getPredicate();
105 if (!isset($byPredicates[$predicate]))
107 $byPredicates[$predicate] = [
108 'predicate' => $predicate,
109 'dep' => $statement->dependOn,
116 $byPredicates[$predicate][
'count']++;
123 sortByColumn($byPredicates, [
125 'count' => SORT_DESC,
128 $mostPopular = key($byPredicates);
131 'if' => [$mostPopular],
134 foreach ($updaterSteps as $i => $statement)
136 foreach ($statement->conditions as $j => $condition)
138 if ($condition->getPredicate() == $mostPopular)
140 unset($statement->conditions[$j]);
141 $subSteps[] = $statement;
142 unset($updaterSteps[$i]);
146 $this->makeCodeTree($subSteps, $ifStatement[
'body']);
148 is_array($ifStatement[
'body'])
149 && count($ifStatement[
'body']) == 1
150 && is_array($ifStatement[
'body'][0])
151 && isset($ifStatement[
'body'][0][
'if'])
152 && isset($ifStatement[
'body'][0][
'body'])
153 && mb_strlen(implode(
' && ', array_merge($ifStatement[
'if'], $ifStatement[
'body'][0][
'if']))) < 100
156 $ifStatement[
'if'] = array_merge($ifStatement[
'if'], $ifStatement[
'body'][0][
'if']);
157 $ifStatement[
'body'] = $ifStatement[
'body'][0][
'body'];
159 $result[] = $ifStatement;
171 if (mb_strpos($predicate,
'CanUpdateDatabase'))
175 elseif (mb_strpos($predicate,
'->type'))
179 elseif (mb_strpos($predicate,
'TableExists'))
183 elseif (mb_strpos($predicate,
'IndexExists'))