Passed
Push — master ( 5b4064...cd467c )
by Valentin
17:10 queued 13:04
created
src/Validation/src/Checker/DatetimeChecker/ThresholdChecker.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
         bool $useMicroSeconds = false
23 23
     ): bool {
24 24
         $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds);
25
-        if (is_bool($compare)) {
25
+        if (is_bool($compare)){
26 26
             return $compare;
27 27
         }
28 28
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         bool $useMicroSeconds = false
46 46
     ): bool {
47 47
         $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds);
48
-        if (is_bool($compare)) {
48
+        if (is_bool($compare)){
49 49
             return $compare;
50 50
         }
51 51
 
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
      */
59 59
     private function date($value): ?\DateTimeImmutable
60 60
     {
61
-        if ($value instanceof \DateTimeImmutable) {
61
+        if ($value instanceof \DateTimeImmutable){
62 62
             return $value;
63 63
         }
64 64
 
65
-        if ($value instanceof \DateTime) {
65
+        if ($value instanceof \DateTime){
66 66
             return \DateTimeImmutable::createFromMutable($value);
67 67
         }
68 68
 
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
      */
78 78
     private function compare(?\DateTimeImmutable $date, ?\DateTimeImmutable $threshold, bool $useMicroseconds)
79 79
     {
80
-        if ($date === null) {
80
+        if ($date === null){
81 81
             return false;
82 82
         }
83 83
 
84
-        if ($threshold === null) {
84
+        if ($threshold === null){
85 85
             return true;
86 86
         }
87 87
 
88
-        if (!$useMicroseconds) {
88
+        if (!$useMicroseconds){
89 89
             $date = $this->dropMicroSeconds($date);
90 90
             $threshold = $this->dropMicroSeconds($threshold);
91 91
         }
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,8 @@  discard block
 block discarded – undo
22 22
         bool $useMicroSeconds = false
23 23
     ): bool {
24 24
         $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds);
25
-        if (is_bool($compare)) {
25
+        if (is_bool($compare))
26
+        {
26 27
             return $compare;
27 28
         }
28 29
 
@@ -45,7 +46,8 @@  discard block
 block discarded – undo
45 46
         bool $useMicroSeconds = false
46 47
     ): bool {
47 48
         $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds);
48
-        if (is_bool($compare)) {
49
+        if (is_bool($compare))
50
+        {
49 51
             return $compare;
50 52
         }
51 53
 
@@ -58,11 +60,13 @@  discard block
 block discarded – undo
58 60
      */
59 61
     private function date($value): ?\DateTimeImmutable
60 62
     {
61
-        if ($value instanceof \DateTimeImmutable) {
63
+        if ($value instanceof \DateTimeImmutable)
64
+        {
62 65
             return $value;
63 66
         }
64 67
 
65
-        if ($value instanceof \DateTime) {
68
+        if ($value instanceof \DateTime)
69
+        {
66 70
             return \DateTimeImmutable::createFromMutable($value);
67 71
         }
68 72
 
@@ -77,15 +81,18 @@  discard block
 block discarded – undo
77 81
      */
78 82
     private function compare(?\DateTimeImmutable $date, ?\DateTimeImmutable $threshold, bool $useMicroseconds)
79 83
     {
80
-        if ($date === null) {
84
+        if ($date === null)
85
+        {
81 86
             return false;
82 87
         }
83 88
 
84
-        if ($threshold === null) {
89
+        if ($threshold === null)
90
+        {
85 91
             return true;
86 92
         }
87 93
 
88
-        if (!$useMicroseconds) {
94
+        if (!$useMicroseconds)
95
+        {
89 96
             $date = $this->dropMicroSeconds($date);
90 97
             $threshold = $this->dropMicroSeconds($threshold);
91 98
         }
Please login to merge, or discard this patch.
src/Validation/src/Checker/DatetimeChecker.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function format($value, string $format): bool
84 84
     {
85
-        if (!$this->isApplicableValue($value)) {
85
+        if (!$this->isApplicableValue($value)){
86 86
             return false;
87 87
         }
88 88
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public function timezone($value): bool
112 112
     {
113
-        if (!is_scalar($value)) {
113
+        if (!is_scalar($value)){
114 114
             return false;
115 115
         }
116 116
 
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
      */
151 151
     private function now(): ?\DateTimeInterface
152 152
     {
153
-        try {
153
+        try{
154 154
             return $this->date($this->now ?: 'now');
155
-        } catch (\Throwable $e) {
155
+        }catch (\Throwable $e){
156 156
             //here's the fail;
157 157
         }
158 158
 
@@ -165,25 +165,25 @@  discard block
 block discarded – undo
165 165
      */
166 166
     private function date($value): ?\DateTimeInterface
167 167
     {
168
-        if (is_callable($value)) {
168
+        if (is_callable($value)){
169 169
             $value = $value();
170 170
         }
171 171
 
172
-        if ($value instanceof \DateTimeInterface) {
172
+        if ($value instanceof \DateTimeInterface){
173 173
             return $value;
174 174
         }
175 175
 
176
-        if (!$this->isApplicableValue($value)) {
176
+        if (!$this->isApplicableValue($value)){
177 177
             return null;
178 178
         }
179 179
 
180
-        try {
181
-            if (!$value) {
180
+        try{
181
+            if (!$value){
182 182
                 $value = '0';
183 183
             }
184 184
 
185 185
             return new \DateTimeImmutable(is_numeric($value) ? sprintf('@%d', $value) : trim($value));
186
-        } catch (\Throwable $e) {
186
+        }catch (\Throwable $e){
187 187
             //here's the fail;
188 188
         }
189 189
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     private function fromField(string $field): ?\DateTimeInterface
207 207
     {
208 208
         $before = $this->getValidator()->getValue($field);
209
-        if ($before !== null) {
209
+        if ($before !== null){
210 210
             return $this->date($before);
211 211
         }
212 212
 
Please login to merge, or discard this patch.
Braces   +24 added lines, -11 removed lines patch added patch discarded remove patch
@@ -82,7 +82,8 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function format($value, string $format): bool
84 84
     {
85
-        if (!$this->isApplicableValue($value)) {
85
+        if (!$this->isApplicableValue($value))
86
+        {
86 87
             return false;
87 88
         }
88 89
 
@@ -110,7 +111,8 @@  discard block
 block discarded – undo
110 111
      */
111 112
     public function timezone($value): bool
112 113
     {
113
-        if (!is_scalar($value)) {
114
+        if (!is_scalar($value))
115
+        {
114 116
             return false;
115 117
         }
116 118
 
@@ -150,9 +152,12 @@  discard block
 block discarded – undo
150 152
      */
151 153
     private function now(): ?\DateTimeInterface
152 154
     {
153
-        try {
155
+        try
156
+        {
154 157
             return $this->date($this->now ?: 'now');
155
-        } catch (\Throwable $e) {
158
+        }
159
+        catch (\Throwable $e)
160
+        {
156 161
             //here's the fail;
157 162
         }
158 163
 
@@ -165,25 +170,32 @@  discard block
 block discarded – undo
165 170
      */
166 171
     private function date($value): ?\DateTimeInterface
167 172
     {
168
-        if (is_callable($value)) {
173
+        if (is_callable($value))
174
+        {
169 175
             $value = $value();
170 176
         }
171 177
 
172
-        if ($value instanceof \DateTimeInterface) {
178
+        if ($value instanceof \DateTimeInterface)
179
+        {
173 180
             return $value;
174 181
         }
175 182
 
176
-        if (!$this->isApplicableValue($value)) {
183
+        if (!$this->isApplicableValue($value))
184
+        {
177 185
             return null;
178 186
         }
179 187
 
180
-        try {
181
-            if (!$value) {
188
+        try
189
+        {
190
+            if (!$value)
191
+            {
182 192
                 $value = '0';
183 193
             }
184 194
 
185 195
             return new \DateTimeImmutable(is_numeric($value) ? sprintf('@%d', $value) : trim($value));
186
-        } catch (\Throwable $e) {
196
+        }
197
+        catch (\Throwable $e)
198
+        {
187 199
             //here's the fail;
188 200
         }
189 201
 
@@ -206,7 +218,8 @@  discard block
 block discarded – undo
206 218
     private function fromField(string $field): ?\DateTimeInterface
207 219
     {
208 220
         $before = $this->getValidator()->getValue($field);
209
-        if ($before !== null) {
221
+        if ($before !== null)
222
+        {
210 223
             return $this->date($before);
211 224
         }
212 225
 
Please login to merge, or discard this patch.
src/Validation/tests/Checkers/DatetimeTest.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             [true, $callableNow, $now, true, true]
45 45
         ];
46 46
 
47
-        $callableFutureTime = static function () {
47
+        $callableFutureTime = static function (){
48 48
             return time() + 1000;
49 49
         };
50 50
         yield from [
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             [false, $callableFutureTime, $now, true, true],
53 53
         ];
54 54
 
55
-        $callablePastTime = static function () {
55
+        $callablePastTime = static function (){
56 56
             return time() - 1000;
57 57
         };
58 58
         yield from [
@@ -231,24 +231,24 @@  discard block
 block discarded – undo
231 231
     public function validProvider(): array
232 232
     {
233 233
         return [
234
-            [true, time() - 1000,],
235
-            [true, time(),],
236
-            [true, date('u'),],
237
-            [true, time() + 1000,],
238
-            [true, '',],
239
-            [true, 'tomorrow +2hours',],
240
-            [true, 'yesterday -2hours',],
241
-            [true, 'now',],
242
-            [true, 'now + 1000 seconds',],
243
-            [true, 'now - 1000 seconds',],
244
-            [true, 0,],
245
-            [true, 1.1,],
246
-            [false, [],],
247
-            [false, false,],
248
-            [false, true,],
249
-            [false, null,],
250
-            [false, [],],
251
-            [false, new \stdClass(),],
234
+            [true, time() - 1000, ],
235
+            [true, time(), ],
236
+            [true, date('u'), ],
237
+            [true, time() + 1000, ],
238
+            [true, '', ],
239
+            [true, 'tomorrow +2hours', ],
240
+            [true, 'yesterday -2hours', ],
241
+            [true, 'now', ],
242
+            [true, 'now + 1000 seconds', ],
243
+            [true, 'now - 1000 seconds', ],
244
+            [true, 0, ],
245
+            [true, 1.1, ],
246
+            [false, [], ],
247
+            [false, false, ],
248
+            [false, true, ],
249
+            [false, null, ],
250
+            [false, [], ],
251
+            [false, new \stdClass(), ],
252 252
         ];
253 253
     }
254 254
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         $checker = new DatetimeChecker();
258 258
 
259
-        foreach (\DateTimeZone::listIdentifiers() as $identifier) {
259
+        foreach (\DateTimeZone::listIdentifiers() as $identifier){
260 260
             $this->assertTrue($checker->timezone($identifier));
261 261
             $this->assertFalse($checker->timezone(str_rot13($identifier)));
262 262
         }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 
398 398
     private function now(): \Closure
399 399
     {
400
-        return static function () {
400
+        return static function (){
401 401
             return \time();
402 402
         };
403 403
     }
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,7 +35,8 @@  discard block
 block discarded – undo
35 35
     public function nowProvider(): iterable
36 36
     {
37 37
         $now = new \DateTime();
38
-        $callableNow = static function () use ($now) {
38
+        $callableNow = static function () use ($now)
39
+        {
39 40
             return $now;
40 41
         };
41 42
 
@@ -44,7 +45,8 @@  discard block
 block discarded – undo
44 45
             [true, $callableNow, $now, true, true]
45 46
         ];
46 47
 
47
-        $callableFutureTime = static function () {
48
+        $callableFutureTime = static function ()
49
+        {
48 50
             return time() + 1000;
49 51
         };
50 52
         yield from [
@@ -52,7 +54,8 @@  discard block
 block discarded – undo
52 54
             [false, $callableFutureTime, $now, true, true],
53 55
         ];
54 56
 
55
-        $callablePastTime = static function () {
57
+        $callablePastTime = static function ()
58
+        {
56 59
             return time() - 1000;
57 60
         };
58 61
         yield from [
@@ -256,7 +259,8 @@  discard block
 block discarded – undo
256 259
     {
257 260
         $checker = new DatetimeChecker();
258 261
 
259
-        foreach (\DateTimeZone::listIdentifiers() as $identifier) {
262
+        foreach (\DateTimeZone::listIdentifiers() as $identifier)
263
+        {
260 264
             $this->assertTrue($checker->timezone($identifier));
261 265
             $this->assertFalse($checker->timezone(str_rot13($identifier)));
262 266
         }
@@ -397,21 +401,24 @@  discard block
 block discarded – undo
397 401
 
398 402
     private function now(): \Closure
399 403
     {
400
-        return static function () {
404
+        return static function ()
405
+        {
401 406
             return \time();
402 407
         };
403 408
     }
404 409
 
405 410
     private function inFuture(int $seconds): \Closure
406 411
     {
407
-        return static function () use ($seconds) {
412
+        return static function () use ($seconds)
413
+        {
408 414
             return \time() + $seconds;
409 415
         };
410 416
     }
411 417
 
412 418
     private function inPast(int $seconds): \Closure
413 419
     {
414
-        return static function () use ($seconds) {
420
+        return static function () use ($seconds)
421
+        {
415 422
             return \time() - $seconds;
416 423
         };
417 424
     }
Please login to merge, or discard this patch.