Passed
Pull Request — master (#356)
by Valentin
04:42
created
src/Validation/src/Checker/DatetimeChecker/ThresholdChecker.php 1 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 1 patch
Braces   +26 added lines, -12 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,18 +152,23 @@  discard block
 block discarded – undo
150 152
      */
151 153
     private function now(): ?\DateTimeInterface
152 154
     {
153
-        try {
154
-            if (is_callable($this->now)) {
155
+        try
156
+        {
157
+            if (is_callable($this->now))
158
+            {
155 159
                 $now = $this->now;
156 160
                 return $now();
157 161
             }
158 162
 
159
-            if ($this->now !== null) {
163
+            if ($this->now !== null)
164
+            {
160 165
                 return $this->date($this->now);
161 166
             }
162 167
 
163 168
             return new \DateTimeImmutable('now');
164
-        } catch (\Throwable $e) {
169
+        }
170
+        catch (\Throwable $e)
171
+        {
165 172
             //here's the fail;
166 173
         }
167 174
 
@@ -174,21 +181,27 @@  discard block
 block discarded – undo
174 181
      */
175 182
     private function date($value): ?\DateTimeInterface
176 183
     {
177
-        if ($value instanceof \DateTimeInterface) {
184
+        if ($value instanceof \DateTimeInterface)
185
+        {
178 186
             return $value;
179 187
         }
180 188
 
181
-        if (!$this->isApplicableValue($value)) {
189
+        if (!$this->isApplicableValue($value))
190
+        {
182 191
             return null;
183 192
         }
184 193
 
185
-        try {
186
-            if (!$value) {
194
+        try
195
+        {
196
+            if (!$value)
197
+            {
187 198
                 $value = '0';
188 199
             }
189 200
 
190 201
             return new \DateTimeImmutable(is_numeric($value) ? sprintf('@%d', $value) : trim($value));
191
-        } catch (\Throwable $e) {
202
+        }
203
+        catch (\Throwable $e)
204
+        {
192 205
             //here's the fail;
193 206
         }
194 207
 
@@ -211,7 +224,8 @@  discard block
 block discarded – undo
211 224
     private function fromField(string $field): ?\DateTimeInterface
212 225
     {
213 226
         $before = $this->getValidator()->getValue($field);
214
-        if ($before !== null) {
227
+        if ($before !== null)
228
+        {
215 229
             return $this->date($before);
216 230
         }
217 231
 
Please login to merge, or discard this patch.