@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function withValue($value, string $bind_label = null): self |
64 | 64 | { |
65 | 65 | $this->bindings[$this->bindLabel($bind_label)] = $value; |
66 | - $this->right = ':' . $this->bindLabel($bind_label); |
|
66 | + $this->right = ':'.$this->bindLabel($bind_label); |
|
67 | 67 | return $this; |
68 | 68 | } |
69 | 69 | |
@@ -79,7 +79,7 @@ discard block |
||
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 | } |
@@ -118,8 +118,9 @@ |
||
118 | 118 | return $this->bind_label; |
119 | 119 | } |
120 | 120 | // getter |
121 | - else if ($this->bind_label !== null) |
|
122 | - return $this->bind_label; |
|
121 | + else if ($this->bind_label !== null) { |
|
122 | + return $this->bind_label; |
|
123 | + } |
|
123 | 124 | |
124 | 125 | // generator |
125 | 126 | else if (is_array($this->left)) { |
@@ -42,8 +42,7 @@ |
||
42 | 42 | // no props, assumes connection made, verify and return |
43 | 43 | if (isset($dsn, $user, $pass)) { |
44 | 44 | self::$connection = new Connection($dsn, $user, $pass); |
45 | - } |
|
46 | - elseif (self::$connection === null) { |
|
45 | + } elseif (self::$connection === null) { |
|
47 | 46 | throw new CruditesException('NO_DATABASE'); |
48 | 47 | } |
49 | 48 |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $res = self::$connection->result($select); |
62 | 62 | $res = $res->ret(\PDO::FETCH_COLUMN); |
63 | 63 | if (is_array($res)) { |
64 | - return (int) current($res); |
|
64 | + return (int)current($res); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | return null; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $ret = []; |
79 | 79 | |
80 | 80 | $res = self::$connection->result($select); |
81 | - if($res->ran()) { |
|
81 | + if ($res->ran()) { |
|
82 | 82 | |
83 | 83 | $primary_keys = self::$connection->schema()->primaryKeys($select->table()); |
84 | 84 | $pk_name = implode('_', $primary_keys); |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | public function __toString() |
47 | 47 | { |
48 | - return PHP_EOL . 'load: ' |
|
48 | + return PHP_EOL.'load: ' |
|
49 | 49 | . json_encode($this->load) |
50 | - . PHP_EOL . 'alterations: ' |
|
50 | + . PHP_EOL.'alterations: ' |
|
51 | 51 | . json_encode(array_keys($this->alterations)); |
52 | 52 | } |
53 | 53 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | { |
135 | 135 | foreach (array_keys($datass) as $field_name) { |
136 | 136 | |
137 | - if($datass[$field_name] === $this->get($field_name)) { |
|
137 | + if ($datass[$field_name] === $this->get($field_name)) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | // Replace empty strings with null if the column is nullable |
153 | - if (trim('' . $datass[$field_name]) === '' && $attributes->nullable()) { |
|
153 | + if (trim(''.$datass[$field_name]) === '' && $attributes->nullable()) { |
|
154 | 154 | $datass[$field_name] = null; |
155 | 155 | } |
156 | 156 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function values(array $dat_ass): self |
23 | 23 | { |
24 | - $this->binding_names []= $this->addBindings($dat_ass); |
|
24 | + $this->binding_names [] = $this->addBindings($dat_ass); |
|
25 | 25 | |
26 | 26 | return $this; |
27 | 27 | } |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | |
38 | 38 | $fields_labels = array_shift($this->binding_names); |
39 | 39 | $fields = array_keys($fields_labels); |
40 | - $fields = '`' . implode('`,`', $fields) . '`'; |
|
40 | + $fields = '`'.implode('`,`', $fields).'`'; |
|
41 | 41 | |
42 | 42 | $bindings = implode(',:', $fields_labels); |
43 | 43 | |
44 | 44 | $statement = sprintf('INSERT INTO `%s` (%s) VALUES (:%s)', $this->table, $fields, $bindings); |
45 | - foreach($this->binding_names as $bindings){ |
|
45 | + foreach ($this->binding_names as $bindings) { |
|
46 | 46 | $statement .= sprintf(',(:%s)', implode(',:', $bindings)); |
47 | 47 | } |
48 | 48 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $schema = Grammar::identifier($this->table()); |
32 | 32 | if (!empty($this->alias())) { |
33 | - $schema .= ' ' . Grammar::identifier($this->alias()); |
|
33 | + $schema .= ' '.Grammar::identifier($this->alias()); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $ret = sprintf('SELECT %s FROM %s', $this->deck, $schema); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | Clause::LIMIT |
47 | 47 | ] as $clause |
48 | 48 | ) { |
49 | - if($this->clause($clause) === null) |
|
49 | + if ($this->clause($clause) === null) |
|
50 | 50 | continue; |
51 | 51 | |
52 | - $ret .= ' ' . $this->clause($clause); |
|
52 | + $ret .= ' '.$this->clause($clause); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $ret; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | if (is_int($alias)) { |
87 | 87 | $alias = null; |
88 | 88 | } |
89 | - if(!isset($this->deck)){ |
|
89 | + if (!isset($this->deck)) { |
|
90 | 90 | $this->deck = new Deck($column, $alias); |
91 | 91 | } else { |
92 | 92 | $this->deck->add($column, $alias); |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | return $where; |
104 | 104 | } |
105 | 105 | |
106 | - public function join(string $table, ?string $alias=null): Join |
|
106 | + public function join(string $table, ?string $alias = null): Join |
|
107 | 107 | { |
108 | 108 | $join = new Join($table, $alias); |
109 | 109 | |
110 | - if($this->clause(Clause::JOINS) === null){ |
|
110 | + if ($this->clause(Clause::JOINS) === null) { |
|
111 | 111 | $joins = new Joins([$join]); |
112 | 112 | $this->add($joins); |
113 | 113 | } |
114 | - else{ |
|
114 | + else { |
|
115 | 115 | $this->clause(Clause::JOINS)->add($join); |
116 | 116 | } |
117 | 117 |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | Clause::LIMIT |
47 | 47 | ] as $clause |
48 | 48 | ) { |
49 | - if($this->clause($clause) === null) |
|
50 | - continue; |
|
49 | + if($this->clause($clause) === null) { |
|
50 | + continue; |
|
51 | + } |
|
51 | 52 | |
52 | 53 | $ret .= ' ' . $this->clause($clause); |
53 | 54 | } |
@@ -78,8 +79,9 @@ discard block |
||
78 | 79 | */ |
79 | 80 | public function selectAlso(array $setter): self |
80 | 81 | { |
81 | - if (empty($setter)) |
|
82 | - throw new \InvalidArgumentException('EMPTY_SETTER_ARRAY'); |
|
82 | + if (empty($setter)) { |
|
83 | + throw new \InvalidArgumentException('EMPTY_SETTER_ARRAY'); |
|
84 | + } |
|
83 | 85 | |
84 | 86 | foreach ($setter as $alias => $column) { |
85 | 87 | |
@@ -110,8 +112,7 @@ discard block |
||
110 | 112 | if($this->clause(Clause::JOINS) === null){ |
111 | 113 | $joins = new Joins([$join]); |
112 | 114 | $this->add($joins); |
113 | - } |
|
114 | - else{ |
|
115 | + } else{ |
|
115 | 116 | $this->clause(Clause::JOINS)->add($join); |
116 | 117 | } |
117 | 118 |
@@ -72,8 +72,9 @@ discard block |
||
72 | 72 | $this->statement = $statement; |
73 | 73 | } |
74 | 74 | |
75 | - if ($this->statement instanceof \PDOStatement) |
|
76 | - $this->prepared = $this->statement; |
|
75 | + if ($this->statement instanceof \PDOStatement) { |
|
76 | + $this->prepared = $this->statement; |
|
77 | + } |
|
77 | 78 | |
78 | 79 | $this->run($bindings); |
79 | 80 | } |
@@ -97,8 +98,9 @@ discard block |
||
97 | 98 | $pdo_cascade = $this->pdo; |
98 | 99 | } |
99 | 100 | // two time testing is necessary, f.i. lastInsertId is a PDO method, not a PDOStatement method |
100 | - if ($pdo_cascade === null || !method_exists($pdo_cascade, $method)) |
|
101 | - throw new \BadMethodCallException("__call($method) not possible in PDO or PDOStatement"); |
|
101 | + if ($pdo_cascade === null || !method_exists($pdo_cascade, $method)) { |
|
102 | + throw new \BadMethodCallException("__call($method) not possible in PDO or PDOStatement"); |
|
103 | + } |
|
102 | 104 | |
103 | 105 | return call_user_func_array([$pdo_cascade, $method], $args); |
104 | 106 | } |
@@ -130,8 +132,9 @@ discard block |
||
130 | 132 | throw new CruditesException('No executed statement available for fetching results'); |
131 | 133 | } |
132 | 134 | |
133 | - if ($mode === \PDO::FETCH_CLASS) |
|
134 | - return $this->executed->fetchAll($mode, $fetch_argument, $ctor_args); |
|
135 | + if ($mode === \PDO::FETCH_CLASS) { |
|
136 | + return $this->executed->fetchAll($mode, $fetch_argument, $ctor_args); |
|
137 | + } |
|
135 | 138 | |
136 | 139 | return $this->executed->fetchAll($mode); |
137 | 140 | } |
@@ -100,13 +100,13 @@ |
||
100 | 100 | $this->assertEquals($expected, (string)$query); |
101 | 101 | |
102 | 102 | $query->join('products', 'p')->on('product_id', 'oi', 'product_id'); |
103 | - $this->assertEquals($expected .' JOIN `products` `p` ON `p`.`product_id` = `oi`.`product_id`', (string)$query); |
|
103 | + $this->assertEquals($expected.' JOIN `products` `p` ON `p`.`product_id` = `oi`.`product_id`', (string)$query); |
|
104 | 104 | |
105 | 105 | $query->selectAlso(['productName' => ['p', 'name']]); |
106 | 106 | $expected = 'SELECT quantity,price AS `sold_price`,`p`.`name` AS `productName` FROM `order_items` `oi` JOIN `products` `p` ON `p`.`product_id` = `oi`.`product_id`'; |
107 | 107 | $this->assertEquals($expected, (string)$query); |
108 | 108 | |
109 | - $query->join('orders', 'o')->on('order_id','oi', 'order_id'); |
|
109 | + $query->join('orders', 'o')->on('order_id', 'oi', 'order_id'); |
|
110 | 110 | $expected .= ' JOIN `orders` `o` ON `o`.`order_id` = `oi`.`order_id`'; |
111 | 111 | $this->assertEquals($expected, (string)$query); |
112 | 112 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | private string $table = 'users'; |
13 | 13 | private array $data_pk_match = ['id' => 1]; |
14 | 14 | private array $data_form = ['name' => 'Test', 'username' => 'john_doe']; |
15 | - private array $data_form_with_id = ['name' => 'Test', 'username' => 'john_doe'] + ['id' => 1]; |
|
15 | + private array $data_form_with_id = ['name' => 'Test', 'username' => 'john_doe']+['id' => 1]; |
|
16 | 16 | |
17 | 17 | // setup |
18 | 18 | public function setUp(): void |