Passed
Push — master ( e92e1f...a725e0 )
by y
06:32
created
src/DB/Record.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      * @param string|EntityInterface $class
65 65
      * @return Record
66 66
      */
67
-    public static function fromClass (DB $db, $class) {
67
+    public static function fromClass(DB $db, $class) {
68 68
         return (function() use ($db, $class) {
69 69
             $rClass = new ReflectionClass($class);
70 70
             $columns = [];
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      * @param string[] $columns Property names.
94 94
      * @param EAV[] $eav Keyed by property name.
95 95
      */
96
-    public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
96
+    public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
97 97
         parent::__construct($db, $table, $columns);
98 98
         $this->proto = $proto;
99 99
         (function() use ($proto, $columns, $eav) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @param array[] $eavMatch `[eav property => attribute => mixed]`
131 131
      * @return Select
132 132
      */
133
-    public function find (array $match, array $eavMatch = []) {
133
+    public function find(array $match, array $eavMatch = []) {
134 134
         $select = $this->select();
135 135
         foreach ($match as $a => $b) {
136 136
             $select->where($this->db->match($this[$a] ?? $a, $b));
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      * @param Statement $statement
149 149
      * @return EntityInterface[] Keyed by ID
150 150
      */
151
-    public function getAll (Statement $statement): array {
151
+    public function getAll(Statement $statement): array {
152 152
         return iterator_to_array($this->getEach($statement));
153 153
     }
154 154
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @param Statement $statement
160 160
      * @return Generator|EntityInterface[] Keyed by ID
161 161
      */
162
-    public function getEach (Statement $statement) {
162
+    public function getEach(Statement $statement) {
163 163
         do {
164 164
             $entities = [];
165 165
             for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) {
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
      * @param string $property
177 177
      * @return EAV
178 178
      */
179
-    final public function getEav (string $property) {
179
+    final public function getEav(string $property) {
180 180
         return $this->eav[$property];
181 181
     }
182 182
 
183 183
     /**
184 184
      * @return EntityInterface
185 185
      */
186
-    public function getProto () {
186
+    public function getProto() {
187 187
         return $this->proto;
188 188
     }
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param EntityInterface $entity
192 192
      * @return array
193 193
      */
194
-    protected function getValues (EntityInterface $entity): array {
194
+    protected function getValues(EntityInterface $entity): array {
195 195
         $values = [];
196 196
         foreach (array_keys($this->columns) as $name) {
197 197
             $values[$name] = $this->properties[$name]->getValue($entity);
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      * @param int $id
206 206
      * @return null|EntityInterface
207 207
      */
208
-    public function load (int $id) {
208
+    public function load(int $id) {
209 209
         $load = $this->cache(__FUNCTION__, function() {
210 210
             return $this->select(array_keys($this->columns))->where('id = ?')->prepare();
211 211
         });
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      *
224 224
      * @param EntityInterface[] $entities
225 225
      */
226
-    protected function loadEav (array $entities): void {
226
+    protected function loadEav(array $entities): void {
227 227
         $ids = array_keys($entities);
228 228
         foreach ($this->eav as $name => $eav) {
229 229
             foreach ($eav->loadAll($ids) as $id => $values) {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * @param EntityInterface $entity
239 239
      * @return int ID
240 240
      */
241
-    public function save (EntityInterface $entity): int {
241
+    public function save(EntityInterface $entity): int {
242 242
         if (!$entity->getId()) {
243 243
             $this->saveInsert($entity);
244 244
         }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     /**
253 253
      * @param EntityInterface $entity
254 254
      */
255
-    protected function saveEav (EntityInterface $entity): void {
255
+    protected function saveEav(EntityInterface $entity): void {
256 256
         $id = $entity->getId();
257 257
         foreach ($this->eav as $name => $eav) {
258 258
             // may be null to skip
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      *
269 269
      * @param EntityInterface $entity
270 270
      */
271
-    protected function saveInsert (EntityInterface $entity): void {
271
+    protected function saveInsert(EntityInterface $entity): void {
272 272
         $insert = $this->cache(__FUNCTION__, function() {
273 273
             $slots = SQL::slots(array_keys($this->columns));
274 274
             unset($slots['id']);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      *
287 287
      * @param EntityInterface $entity
288 288
      */
289
-    protected function saveUpdate (EntityInterface $entity): void {
289
+    protected function saveUpdate(EntityInterface $entity): void {
290 290
         $this->cache(__FUNCTION__, function() {
291 291
             $slots = SQL::slotsEqual(array_keys($this->columns));
292 292
             unset($slots['id']);
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * @param array $columns Defaults to all columns.
302 302
      * @return Select
303 303
      */
304
-    public function select (array $columns = []) {
304
+    public function select(array $columns = []) {
305 305
         $select = parent::select($columns);
306 306
         if (empty($columns)) {
307 307
             $select->setFetcher(function(Statement $statement) {
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      * @param EntityInterface $proto
316 316
      * @return $this
317 317
      */
318
-    public function setProto (EntityInterface $proto) {
318
+    public function setProto(EntityInterface $proto) {
319 319
         $this->proto = $proto;
320 320
         return $this;
321 321
     }
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @param EntityInterface $entity
325 325
      * @param array $values
326 326
      */
327
-    protected function setValues (EntityInterface $entity, array $values): void {
327
+    protected function setValues(EntityInterface $entity, array $values): void {
328 328
         foreach ($values as $name => $value) {
329 329
             settype($value, $this->types[$name]);
330 330
             $this->properties[$name]->setValue($entity, $value);
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -75,8 +75,7 @@  discard block
 block discarded – undo
75 75
             foreach ($rClass->getProperties() as $rProp) {
76 76
                 if (preg_match('/@col(umn)?[\s$]/', $rProp->getDocComment())) {
77 77
                     $columns[] = $rProp->getName();
78
-                }
79
-                elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
78
+                } elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
80 79
                     $eav[$rProp->getName()] = EAV::factory($db, $attr['table']);
81 80
                 }
82 81
             }
@@ -243,8 +242,7 @@  discard block
 block discarded – undo
243 242
     public function save (EntityInterface $entity): int {
244 243
         if (!$entity->getId()) {
245 244
             $this->saveInsert($entity);
246
-        }
247
-        else {
245
+        } else {
248 246
             $this->saveUpdate($entity);
249 247
         }
250 248
         $this->saveEav($entity);
Please login to merge, or discard this patch.
src/DB/SQL/Choice.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,8 +85,10 @@
 block discarded – undo
85 85
      * @param string|ValueInterface $else
86 86
      * @return $this
87 87
      */
88
-    public function else ($else) {
88
+    public function else {
89
+        ($else) {
89 90
         $this->else = isset($else) ? $this->db->quote($else) : null;
91
+    }
90 92
         return $this;
91 93
     }
92 94
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      * @param null|string $subject
60 60
      * @param array $values `[when => then]` for the subject.
61 61
      */
62
-    public function __construct (DB $db, string $subject = null, array $values = []) {
62
+    public function __construct(DB $db, string $subject = null, array $values = []) {
63 63
         parent::__construct($db, '');
64 64
         $this->subject = $subject;
65 65
         $this->whenValues($values);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     /**
69 69
      * @return string
70 70
      */
71
-    public function __toString () {
71
+    public function __toString() {
72 72
         $sql = 'CASE';
73 73
         if (isset($this->subject)) {
74 74
             $sql .= " {$this->subject}";
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      * @param string|ValueInterface $then
100 100
      * @return $this
101 101
      */
102
-    public function when ($expression, $then) {
102
+    public function when($expression, $then) {
103 103
         $this->values[$this->db->quote($expression)] = $this->db->quote($then);
104 104
         return $this;
105 105
     }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      * @param array $values `[when => then]`
114 114
      * @return $this
115 115
      */
116
-    public function whenValues (array $values) {
116
+    public function whenValues(array $values) {
117 117
         foreach ($values as $when => $then) {
118 118
             $this->when($when, $then);
119 119
         }
Please login to merge, or discard this patch.
src/DB/SQL.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@  discard block
 block discarded – undo
18 18
      * @param int|array|Countable $count
19 19
      * @return ExpressionInterface[]
20 20
      */
21
-    public static function marks ($count): array {
21
+    public static function marks($count): array {
22 22
         static $mark;
23 23
         $mark ??= new class implements ExpressionInterface {
24 24
 
25
-            public function __toString () {
25
+            public function __toString() {
26 26
                 return '?';
27 27
             }
28 28
         };
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @param string[] $columns
42 42
      * @return string[] `["column" => ":column"]`
43 43
      */
44
-    public static function slots (array $columns): array {
44
+    public static function slots(array $columns): array {
45 45
         $slots = [];
46 46
         foreach ($columns as $column) {
47 47
             $slots[$column] = ':' . str_replace('.', '__', $column);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      * @param string[] $columns
54 54
      * @return string[] `["column" => "column=:column"]`
55 55
      */
56
-    public static function slotsEqual (array $columns): array {
56
+    public static function slotsEqual(array $columns): array {
57 57
         $slots = static::slots($columns);
58 58
         foreach ($slots as $column => $slot) {
59 59
             $slots[$column] = "{$column} = {$slot}";
@@ -61,6 +61,6 @@  discard block
 block discarded – undo
61 61
         return $slots;
62 62
     }
63 63
 
64
-    final private function __construct () {
64
+    final private function __construct() {
65 65
     }
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/SQL/DateTimeTrait.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 trait DateTimeTrait {
11 11
 
12
-    abstract public function __toString ();
12
+    abstract public function __toString();
13 13
 
14 14
     /**
15 15
      * @var DB
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @return Text
23 23
      */
24
-    public function getDate () {
24
+    public function getDate() {
25 25
         return Text::factory($this->db, $this->getDateTimeFormat('%Y-%m-%d'));
26 26
     }
27 27
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param string|array $format Format, or formats keyed by driver name.
32 32
      * @return Text
33 33
      */
34
-    public function getDateTimeFormat ($format) {
34
+    public function getDateTimeFormat($format) {
35 35
         if (is_array($format)) {
36 36
             $format = $format[$this->db->getDriver()];
37 37
         }
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return Numeric
49 49
      */
50
-    public function getDay () {
50
+    public function getDay() {
51 51
         return Numeric::factory($this->db, $this->getDateTimeFormat('%d'));
52 52
     }
53 53
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return Numeric
58 58
      */
59
-    public function getDayOfWeek () {
59
+    public function getDayOfWeek() {
60 60
         return Numeric::factory($this->db, $this->getDateTimeFormat('%w'));
61 61
     }
62 62
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      *
66 66
      * @return Numeric
67 67
      */
68
-    public function getDayOfYear () {
68
+    public function getDayOfYear() {
69 69
         return Numeric::factory($this->db, $this->getDateTimeFormat('%j'));
70 70
     }
71 71
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return Numeric
76 76
      */
77
-    public function getHours () {
77
+    public function getHours() {
78 78
         return Numeric::factory($this->db, $this->getDateTimeFormat('%H'));
79 79
     }
80 80
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return Numeric
85 85
      */
86
-    public function getMinutes () {
86
+    public function getMinutes() {
87 87
         return Numeric::factory($this->db, $this->getDateTimeFormat([
88 88
             'mysql' => '%i',
89 89
             'sqlite' => '%M'
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @return Numeric
97 97
      */
98
-    public function getMonth () {
98
+    public function getMonth() {
99 99
         return Numeric::factory($this->db, $this->getDateTimeFormat('%m'));
100 100
     }
101 101
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      *
105 105
      * @return Numeric
106 106
      */
107
-    public function getSeconds () {
107
+    public function getSeconds() {
108 108
         return Numeric::factory($this->db, $this->getDateTimeFormat('%S'));
109 109
     }
110 110
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @return Text
115 115
      */
116
-    public function getTime () {
116
+    public function getTime() {
117 117
         return Text::factory($this->db, $this->getDateTimeFormat([
118 118
             'mysql' => '%H:%i:%S',
119 119
             'sqlite' => '%H:%M:%S'
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      *
126 126
      * @return Numeric
127 127
      */
128
-    public function getTimestamp () {
128
+    public function getTimestamp() {
129 129
         if ($this->db->isSQLite()) {
130 130
             return Numeric::factory($this->db, "STRFTIME('%s',{$this})");
131 131
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return Numeric
139 139
      */
140
-    public function getWeekOfYear () {
140
+    public function getWeekOfYear() {
141 141
         return Numeric::factory($this->db, $this->getDateTimeFormat([
142 142
             'mysql' => '%U',
143 143
             'sqlite' => '%W'
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      *
150 150
      * @return Numeric
151 151
      */
152
-    public function getYear () {
152
+    public function getYear() {
153 153
         return Numeric::factory($this->db, $this->getDateTimeFormat('%Y'));
154 154
     }
155 155
 }
156 156
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/SQL/Text.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @return Numeric
16 16
      */
17
-    public function toFloat () {
17
+    public function toFloat() {
18 18
         if ($this->db->isSQLite()) {
19 19
             return Numeric::factory($this->db, "CAST({$this} AS REAL)");
20 20
         }
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @return Numeric
28 28
      */
29
-    public function toInt () {
29
+    public function toInt() {
30 30
         if ($this->db->isSQLite()) {
31 31
             return Numeric::factory($this->db, "CAST({$this} AS INTEGER)");
32 32
         }
Please login to merge, or discard this patch.
src/DB/SQL/NumericTrait.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 trait NumericTrait {
11 11
 
12
-    abstract public function __toString ();
12
+    abstract public function __toString();
13 13
 
14 14
     /**
15 15
      * @var DB
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @return Numeric
23 23
      */
24
-    public function abs () {
24
+    public function abs() {
25 25
         return Numeric::factory($this->db, "ABS({$this})");
26 26
     }
27 27
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param number|ValueInterface $arg
32 32
      * @return Numeric
33 33
      */
34
-    public function add ($arg) {
34
+    public function add($arg) {
35 35
         return Numeric::factory($this->db, "({$this} + {$arg})");
36 36
     }
37 37
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return Numeric
42 42
      */
43
-    public function ceil () {
43
+    public function ceil() {
44 44
         return Numeric::factory($this->db, "CEIL({$this})");
45 45
     }
46 46
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @param number|ValueInterface $arg
51 51
      * @return Numeric
52 52
      */
53
-    public function divide ($arg) {
53
+    public function divide($arg) {
54 54
         return Numeric::factory($this->db, "({$this} / {$arg})");
55 55
     }
56 56
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @return Numeric
61 61
      */
62
-    public function floor () {
62
+    public function floor() {
63 63
         return Numeric::factory($this->db, "FLOOR({$this})");
64 64
     }
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @return Predicate
70 70
      */
71
-    public function isEven () {
71
+    public function isEven() {
72 72
         return Predicate::factory($this->db, "({$this} % 2) = 0");
73 73
     }
74 74
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @return Predicate
79 79
      */
80
-    public function isNegative () {
80
+    public function isNegative() {
81 81
         return Predicate::factory($this->db, "{$this} < 0");
82 82
     }
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
      * @return Predicate
88 88
      */
89
-    public function isOdd () {
89
+    public function isOdd() {
90 90
         return Predicate::factory($this->db, "({$this} % 2) <> 0");
91 91
     }
92 92
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @return Predicate
97 97
      */
98
-    public function isPositive () {
98
+    public function isPositive() {
99 99
         return Predicate::factory($this->db, "{$this} > 0");
100 100
     }
101 101
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      * @param number|ValueInterface $arg
106 106
      * @return Numeric
107 107
      */
108
-    public function modulo ($arg) {
108
+    public function modulo($arg) {
109 109
         return Numeric::factory($this->db, "({$this} % {$arg})");
110 110
     }
111 111
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      * @param number|ValueInterface $arg
116 116
      * @return Numeric
117 117
      */
118
-    public function multiply ($arg) {
118
+    public function multiply($arg) {
119 119
         return Numeric::factory($this->db, "({$this} * {$arg})");
120 120
     }
121 121
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * @param number|ValueInterface $exponent
126 126
      * @return Numeric
127 127
      */
128
-    public function pow ($exponent) {
128
+    public function pow($exponent) {
129 129
         return Numeric::factory($this->db, "POW({$this},{$exponent})");
130 130
     }
131 131
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * @param int $decimals
136 136
      * @return Numeric
137 137
      */
138
-    public function round (int $decimals = 0) {
138
+    public function round(int $decimals = 0) {
139 139
         return Numeric::factory($this->db, "ROUND({$this},{$decimals})");
140 140
     }
141 141
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      * @param number|ValueInterface $arg
146 146
      * @return Numeric
147 147
      */
148
-    public function subtract (ValueInterface $arg) {
148
+    public function subtract(ValueInterface $arg) {
149 149
         return Numeric::factory($this->db, "({$this} - {$arg})");
150 150
     }
151 151
 }
152 152
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/SQL/Numeric.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
      *
15 15
      * @return Text
16 16
      */
17
-    public function toText () {
17
+    public function toText() {
18 18
         if ($this->db->isSQLite()) {
19 19
             return Text::factory($this->db, "CAST({$this} AS TEXT)");
20 20
         }
Please login to merge, or discard this patch.
src/DB/SQL/Predicate.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      *
13 13
      * @return static
14 14
      */
15
-    public function not () {
15
+    public function not() {
16 16
         return static::factory($this->db, "NOT({$this})");
17 17
     }
18 18
 
Please login to merge, or discard this patch.
src/DB/SQL/Expression.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @param DB $db
29 29
      * @param string $expression
30 30
      */
31
-    public function __construct (DB $db, string $expression) {
31
+    public function __construct(DB $db, string $expression) {
32 32
         $this->db = $db;
33 33
         $this->expression = $expression;
34 34
     }
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * @return string
38 38
      */
39
-    public function __toString () {
39
+    public function __toString() {
40 40
         return $this->expression;
41 41
     }
42 42
 }
43 43
\ No newline at end of file
Please login to merge, or discard this patch.