@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public function column(string $table, string $column): array |
| 54 | 54 | { |
| 55 | 55 | if (!$this->hasColumn($table, $column)) { |
| 56 | - throw new \InvalidArgumentException('CANNOT FIND COLUMN ' . $column . ' IN TABLE ' . $table); |
|
| 56 | + throw new \InvalidArgumentException('CANNOT FIND COLUMN '.$column.' IN TABLE '.$table); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if (!isset($this->tables[$table]['columns'][$column]['schema'])) { |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public static function cache(string $database): ?SchemaInterface |
| 23 | 23 | { |
| 24 | - $cache_file = __DIR__ . '/cache/' . $database . '.php'; |
|
| 25 | - if(!file_exists($cache_file)){ |
|
| 24 | + $cache_file = __DIR__.'/cache/'.$database.'.php'; |
|
| 25 | + if (!file_exists($cache_file)) { |
|
| 26 | 26 | return null; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -36,18 +36,18 @@ discard block |
||
| 36 | 36 | $pdo->beginTransaction(); |
| 37 | 37 | |
| 38 | 38 | // switch to the INFORMATION_SCHEMA database |
| 39 | - if(false === $pdo->query(sprintf('USE %s;', $schema_database))){ |
|
| 39 | + if (false === $pdo->query(sprintf('USE %s;', $schema_database))) { |
|
| 40 | 40 | throw new CruditesException('SWICTH_TO_INFORMATION_SCHEMA'); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // get the schema information |
| 44 | 44 | $res = $pdo->query(self::informationSchemaQuery($database)); |
| 45 | - if(false === $res){ |
|
| 45 | + if (false === $res) { |
|
| 46 | 46 | throw new CruditesException('LOAD_INFORMATION_SCHEMA'); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | // switch back to the original database |
| 50 | - if(false === $pdo->query(sprintf('USE %s;', $database))){ |
|
| 50 | + if (false === $pdo->query(sprintf('USE %s;', $database))) { |
|
| 51 | 51 | throw new CruditesException('SWICTH_BACK_TO_USER_DATABASE'); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $res = $res->fetchAll(\PDO::FETCH_ASSOC); |
| 63 | - if($res === false){ |
|
| 63 | + if ($res === false) { |
|
| 64 | 64 | throw new CruditesException('SCHEMA_LOAD_FETCHALL'); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if(empty($res)){ |
|
| 67 | + if (empty($res)) { |
|
| 68 | 68 | throw new CruditesException('SCHEMA_LOAD_FETCHED_EMPTY_RESULTS'); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | $alterations = ['field1' => 'value1', 'field2' => 'value2']; |
| 17 | 17 | $setClause = new Set($alterations); |
| 18 | 18 | $this->assertEquals('SET `field1` = :set_field1,`field2` = :set_field2', (string)$setClause); |
| 19 | - $this->assertEquals(['set_field1' => 'value1','set_field2' => 'value2'], $setClause->bindings()); |
|
| 19 | + $this->assertEquals(['set_field1' => 'value1', 'set_field2' => 'value2'], $setClause->bindings()); |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function withValue($value, string $bind_prefix = null): self |
| 64 | 64 | { |
| 65 | 65 | $this->bindings[$this->bindLabel($bind_prefix)] = $value; |
| 66 | - $this->right = ':' . $this->bindLabel($bind_prefix); |
|
| 66 | + $this->right = ':'.$this->bindLabel($bind_prefix); |
|
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $bind_label = $this->bindLabel($bind_prefix); |
| 77 | 77 | foreach ($values as $index => $val) { |
| 78 | - $this->bindings[sprintf('%s_%d',$bind_label, $index)] = $val; |
|
| 78 | + $this->bindings[sprintf('%s_%d', $bind_label, $index)] = $val; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $this->operator = 'IN'; |
| 82 | - $this->right = '(:' . implode(',:', array_keys($this->bindings)) . ')'; |
|
| 82 | + $this->right = '(:'.implode(',:', array_keys($this->bindings)).')'; |
|
| 83 | 83 | |
| 84 | 84 | return $this; |
| 85 | 85 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | if ($prefix !== null) |
| 127 | - $this->bind_label = $prefix . '_' . $this->bind_label; |
|
| 127 | + $this->bind_label = $prefix.'_'.$this->bind_label; |
|
| 128 | 128 | |
| 129 | 129 | return $this->bind_label; |
| 130 | 130 | } |
@@ -112,8 +112,9 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function bindLabel(string $prefix = null): string |
| 114 | 114 | { |
| 115 | - if ($this->bind_label !== null) |
|
| 116 | - return $this->bind_label; |
|
| 115 | + if ($this->bind_label !== null) { |
|
| 116 | + return $this->bind_label; |
|
| 117 | + } |
|
| 117 | 118 | |
| 118 | 119 | if (is_string($this->right)) { |
| 119 | 120 | $this->bind_label = $this->right; |
@@ -123,8 +124,9 @@ discard block |
||
| 123 | 124 | $this->bind_label = $this->left; |
| 124 | 125 | } |
| 125 | 126 | |
| 126 | - if ($prefix !== null) |
|
| 127 | - $this->bind_label = $prefix . '_' . $this->bind_label; |
|
| 127 | + if ($prefix !== null) { |
|
| 128 | + $this->bind_label = $prefix . '_' . $this->bind_label; |
|
| 129 | + } |
|
| 128 | 130 | |
| 129 | 131 | return $this->bind_label; |
| 130 | 132 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function __toString(): string |
| 22 | 22 | { |
| 23 | - return 'SET ' . rtrim($this->alterations, ','); |
|
| 23 | + return 'SET '.rtrim($this->alterations, ','); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function name(): string |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | public function __construct(array $predicates = null) |
| 12 | 12 | { |
| 13 | - if ($predicates !== null){ |
|
| 13 | + if ($predicates !== null) { |
|
| 14 | 14 | foreach ($predicates as $predicate) { |
| 15 | 15 | if (is_string($predicate)) |
| 16 | 16 | $this->and($predicate); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | return ''; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - return 'WHERE ' . implode(' AND ', $this->and); |
|
| 29 | + return 'WHERE '.implode(' AND ', $this->and); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function name(): string |
@@ -12,10 +12,11 @@ |
||
| 12 | 12 | { |
| 13 | 13 | if ($predicates !== null){ |
| 14 | 14 | foreach ($predicates as $predicate) { |
| 15 | - if (is_string($predicate)) |
|
| 16 | - $this->and($predicate); |
|
| 17 | - else |
|
| 18 | - $this->and($predicate, $predicate->bindings()); |
|
| 15 | + if (is_string($predicate)) { |
|
| 16 | + $this->and($predicate); |
|
| 17 | + } else { |
|
| 18 | + $this->and($predicate, $predicate->bindings()); |
|
| 19 | + } |
|
| 19 | 20 | } |
| 20 | 21 | } |
| 21 | 22 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | { |
| 27 | 27 | // Generate the INSERT statement with backticks around the field names |
| 28 | 28 | $fields = array_keys($this->binding_names); |
| 29 | - $fields = '`' . implode('`, `', $fields) . '`'; |
|
| 29 | + $fields = '`'.implode('`, `', $fields).'`'; |
|
| 30 | 30 | $bindings = implode(', ', array_keys($this->bindings())); |
| 31 | 31 | |
| 32 | 32 | return sprintf('INSERT INTO `%s` (%s) VALUES (%s)', $this->table, $fields, $bindings); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $schema = Grammar::identifier($this->table()); |
| 26 | 26 | if (!empty($this->alias())) { |
| 27 | - $schema .= ' ' . Grammar::identifier($this->alias()); |
|
| 27 | + $schema .= ' '.Grammar::identifier($this->alias()); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $ret = sprintf('SELECT %s FROM %s', $this->deck, $schema); |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | Clause::LIMIT |
| 40 | 40 | ] as $clause |
| 41 | 41 | ) { |
| 42 | - if($this->clause($clause) === null) |
|
| 42 | + if ($this->clause($clause) === null) |
|
| 43 | 43 | continue; |
| 44 | 44 | |
| 45 | - $ret .= ' ' . $this->clause($clause); |
|
| 45 | + $ret .= ' '.$this->clause($clause); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return $ret; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | if (is_int($alias)) { |
| 80 | 80 | $alias = null; |
| 81 | 81 | } |
| 82 | - if(!isset($this->deck)){ |
|
| 82 | + if (!isset($this->deck)) { |
|
| 83 | 83 | $this->deck = new Deck($column, $alias); |
| 84 | 84 | } else { |
| 85 | 85 | $this->deck->add($column, $alias); |
@@ -39,8 +39,9 @@ discard block |
||
| 39 | 39 | Clause::LIMIT |
| 40 | 40 | ] as $clause |
| 41 | 41 | ) { |
| 42 | - if($this->clause($clause) === null) |
|
| 43 | - continue; |
|
| 42 | + if($this->clause($clause) === null) { |
|
| 43 | + continue; |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | 46 | $ret .= ' ' . $this->clause($clause); |
| 46 | 47 | } |
@@ -71,8 +72,9 @@ discard block |
||
| 71 | 72 | */ |
| 72 | 73 | public function selectAlso(array $setter): self |
| 73 | 74 | { |
| 74 | - if (empty($setter)) |
|
| 75 | - throw new \InvalidArgumentException('EMPTY_SETTER_ARRAY'); |
|
| 75 | + if (empty($setter)) { |
|
| 76 | + throw new \InvalidArgumentException('EMPTY_SETTER_ARRAY'); |
|
| 77 | + } |
|
| 76 | 78 | |
| 77 | 79 | foreach ($setter as $alias => $column) { |
| 78 | 80 | |