Passed
Push — master ( 693dda...155960 )
by Sebastian
02:20
created
src/NumberInfo.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function setValue($value) : NumberInfo
86 86
     {
87
-        if($value instanceof NumberInfo) {
87
+        if ($value instanceof NumberInfo) {
88 88
             $value = $value->getValue();
89 89
         }
90 90
         
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     
118 118
     public function isPositive() : bool
119 119
     {
120
-        if(!$this->isEmpty()) {
120
+        if (!$this->isEmpty()) {
121 121
             $number = $this->getNumber();
122 122
             return $number > 0;
123 123
         }
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function hasValue() : bool
150 150
     {
151
-        if(!$this->isEmpty() && !$this->isZero()) {
151
+        if (!$this->isEmpty() && !$this->isZero()) {
152 152
             return true;
153 153
         }
154 154
         
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      */
222 222
     public function getUnits()
223 223
     {
224
-        if(!$this->hasUnits()) {
224
+        if (!$this->hasUnits()) {
225 225
             return 'px';
226 226
         }
227 227
         
@@ -255,15 +255,15 @@  discard block
 block discarded – undo
255 255
      */
256 256
     public function toAttribute()
257 257
     {
258
-        if($this->isEmpty()) {
258
+        if ($this->isEmpty()) {
259 259
             return null;
260 260
         }
261 261
         
262
-        if($this->isZero()) {
262
+        if ($this->isZero()) {
263 263
             return '0';
264 264
         }
265 265
         
266
-        if($this->isPercent()) {
266
+        if ($this->isPercent()) {
267 267
             return $this->getNumber().$this->getUnits();
268 268
         }
269 269
         
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
      */
277 277
     public function toCSS()
278 278
     {
279
-        if($this->isEmpty()) {
279
+        if ($this->isEmpty()) {
280 280
             return null;
281 281
         }
282 282
         
283
-        if($this->isZero()) {
283
+        if ($this->isZero()) {
284 284
             return '0';
285 285
         }
286 286
         
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
     
290 290
     public function __toString()
291 291
     {
292
-        if($this->isEmpty()) {
292
+        if ($this->isEmpty()) {
293 293
             return '';
294 294
         }
295 295
         
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     public function isBiggerThan($number)
308 308
     {
309 309
         $number = parseNumber($number);
310
-        if($number->getUnits() != $this->getUnits()) {
310
+        if ($number->getUnits() != $this->getUnits()) {
311 311
             return false;
312 312
         }
313 313
         
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
     public function isSmallerThan($number)
326 326
     {
327 327
         $number = parseNumber($number);
328
-        if($number->getUnits() != $this->getUnits()) {
328
+        if ($number->getUnits() != $this->getUnits()) {
329 329
             return false;
330 330
         }
331 331
         
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
     public function isBiggerEqual($number)
336 336
     {
337 337
         $number = parseNumber($number);
338
-        if($number->getUnits() != $this->getUnits()) {
338
+        if ($number->getUnits() != $this->getUnits()) {
339 339
             return false;
340 340
         }
341 341
         
@@ -352,14 +352,14 @@  discard block
 block discarded – undo
352 352
      */
353 353
     public function add($value)
354 354
     {
355
-        if($this->isEmpty()) {
355
+        if ($this->isEmpty()) {
356 356
             $this->setValue($value);
357 357
             return $this;
358 358
         }
359 359
         
360 360
         $number = parseNumber($value);
361 361
         
362
-        if($number->getUnits() == $this->getUnits() || !$number->hasUnits())
362
+        if ($number->getUnits() == $this->getUnits() || !$number->hasUnits())
363 363
         {
364 364
             $new = $this->getNumber() + $number->getNumber();
365 365
             $this->setValue($new.$this->getUnits());
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
      */
379 379
     public function subtract($value)
380 380
     {
381
-        if($this->isEmpty()) {
381
+        if ($this->isEmpty()) {
382 382
             $this->setValue($value);
383 383
             return $this;
384 384
         }
385 385
         
386 386
         $number = parseNumber($value);
387 387
         
388
-        if($number->getUnits() == $this->getUnits() || !$number->hasUnits())
388
+        if ($number->getUnits() == $this->getUnits() || !$number->hasUnits())
389 389
         {
390 390
             $new = $this->getNumber() - $number->getNumber();
391 391
             $this->setValue($new.$this->getUnits());
@@ -412,25 +412,25 @@  discard block
 block discarded – undo
412 412
     
413 413
     protected function percentOperation($operation, $percent)
414 414
     {
415
-        if($this->isZeroOrEmpty()) {
415
+        if ($this->isZeroOrEmpty()) {
416 416
             return $this;
417 417
         }
418 418
         
419 419
         $percent = parseNumber($percent);
420
-        if($percent->hasUnits() && !$percent->isPercent()) {
420
+        if ($percent->hasUnits() && !$percent->isPercent()) {
421 421
             return $this;
422 422
         }
423 423
         
424 424
         $number = $this->getNumber();
425 425
         $value = $number * $percent->getNumber() / 100;
426 426
         
427
-        if($operation == '-') {
427
+        if ($operation == '-') {
428 428
             $number = $number - $value;
429 429
         } else {
430 430
             $number = $number + $value;
431 431
         }
432 432
         
433
-        if($this->isUnitInteger()) {
433
+        if ($this->isUnitInteger()) {
434 434
             $number = intval($number);
435 435
         }
436 436
         
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
         
482 482
         $key = $this->createValueKey($value);
483 483
 
484
-        if(array_key_exists($key, $cache)) {
484
+        if (array_key_exists($key, $cache)) {
485 485
             return $cache[$key];
486 486
         }
487 487
         
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
             'number' => null
492 492
         );
493 493
         
494
-        if($key === '_EMPTY_') 
494
+        if ($key === '_EMPTY_') 
495 495
         {
496 496
             $cache[$key]['empty'] = true;
497 497
             return $cache[$key];
498 498
         }
499 499
         
500
-        if($value === 0 || $value === '0') 
500
+        if ($value === 0 || $value === '0') 
501 501
         {
502 502
             $cache[$key]['number'] = 0;
503 503
             $cache[$key] = $this->filterInfo($cache[$key]);
@@ -506,20 +506,20 @@  discard block
 block discarded – undo
506 506
         
507 507
         $test = trim((string)$value);
508 508
         
509
-        if($test === '') 
509
+        if ($test === '') 
510 510
         {
511 511
             $cache[$key]['empty'] = true;
512 512
             return $cache[$key];
513 513
         }
514 514
         
515 515
         // replace comma notation (which is only possible if it's a string)
516
-        if(is_string($value))
516
+        if (is_string($value))
517 517
         {
518 518
             $test = $this->preProcess($test, $cache, $value);
519 519
         }
520 520
         
521 521
         // convert to a number if it's numeric
522
-        if(is_numeric($test)) 
522
+        if (is_numeric($test)) 
523 523
         {
524 524
             $cache[$key]['number'] = $test * 1;
525 525
             $cache[$key] = $this->filterInfo($cache[$key]);
@@ -545,19 +545,19 @@  discard block
 block discarded – undo
545 545
         $empty = false;
546 546
         
547 547
         $found = $this->findUnits($test);
548
-        if($found !== null) 
548
+        if ($found !== null) 
549 549
         {
550 550
             $number = $found['number'];
551 551
             $units = $found['units'];
552 552
         }
553 553
         
554 554
         // the filters have to restore the value
555
-        if($this->postProcess)
555
+        if ($this->postProcess)
556 556
         {
557 557
             $number = $this->postProcess($number, $test);
558 558
         }
559 559
         // empty number
560
-        else if($number === '' || $number === null || is_bool($number))
560
+        else if ($number === '' || $number === null || is_bool($number))
561 561
         {
562 562
             $number = null;
563 563
             $empty = true;
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
             $number = trim($number);
569 569
             
570 570
             // may be an arbitrary string in some cases
571
-            if(!is_numeric($number))
571
+            if (!is_numeric($number))
572 572
             {
573 573
                 $number = null;
574 574
                 $empty = true;
@@ -600,17 +600,17 @@  discard block
 block discarded – undo
600 600
         $vlength = strlen($value);
601 601
         $names = array_keys($this->knownUnits);
602 602
         
603
-        foreach($names as $unit)
603
+        foreach ($names as $unit)
604 604
         {
605 605
             $ulength = strlen($unit);
606
-            $start = $vlength-$ulength;
607
-            if($start < 0) {
606
+            $start = $vlength - $ulength;
607
+            if ($start < 0) {
608 608
                 continue;
609 609
             }
610 610
             
611 611
             $search = substr($value, $start, $ulength);
612 612
             
613
-            if($search==$unit) 
613
+            if ($search == $unit) 
614 614
             {
615 615
                 return array(
616 616
                     'units' => $unit,
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
     */
631 631
     private function createValueKey($value) : string
632 632
     {
633
-        if(!is_string($value) && !is_numeric($value))
633
+        if (!is_string($value) && !is_numeric($value))
634 634
         {
635 635
             return '_EMPTY_';
636 636
         }
@@ -696,12 +696,12 @@  discard block
 block discarded – undo
696 696
     protected function filterInfo(array $info) : array
697 697
     {
698 698
         $useUnits = 'px';
699
-        if($info['units'] !== null) {
699
+        if ($info['units'] !== null) {
700 700
             $useUnits = $info['units'];
701 701
         }
702 702
         
703 703
         // the units are non-decimal: convert decimal values
704
-        if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number']))
704
+        if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number']))
705 705
         {
706 706
             $info['number'] = intval($info['number']);
707 707
         }
Please login to merge, or discard this patch.