Completed
Push — master ( 57c37c...bb12e7 )
by Terry
01:43
created
src/Tester.php 1 patch
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types=1);
1
+<?php declare(strict_types = 1);
2 2
 
3 3
 namespace Terah\Assert;
4 4
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     protected static $currentSuite  = self::DEFAULT_SUITE;
13 13
 
14 14
     /** @var Suite[]  */
15
-    protected static $suites        = [];
15
+    protected static $suites        = [ ];
16 16
 
17 17
     /** @var Logger $logger */
18 18
     public static $logger           = null;
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
      * @param string $suiteName
30 30
      * @return Suite
31 31
      */
32
-    public static function suite(string $suiteName='') : Suite
32
+    public static function suite(string $suiteName = '') : Suite
33 33
     {
34 34
         $suiteName                  = $suiteName ?: static::$currentSuite;
35
-        static::$suites[$suiteName] = new Suite();
35
+        static::$suites[ $suiteName ] = new Suite();
36 36
 
37
-        return static::$suites[$suiteName];
37
+        return static::$suites[ $suiteName ];
38 38
     }
39 39
 
40 40
     /**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @return Suite
48 48
      * @throws AssertionFailedException
49 49
      */
50
-    public static function test(string $testName, Closure $test, string $suiteName='', string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite
50
+    public static function test(string $testName, Closure $test, string $suiteName = '', string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite
51 51
     {
52 52
         Assert::that($successMessage)->notEmpty();
53 53
         Assert::that($test)->isCallable();
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
      * @param string $suiteName
61 61
      * @param string $testName
62 62
      */
63
-    public static function run(string $suiteName='', string $testName='')
63
+    public static function run(string $suiteName = '', string $testName = '')
64 64
     {
65
-        $suites         = static::$suites;
66
-        if ( ! empty($suiteName) )
65
+        $suites = static::$suites;
66
+        if ( ! empty($suiteName))
67 67
         {
68 68
             Assert::that($suites)->keyExists($suiteName, "The test suite ({$suiteName}) has not been loaded");
69
-            $suites         = [$suites[$suiteName]];
69
+            $suites = [ $suites[ $suiteName ] ];
70 70
         }
71
-        foreach ( $suites as $suite )
71
+        foreach ($suites as $suite)
72 72
         {
73 73
             $suite->run($testName);
74 74
         }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public static function getLogger() : Logger
81 81
     {
82
-        if ( ! static::$logger )
82
+        if ( ! static::$logger)
83 83
         {
84 84
             static::$logger = new Logger();
85 85
         }
@@ -91,15 +91,15 @@  discard block
 block discarded – undo
91 91
      * @param string $suiteName
92 92
      * @return Suite
93 93
      */
94
-    protected static function getSuite(string $suiteName='') : Suite
94
+    protected static function getSuite(string $suiteName = '') : Suite
95 95
     {
96
-        $suiteName                  = $suiteName ?: static::$currentSuite;
97
-        if ( ! array_key_exists($suiteName, static::$suites) )
96
+        $suiteName = $suiteName ?: static::$currentSuite;
97
+        if ( ! array_key_exists($suiteName, static::$suites))
98 98
         {
99 99
             return static::suite($suiteName);
100 100
         }
101 101
 
102
-        return static::$suites[$suiteName];
102
+        return static::$suites[ $suiteName ];
103 103
     }
104 104
 
105 105
 
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
 
117 117
         $className          = array_values(array_diff_key(get_declared_classes(), $declaredClasses));
118 118
 
119
-        $reflectionClass    = new \ReflectionClass($className[0]);
119
+        $reflectionClass    = new \ReflectionClass($className[ 0 ]);
120 120
         $publicMethods      = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
121 121
         $fullClassName      = $reflectionClass->getName();
122 122
         $className          = $reflectionClass->getShortName();
123 123
         $namespace          = $reflectionClass->getNamespaceName();
124 124
         $constructorParams  = '';
125
-        foreach ( $publicMethods as $method )
125
+        foreach ($publicMethods as $method)
126 126
         {
127
-            if ( $method->isConstructor() )
127
+            if ($method->isConstructor())
128 128
             {
129
-                $constructorParams  = static::getMethodParams($method);
129
+                $constructorParams = static::getMethodParams($method);
130 130
             }
131 131
         }
132 132
         $objectInit         = "new {$fullClassName}({$constructorParams})";
133
-        $output             = [];
134
-        $output[]           = <<<PHP
133
+        $output             = [ ];
134
+        $output[ ]           = <<<PHP
135 135
 <?php declare(strict_types=1);
136 136
 
137 137
 namespace {$namespace}\Test;
@@ -145,22 +145,22 @@  discard block
 block discarded – undo
145 145
     ->fixture('testSubject', {$objectInit})
146 146
 PHP;
147 147
 
148
-        foreach ( $publicMethods as $method )
148
+        foreach ($publicMethods as $method)
149 149
         {
150 150
             $methodName         = $method->getName();
151 151
             $methodParams       = static::getMethodParams($method);
152
-            $testName           = 'test' . ucfirst($methodName);
152
+            $testName           = 'test'.ucfirst($methodName);
153 153
             $successArgs        = static::getMethodArgs($method);
154 154
             $failArgs           = static::getMethodArgs($method, '    ');
155 155
             $returnVal          = static::getReturnVal($method);
156 156
             $methodSignature    = "\$suite->getFixture('testSubject')->{$methodName}({$methodParams})";
157 157
 
158
-            if ( $method->isStatic() )
158
+            if ($method->isStatic())
159 159
             {
160 160
                 $methodSignature = "{$className}::{$methodName}({$methodParams})";
161 161
             }
162 162
 
163
-            $output[] = <<<PHP
163
+            $output[ ] = <<<PHP
164 164
             
165 165
     ->test('{$testName}Success', function(Suite \$suite) {
166 166
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
         }
186 186
 
187
-        $output[] = "    ;";
187
+        $output[ ] = "    ;";
188 188
 
189 189
         return static::createDirectoriesAndSaveFile($outputPath, implode("\n", $output));
190 190
     }
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      * @param int $dirMode
198 198
      * @return bool
199 199
      */
200
-    protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags=0, $dirMode=0755) : bool
200
+    protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags = 0, $dirMode = 0755) : bool
201 201
     {
202 202
         static::createParentDirectories($filePath, $dirMode);
203 203
         Assert::that(file_put_contents($filePath, $data, $flags))->notFalse("Failed to put contents in file ({$filePath})");
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
      * @param int $mode
211 211
      * @return bool
212 212
      */
213
-    protected static function createParentDirectories(string $filePath, $mode=0755) : bool
213
+    protected static function createParentDirectories(string $filePath, $mode = 0755) : bool
214 214
     {
215
-        $directoryPath  = preg_match('/.*\//', $filePath);
215
+        $directoryPath = preg_match('/.*\//', $filePath);
216 216
         Assert::that($filePath)
217 217
             ->notEmpty("Failed to identify path ({$directoryPath}) to create")
218 218
             ->notEq(DIRECTORY_SEPARATOR, "Failed to identify path ({$directoryPath}) to create");
219
-        if ( file_exists($directoryPath) )
219
+        if (file_exists($directoryPath))
220 220
         {
221 221
             Assert::that(is_dir($directoryPath))->notFalse("Failed to create parent directories.. files exists and is not a directory({$directoryPath})");
222 222
 
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
      */
235 235
     protected static function getMethodParams(\ReflectionMethod $method) : string
236 236
     {
237
-        $output = [];
238
-        foreach ( $method->getParameters() as $param )
237
+        $output = [ ];
238
+        foreach ($method->getParameters() as $param)
239 239
         {
240
-            $output[] = '$' . $param->getName();
240
+            $output[ ] = '$'.$param->getName();
241 241
         }
242 242
 
243 243
         return implode(', ', $output);
@@ -248,16 +248,16 @@  discard block
 block discarded – undo
248 248
      * @param string $extraPadding
249 249
      * @return string
250 250
      */
251
-    protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding='') : string
251
+    protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding = '') : string
252 252
     {
253
-        $output     = [];
253
+        $output     = [ ];
254 254
         $params     = $method->getParameters();
255
-        foreach ( $params as $param )
255
+        foreach ($params as $param)
256 256
         {
257 257
             $type       = $param->hasType() ? $param->getType()->_toString() : '';
258
-            $paramDef   = str_pad('$' . $param->getName(), 32, ' ') . '= ';
259
-            $paramDef   .= static::getDefaultValue($type);
260
-            $output[]   = $paramDef . ';';
258
+            $paramDef   = str_pad('$'.$param->getName(), 32, ' ').'= ';
259
+            $paramDef .= static::getDefaultValue($type);
260
+            $output[ ]   = $paramDef.';';
261 261
         }
262 262
 
263 263
         return implode("\n        {$extraPadding}", $output);
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
      * @param string $default
281 281
      * @return string
282 282
      */
283
-    protected static function getDefaultValue(string $type='', string $default='null') : string
283
+    protected static function getDefaultValue(string $type = '', string $default = 'null') : string
284 284
     {
285
-        $typeMap    = [
285
+        $typeMap = [
286 286
             'int'           => "0",
287 287
             'float'         => "0.0",
288 288
             'string'        => "''",
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
             'array'         => "[]",
292 292
         ];
293 293
 
294
-        return $typeMap[$type] ?? $default;
294
+        return $typeMap[ $type ] ?? $default;
295 295
     }
296 296
 }
297 297
 
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
 class Suite
300 300
 {
301 301
     /** @var Test[] */
302
-    protected $tests        = [];
302
+    protected $tests        = [ ];
303 303
 
304 304
     /** @var mixed[] */
305
-    protected $fixtures     = [];
305
+    protected $fixtures     = [ ];
306 306
 
307 307
     /** @var Logger */
308 308
     protected $logger       = null;
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
     /**
314 314
      * @param string $filter
315 315
      */
316
-    public function run(string $filter='')
316
+    public function run(string $filter = '')
317 317
     {
318
-        foreach ( $this->tests as $test => $testCase )
318
+        foreach ($this->tests as $test => $testCase)
319 319
         {
320
-            $testName   = $testCase->getTestName();
321
-            if ( $filter && $test !== $filter )
320
+            $testName = $testCase->getTestName();
321
+            if ($filter && $test !== $filter)
322 322
             {
323 323
                 continue;
324 324
             }
@@ -326,36 +326,36 @@  discard block
 block discarded – undo
326 326
             {
327 327
                 $this->getLogger()->info("[{$testName}] - Starting...");
328 328
                 $testCase->runTest($this);
329
-                $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage());
329
+                $this->getLogger()->info("[{$testName}] - ".$testCase->getSuccessMessage());
330 330
             }
331
-            catch ( \Exception $e )
331
+            catch (\Exception $e)
332 332
             {
333 333
                 $expectedCode       = $testCase->getExceptionCode();
334 334
                 $expectedClass      = $testCase->getExceptionType();
335 335
                 $code               = $e->getCode();
336 336
                 $exception          = get_class($e);
337
-                if ( ! $expectedClass &&  ! $expectedCode )
337
+                if ( ! $expectedClass && ! $expectedCode)
338 338
                 {
339
-                    $this->getLogger()->error($e->getMessage(), [compact('testName'), $e]);
339
+                    $this->getLogger()->error($e->getMessage(), [ compact('testName'), $e ]);
340 340
                     $this->failedCount++;
341 341
 
342 342
                     continue;
343 343
                 }
344
-                if ( $expectedCode && $expectedCode !== $code )
344
+                if ($expectedCode && $expectedCode !== $code)
345 345
                 {
346
-                    $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [compact('testName'), $e]);
346
+                    $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [ compact('testName'), $e ]);
347 347
                     $this->failedCount++;
348 348
                     
349 349
                     continue;
350 350
                 }
351
-                if ( $expectedClass && $expectedClass !== $exception )
351
+                if ($expectedClass && $expectedClass !== $exception)
352 352
                 {
353
-                    $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [compact('testName'), $e]);
353
+                    $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [ compact('testName'), $e ]);
354 354
                     $this->failedCount++;
355 355
                     
356 356
                     continue;
357 357
                 }
358
-                $this->getLogger()->info("[{$test}] - " . $testCase->getSuccessMessage());
358
+                $this->getLogger()->info("[{$test}] - ".$testCase->getSuccessMessage());
359 359
             }
360 360
         }
361 361
     }
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
      * @return Suite
375 375
      * @throws AssertionFailedException
376 376
      */
377
-    public function test(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite
377
+    public function test(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite
378 378
     {
379
-        $this->tests[]  = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass);
379
+        $this->tests[ ] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass);
380 380
 
381 381
         return $this;
382 382
     }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
      */
389 389
     public function fixture(string $fixtureName, $value) : Suite
390 390
     {
391
-        $this->fixtures[$fixtureName]  = $value;
391
+        $this->fixtures[ $fixtureName ] = $value;
392 392
 
393 393
         return $this;
394 394
     }
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
     {
403 403
         Assert::that($this->fixtures)->keyExists($fixtureName, "The fixture ({$fixtureName}) does not exist.");
404 404
 
405
-        return $this->fixtures[$fixtureName];
405
+        return $this->fixtures[ $fixtureName ];
406 406
     }
407 407
 
408 408
 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
      */
423 423
     public function getLogger() : Logger
424 424
     {
425
-        if ( ! $this->logger )
425
+        if ( ! $this->logger)
426 426
         {
427 427
             $this->logger = new Logger();
428 428
         }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      * @param string   $exceptionClass
460 460
      * @throws AssertionFailedException
461 461
      */
462
-    public function __construct(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='')
462
+    public function __construct(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '')
463 463
     {
464 464
         $this->setTestName($testName);
465 465
         $this->setTest($test);
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
      */
495 495
     public function getSuccessMessage() : string
496 496
     {
497
-        if ( ! $this->successMessage )
497
+        if ( ! $this->successMessage)
498 498
         {
499 499
             return "Successfully run {$this->testName}";
500 500
         }
@@ -647,21 +647,21 @@  discard block
 block discarded – undo
647 647
     /**
648 648
      * @var array $logLevels List of supported levels
649 649
      */
650
-    static protected $logLevels       = [
651
-        self::EMERGENCY => [1, self::WHITE,       self::RED,      self::DEFAULT,  'EMERG'],
652
-        self::ALERT     => [2, self::WHITE,       self::YELLOW,   self::DEFAULT,  'ALERT'],
653
-        self::CRITICAL  => [3, self::RED,         self::DEFAULT,  self::BOLD ,    'CRIT'],
654
-        self::ERROR     => [4, self::RED,         self::DEFAULT,  self::DEFAULT,  'ERROR'],
655
-        self::WARNING   => [5, self::YELLOW,      self::DEFAULT,  self::DEFAULT,  'WARN'],
656
-        self::NOTICE    => [6, self::CYAN,        self::DEFAULT,  self::DEFAULT,  'NOTE'],
657
-        self::INFO      => [7, self::GREEN,       self::DEFAULT,  self::DEFAULT,  'INFO'],
658
-        self::DEBUG     => [8, self::LIGHT_GRAY,  self::DEFAULT,  self::DEFAULT,  'DEBUG'],
650
+    static protected $logLevels = [
651
+        self::EMERGENCY => [ 1, self::WHITE, self::RED, self::DEFAULT, 'EMERG' ],
652
+        self::ALERT     => [ 2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT' ],
653
+        self::CRITICAL  => [ 3, self::RED, self::DEFAULT, self::BOLD, 'CRIT' ],
654
+        self::ERROR     => [ 4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR' ],
655
+        self::WARNING   => [ 5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN' ],
656
+        self::NOTICE    => [ 6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE' ],
657
+        self::INFO      => [ 7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO' ],
658
+        self::DEBUG     => [ 8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG' ],
659 659
     ];
660 660
 
661 661
     /**
662 662
      * @var array
663 663
      */
664
-    static protected $colours   = [
664
+    static protected $colours = [
665 665
         'fore' => [
666 666
             self::BLACK         => '0;30',
667 667
             self::DARK_GRAY     => '1;30',
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
             self::CYAN          => '46',
693 693
             self::LIGHT_GRAY    => '47',
694 694
         ],
695
-        self::BOLD => [],
695
+        self::BOLD => [ ],
696 696
     ];
697 697
 
698 698
     /**
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
      * @param bool   $gzipFile
703 703
      * @param bool   $addDate
704 704
      */
705
-    public function __construct($resource=STDOUT, string $level=self::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true)
705
+    public function __construct($resource = STDOUT, string $level = self::INFO, bool $useLocking = false, bool $gzipFile = false, bool $addDate = true)
706 706
     {
707 707
         $this->resource     = $resource;
708 708
         $this->setLogLevel($level);
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
      * @param string $message
718 718
      * @param array $context
719 719
      */
720
-    public function emergency(string $message, array $context=[])
720
+    public function emergency(string $message, array $context = [ ])
721 721
     {
722 722
         $this->log(self::EMERGENCY, $message, $context);
723 723
     }
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
      * @param string $message
732 732
      * @param array $context
733 733
      */
734
-    public function alert(string $message, array $context=[])
734
+    public function alert(string $message, array $context = [ ])
735 735
     {
736 736
         $this->log(self::ALERT, $message, $context);
737 737
     }
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
      * @param string $message
745 745
      * @param array $context
746 746
      */
747
-    public function critical(string $message, array $context=[])
747
+    public function critical(string $message, array $context = [ ])
748 748
     {
749 749
         $this->log(self::CRITICAL, $message, $context);
750 750
     }
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
      * @param string $message
757 757
      * @param array $context
758 758
      */
759
-    public function error(string $message, array $context=[])
759
+    public function error(string $message, array $context = [ ])
760 760
     {
761 761
         $this->log(self::ERROR, $message, $context);
762 762
     }
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
      * @param string $message
771 771
      * @param array $context
772 772
      */
773
-    public function warning(string $message, array $context=[])
773
+    public function warning(string $message, array $context = [ ])
774 774
     {
775 775
         $this->log(self::WARNING, $message, $context);
776 776
     }
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
      * @param string $message
782 782
      * @param array $context
783 783
      */
784
-    public function notice(string $message, array $context=[])
784
+    public function notice(string $message, array $context = [ ])
785 785
     {
786 786
         $this->log(self::NOTICE, $message, $context);
787 787
     }
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
      * @param string $message
795 795
      * @param array $context
796 796
      */
797
-    public function info(string $message, array $context=[])
797
+    public function info(string $message, array $context = [ ])
798 798
     {
799 799
         $this->log(self::INFO, $message, $context);
800 800
     }
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      * @param string $message
806 806
      * @param array $context
807 807
      */
808
-    public function debug(string $message, array $context=[])
808
+    public function debug(string $message, array $context = [ ])
809 809
     {
810 810
         $this->log(self::DEBUG, $message, $context);
811 811
     }
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
      */
817 817
     public function setLogFile($resource) : Logger
818 818
     {
819
-        $this->resource     = $resource;
819
+        $this->resource = $resource;
820 820
 
821 821
         return $this;
822 822
     }
@@ -828,23 +828,23 @@  discard block
 block discarded – undo
828 828
      * @param bool $bold
829 829
      * @return string
830 830
      */
831
-    public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string
831
+    public static function addColour(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string
832 832
     {
833 833
         // todo: support bold
834 834
         unset($bold);
835 835
         $coloredString = '';
836 836
         // Check if given foreground color found
837
-        if ( isset(static::$colours['fore'][$foregroundColor]) )
837
+        if (isset(static::$colours[ 'fore' ][ $foregroundColor ]))
838 838
         {
839
-            $coloredString .= "\033[" . static::$colours['fore'][$foregroundColor] . "m";
839
+            $coloredString .= "\033[".static::$colours[ 'fore' ][ $foregroundColor ]."m";
840 840
         }
841 841
         // Check if given background color found
842
-        if ( isset(static::$colours['back'][$backgroundColor]) )
842
+        if (isset(static::$colours[ 'back' ][ $backgroundColor ]))
843 843
         {
844
-            $coloredString .= "\033[" . static::$colours['back'][$backgroundColor] . "m";
844
+            $coloredString .= "\033[".static::$colours[ 'back' ][ $backgroundColor ]."m";
845 845
         }
846 846
         // Add string and end coloring
847
-        $coloredString .=  $string . "\033[0m";
847
+        $coloredString .= $string."\033[0m";
848 848
 
849 849
         return $coloredString;
850 850
     }
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
      * @param bool      $bold
857 857
      * @return string
858 858
      */
859
-    public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string
859
+    public function colourize(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string
860 860
     {
861 861
         return static::addColour($string, $foregroundColor, $backgroundColor, $bold);
862 862
     }
@@ -867,11 +867,11 @@  discard block
 block discarded – undo
867 867
      */
868 868
     public function setLogLevel(string $level) : Logger
869 869
     {
870
-        if ( ! isset(static::$logLevels[$level]) )
870
+        if ( ! isset(static::$logLevels[ $level ]))
871 871
         {
872 872
             throw new \InvalidArgumentException("Log level is invalid");
873 873
         }
874
-        $this->level = static::$logLevels[$level][0];
874
+        $this->level = static::$logLevels[ $level ][ 0 ];
875 875
 
876 876
         return $this;
877 877
     }
@@ -915,25 +915,25 @@  discard block
 block discarded – undo
915 915
      * @param string|object  $message  If an object is passed it must implement __toString()
916 916
      * @param array          $context  Placeholders to be substituted in the message
917 917
      */
918
-    public function log($level, $message, array $context=[])
918
+    public function log($level, $message, array $context = [ ])
919 919
     {
920
-        $level = isset(static::$logLevels[$level]) ? $level : self::INFO;
921
-        list($logLevel, $fore, $back, $style) = static::$logLevels[$level];
920
+        $level = isset(static::$logLevels[ $level ]) ? $level : self::INFO;
921
+        list($logLevel, $fore, $back, $style) = static::$logLevels[ $level ];
922 922
         unset($style);
923
-        if ( $logLevel > $this->level )
923
+        if ($logLevel > $this->level)
924 924
         {
925
-            return ;
925
+            return;
926 926
         }
927
-        if ( is_callable($this->formatter) )
927
+        if (is_callable($this->formatter))
928 928
         {
929
-            $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context);
929
+            $message = $this->formatter->__invoke(static::$logLevels[ $level ][ 4 ], $message, $context);
930 930
         }
931 931
         else
932 932
         {
933 933
             $message = $this->formatMessage($level, $message, $context);
934 934
         }
935 935
         $this->lastLogEntry = $message;
936
-        $this->write($this->colourize($message, $fore, $back) . PHP_EOL);
936
+        $this->write($this->colourize($message, $fore, $back).PHP_EOL);
937 937
     }
938 938
 
939 939
     /**
@@ -943,8 +943,8 @@  discard block
 block discarded – undo
943 943
      */
944 944
     public static function style(string $style, string $message) : string
945 945
     {
946
-        $style = isset(static::$logLevels[$style]) ? $style : self::INFO;
947
-        list($logLevel, $fore, $back, $style) = static::$logLevels[$style];
946
+        $style = isset(static::$logLevels[ $style ]) ? $style : self::INFO;
947
+        list($logLevel, $fore, $back, $style) = static::$logLevels[ $style ];
948 948
         unset($logLevel, $style);
949 949
 
950 950
         return static::addColour($message, $fore, $back);
@@ -956,14 +956,14 @@  discard block
 block discarded – undo
956 956
      * @param array  $context
957 957
      * @return string
958 958
      */
959
-    protected function formatMessage(string $level, string $message, array $context=[]) : string
959
+    protected function formatMessage(string $level, string $message, array $context = [ ]) : string
960 960
     {
961 961
         # Handle objects implementing __toString
962
-        $message            = (string) $message;
963
-        $message            .= empty($context) ? '' : PHP_EOL . json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
964
-        $data               = $this->addDate ? ['date' => date('Y-m-d H:i:s')] : [];
965
-        $data['level']      = strtoupper(str_pad(static::$logLevels[$level][4], 5, ' ', STR_PAD_RIGHT));
966
-        $data['message']    = $message;
962
+        $message            = (string)$message;
963
+        $message .= empty($context) ? '' : PHP_EOL.json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
964
+        $data               = $this->addDate ? [ 'date' => date('Y-m-d H:i:s') ] : [ ];
965
+        $data[ 'level' ]      = strtoupper(str_pad(static::$logLevels[ $level ][ 4 ], 5, ' ', STR_PAD_RIGHT));
966
+        $data[ 'message' ]    = $message;
967 967
 
968 968
         return implode($this->separator, $data);
969 969
     }
@@ -976,12 +976,12 @@  discard block
 block discarded – undo
976 976
     public function write(string $content)
977 977
     {
978 978
         $resource = $this->getResource();
979
-        if ( $this->useLocking )
979
+        if ($this->useLocking)
980 980
         {
981 981
             flock($resource, LOCK_EX);
982 982
         }
983 983
         gzwrite($resource, $content);
984
-        if ( $this->useLocking )
984
+        if ($this->useLocking)
985 985
         {
986 986
             flock($resource, LOCK_UN);
987 987
         }
@@ -993,14 +993,14 @@  discard block
 block discarded – undo
993 993
      */
994 994
     protected function getResource()
995 995
     {
996
-        if ( is_resource($this->resource) )
996
+        if (is_resource($this->resource))
997 997
         {
998 998
             return $this->resource;
999 999
         }
1000 1000
         $fileName               = $this->resource;
1001 1001
         $this->closeLocally     = true;
1002 1002
         $this->resource         = $this->openResource();
1003
-        if ( ! is_resource($this->resource) )
1003
+        if ( ! is_resource($this->resource))
1004 1004
         {
1005 1005
             throw new \Exception("The resource ({$fileName}) could not be opened");
1006 1006
         }
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
      */
1022 1022
     protected function openResource()
1023 1023
     {
1024
-        if ( $this->gzipFile )
1024
+        if ($this->gzipFile)
1025 1025
         {
1026 1026
             return gzopen($this->resource, 'a');
1027 1027
         }
Please login to merge, or discard this patch.