| @@ -1,4 +1,4 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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(); | 
| @@ -61,17 +61,17 @@ discard block | ||
| 61 | 61 | * @param string $testName | 
| 62 | 62 | * @return array | 
| 63 | 63 | */ | 
| 64 | - public static function run(string $suiteName='', string $testName='') : array | |
| 64 | + public static function run(string $suiteName = '', string $testName = '') : array | |
| 65 | 65 |      { | 
| 66 | 66 | $totalFailed = 0; | 
| 67 | 67 | $totalTests = 0; | 
| 68 | 68 | $suites = static::$suites; | 
| 69 | - if ( ! empty($suiteName) ) | |
| 69 | + if ( ! empty($suiteName)) | |
| 70 | 70 |          { | 
| 71 | 71 |              Assert::that($suites)->keyExists($suiteName, "The test suite ({$suiteName}) has not been loaded"); | 
| 72 | - $suites = [$suites[$suiteName]]; | |
| 72 | + $suites = [ $suites[ $suiteName ] ]; | |
| 73 | 73 | } | 
| 74 | - foreach ( $suites as $suite ) | |
| 74 | + foreach ($suites as $suite) | |
| 75 | 75 |          { | 
| 76 | 76 | $totalFailed += $suite->run($testName); | 
| 77 | 77 | $totalTests += $suite->totalTestsCount(); | 
| @@ -85,7 +85,7 @@ discard block | ||
| 85 | 85 | */ | 
| 86 | 86 | public static function getLogger() : Logger | 
| 87 | 87 |      { | 
| 88 | - if ( ! static::$logger ) | |
| 88 | + if ( ! static::$logger) | |
| 89 | 89 |          { | 
| 90 | 90 | static::$logger = new Logger(); | 
| 91 | 91 | } | 
| @@ -97,15 +97,15 @@ discard block | ||
| 97 | 97 | * @param string $suiteName | 
| 98 | 98 | * @return Suite | 
| 99 | 99 | */ | 
| 100 | - protected static function getSuite(string $suiteName='') : Suite | |
| 100 | + protected static function getSuite(string $suiteName = '') : Suite | |
| 101 | 101 |      { | 
| 102 | - $suiteName = $suiteName ?: static::$currentSuite; | |
| 103 | - if ( ! array_key_exists($suiteName, static::$suites) ) | |
| 102 | + $suiteName = $suiteName ?: static::$currentSuite; | |
| 103 | + if ( ! array_key_exists($suiteName, static::$suites)) | |
| 104 | 104 |          { | 
| 105 | 105 | return static::suite($suiteName); | 
| 106 | 106 | } | 
| 107 | 107 | |
| 108 | - return static::$suites[$suiteName]; | |
| 108 | + return static::$suites[ $suiteName ]; | |
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | |
| @@ -122,22 +122,22 @@ discard block | ||
| 122 | 122 | |
| 123 | 123 | $className = array_values(array_diff_key(get_declared_classes(), $declaredClasses)); | 
| 124 | 124 | |
| 125 | - $reflectionClass = new \ReflectionClass($className[0]); | |
| 125 | + $reflectionClass = new \ReflectionClass($className[ 0 ]); | |
| 126 | 126 | $publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC); | 
| 127 | 127 | $fullClassName = $reflectionClass->getName(); | 
| 128 | 128 | $className = $reflectionClass->getShortName(); | 
| 129 | 129 | $namespace = $reflectionClass->getNamespaceName(); | 
| 130 | 130 | $constructorParams = ''; | 
| 131 | - foreach ( $publicMethods as $method ) | |
| 131 | + foreach ($publicMethods as $method) | |
| 132 | 132 |          { | 
| 133 | - if ( $method->isConstructor() ) | |
| 133 | + if ($method->isConstructor()) | |
| 134 | 134 |              { | 
| 135 | - $constructorParams = static::getMethodParams($method); | |
| 135 | + $constructorParams = static::getMethodParams($method); | |
| 136 | 136 | } | 
| 137 | 137 | } | 
| 138 | 138 |          $objectInit         = "new {$fullClassName}({$constructorParams})"; | 
| 139 | - $output = []; | |
| 140 | - $output[] = <<<PHP | |
| 139 | + $output = [ ]; | |
| 140 | + $output[ ] = <<<PHP | |
| 141 | 141 | <?php declare(strict_types=1); | 
| 142 | 142 | |
| 143 | 143 |  namespace {$namespace}\Test; | 
| @@ -151,22 +151,22 @@ discard block | ||
| 151 | 151 |      ->fixture('testSubject', {$objectInit}) | 
| 152 | 152 | PHP; | 
| 153 | 153 | |
| 154 | - foreach ( $publicMethods as $method ) | |
| 154 | + foreach ($publicMethods as $method) | |
| 155 | 155 |          { | 
| 156 | 156 | $methodName = $method->getName(); | 
| 157 | 157 | $methodParams = static::getMethodParams($method); | 
| 158 | - $testName = 'test' . ucfirst($methodName); | |
| 158 | + $testName = 'test'.ucfirst($methodName); | |
| 159 | 159 | $successArgs = static::getMethodArgs($method); | 
| 160 | 160 | $failArgs = static::getMethodArgs($method, ' '); | 
| 161 | 161 | $returnVal = static::getReturnVal($method); | 
| 162 | 162 |              $methodSignature    = "\$suite->getFixture('testSubject')->{$methodName}({$methodParams})"; | 
| 163 | 163 | |
| 164 | - if ( $method->isStatic() ) | |
| 164 | + if ($method->isStatic()) | |
| 165 | 165 |              { | 
| 166 | 166 |                  $methodSignature = "{$className}::{$methodName}({$methodParams})"; | 
| 167 | 167 | } | 
| 168 | 168 | |
| 169 | - $output[] = <<<PHP | |
| 169 | + $output[ ] = <<<PHP | |
| 170 | 170 | |
| 171 | 171 |      ->test('{$testName}Success', function(Suite \$suite) { | 
| 172 | 172 | |
| @@ -190,7 +190,7 @@ discard block | ||
| 190 | 190 | |
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | - $output[] = " ;"; | |
| 193 | + $output[ ] = " ;"; | |
| 194 | 194 | |
| 195 | 195 |          return static::createDirectoriesAndSaveFile($outputPath, implode("\n", $output)); | 
| 196 | 196 | } | 
| @@ -203,7 +203,7 @@ discard block | ||
| 203 | 203 | * @param int $dirMode | 
| 204 | 204 | * @return bool | 
| 205 | 205 | */ | 
| 206 | - protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags=0, $dirMode=0755) : bool | |
| 206 | + protected static function createDirectoriesAndSaveFile(string $filePath, $data, $flags = 0, $dirMode = 0755) : bool | |
| 207 | 207 |      { | 
| 208 | 208 | static::createParentDirectories($filePath, $dirMode); | 
| 209 | 209 |          Assert::that(file_put_contents($filePath, $data, $flags))->notFalse("Failed to put contents in file ({$filePath})"); | 
| @@ -216,13 +216,13 @@ discard block | ||
| 216 | 216 | * @param int $mode | 
| 217 | 217 | * @return bool | 
| 218 | 218 | */ | 
| 219 | - protected static function createParentDirectories(string $filePath, $mode=0755) : bool | |
| 219 | + protected static function createParentDirectories(string $filePath, $mode = 0755) : bool | |
| 220 | 220 |      { | 
| 221 | -        $directoryPath  = preg_match('/.*\//', $filePath); | |
| 221 | +        $directoryPath = preg_match('/.*\//', $filePath); | |
| 222 | 222 | Assert::that($filePath) | 
| 223 | 223 |              ->notEmpty("Failed to identify path ({$directoryPath}) to create") | 
| 224 | 224 |              ->notEq(DIRECTORY_SEPARATOR, "Failed to identify path ({$directoryPath}) to create"); | 
| 225 | - if ( file_exists($directoryPath) ) | |
| 225 | + if (file_exists($directoryPath)) | |
| 226 | 226 |          { | 
| 227 | 227 |              Assert::that(is_dir($directoryPath))->notFalse("Failed to create parent directories.. files exists and is not a directory({$directoryPath})"); | 
| 228 | 228 | |
| @@ -240,10 +240,10 @@ discard block | ||
| 240 | 240 | */ | 
| 241 | 241 | protected static function getMethodParams(\ReflectionMethod $method) : string | 
| 242 | 242 |      { | 
| 243 | - $output = []; | |
| 244 | - foreach ( $method->getParameters() as $param ) | |
| 243 | + $output = [ ]; | |
| 244 | + foreach ($method->getParameters() as $param) | |
| 245 | 245 |          { | 
| 246 | - $output[] = '$' . $param->getName(); | |
| 246 | + $output[ ] = '$'.$param->getName(); | |
| 247 | 247 | } | 
| 248 | 248 | |
| 249 | 249 |          return implode(', ', $output); | 
| @@ -254,16 +254,16 @@ discard block | ||
| 254 | 254 | * @param string $extraPadding | 
| 255 | 255 | * @return string | 
| 256 | 256 | */ | 
| 257 | - protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding='') : string | |
| 257 | + protected static function getMethodArgs(\ReflectionMethod $method, string $extraPadding = '') : string | |
| 258 | 258 |      { | 
| 259 | - $output = []; | |
| 259 | + $output = [ ]; | |
| 260 | 260 | $params = $method->getParameters(); | 
| 261 | - foreach ( $params as $param ) | |
| 261 | + foreach ($params as $param) | |
| 262 | 262 |          { | 
| 263 | 263 | $type = $param->hasType() ? $param->getType()->_toString() : ''; | 
| 264 | -            $paramDef   = str_pad('$' . $param->getName(), 32, ' ') . '= '; | |
| 265 | - $paramDef .= static::getDefaultValue($type); | |
| 266 | - $output[] = $paramDef . ';'; | |
| 264 | +            $paramDef   = str_pad('$'.$param->getName(), 32, ' ').'= '; | |
| 265 | + $paramDef .= static::getDefaultValue($type); | |
| 266 | + $output[ ] = $paramDef.';'; | |
| 267 | 267 | } | 
| 268 | 268 | |
| 269 | 269 |          return implode("\n        {$extraPadding}", $output); | 
| @@ -286,9 +286,9 @@ discard block | ||
| 286 | 286 | * @param string $default | 
| 287 | 287 | * @return string | 
| 288 | 288 | */ | 
| 289 | - protected static function getDefaultValue(string $type='', string $default='null') : string | |
| 289 | + protected static function getDefaultValue(string $type = '', string $default = 'null') : string | |
| 290 | 290 |      { | 
| 291 | - $typeMap = [ | |
| 291 | + $typeMap = [ | |
| 292 | 292 | 'int' => "0", | 
| 293 | 293 | 'float' => "0.0", | 
| 294 | 294 | 'string' => "''", | 
| @@ -297,7 +297,7 @@ discard block | ||
| 297 | 297 | 'array' => "[]", | 
| 298 | 298 | ]; | 
| 299 | 299 | |
| 300 | - return $typeMap[$type] ?? $default; | |
| 300 | + return $typeMap[ $type ] ?? $default; | |
| 301 | 301 | } | 
| 302 | 302 | } | 
| 303 | 303 | |
| @@ -305,10 +305,10 @@ discard block | ||
| 305 | 305 | class Suite | 
| 306 | 306 |  { | 
| 307 | 307 | /** @var Test[] */ | 
| 308 | - protected $tests = []; | |
| 308 | + protected $tests = [ ]; | |
| 309 | 309 | |
| 310 | 310 | /** @var mixed[] */ | 
| 311 | - protected $fixtures = []; | |
| 311 | + protected $fixtures = [ ]; | |
| 312 | 312 | |
| 313 | 313 | /** @var Logger */ | 
| 314 | 314 | protected $logger = null; | 
| @@ -320,12 +320,12 @@ discard block | ||
| 320 | 320 | * @param string $filter | 
| 321 | 321 | * @return int | 
| 322 | 322 | */ | 
| 323 | - public function run(string $filter='') : int | |
| 323 | + public function run(string $filter = '') : int | |
| 324 | 324 |      { | 
| 325 | - foreach ( $this->tests as $test => $testCase ) | |
| 325 | + foreach ($this->tests as $test => $testCase) | |
| 326 | 326 |          { | 
| 327 | - $testName = $testCase->getTestName(); | |
| 328 | - if ( $filter && $test !== $filter ) | |
| 327 | + $testName = $testCase->getTestName(); | |
| 328 | + if ($filter && $test !== $filter) | |
| 329 | 329 |              { | 
| 330 | 330 | continue; | 
| 331 | 331 | } | 
| @@ -333,36 +333,36 @@ discard block | ||
| 333 | 333 |              { | 
| 334 | 334 |                  $this->getLogger()->info("[{$testName}] - Starting..."); | 
| 335 | 335 | $testCase->runTest($this); | 
| 336 | -                $this->getLogger()->info("[{$testName}] - " . $testCase->getSuccessMessage()); | |
| 336 | +                $this->getLogger()->info("[{$testName}] - ".$testCase->getSuccessMessage()); | |
| 337 | 337 | } | 
| 338 | - catch ( \Exception $e ) | |
| 338 | + catch (\Exception $e) | |
| 339 | 339 |              { | 
| 340 | 340 | $expectedCode = $testCase->getExceptionCode(); | 
| 341 | 341 | $expectedClass = $testCase->getExceptionType(); | 
| 342 | 342 | $code = $e->getCode(); | 
| 343 | 343 | $exception = get_class($e); | 
| 344 | - if ( ! $expectedClass && ! $expectedCode ) | |
| 344 | + if ( ! $expectedClass && ! $expectedCode) | |
| 345 | 345 |                  { | 
| 346 | -                    $this->getLogger()->error($e->getMessage(), [compact('testName'), $e]); | |
| 346 | +                    $this->getLogger()->error($e->getMessage(), [ compact('testName'), $e ]); | |
| 347 | 347 | $this->failedCount++; | 
| 348 | 348 | |
| 349 | 349 | continue; | 
| 350 | 350 | } | 
| 351 | - if ( $expectedCode && $expectedCode !== $code ) | |
| 351 | + if ($expectedCode && $expectedCode !== $code) | |
| 352 | 352 |                  { | 
| 353 | -                    $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [compact('testName'), $e]); | |
| 353 | +                    $this->getLogger()->error("Exception code({$code}) was expected to be ({$expectedCode})", [ compact('testName'), $e ]); | |
| 354 | 354 | $this->failedCount++; | 
| 355 | 355 | |
| 356 | 356 | continue; | 
| 357 | 357 | } | 
| 358 | - if ( $expectedClass && $expectedClass !== $exception ) | |
| 358 | + if ($expectedClass && $expectedClass !== $exception) | |
| 359 | 359 |                  { | 
| 360 | -                    $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [compact('testName'), $e]); | |
| 360 | +                    $this->getLogger()->error("Exception class({$exception}) was expected to be ({$expectedClass})", [ compact('testName'), $e ]); | |
| 361 | 361 | $this->failedCount++; | 
| 362 | 362 | |
| 363 | 363 | continue; | 
| 364 | 364 | } | 
| 365 | -                $this->getLogger()->info("[{$test}] - " . $testCase->getSuccessMessage()); | |
| 365 | +                $this->getLogger()->info("[{$test}] - ".$testCase->getSuccessMessage()); | |
| 366 | 366 | } | 
| 367 | 367 | } | 
| 368 | 368 | |
| @@ -394,9 +394,9 @@ discard block | ||
| 394 | 394 | * @return Suite | 
| 395 | 395 | * @throws AssertionFailedException | 
| 396 | 396 | */ | 
| 397 | - public function test(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') : Suite | |
| 397 | + public function test(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') : Suite | |
| 398 | 398 |      { | 
| 399 | - $this->tests[] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); | |
| 399 | + $this->tests[ ] = new Test($testName, $test, $successMessage, $exceptionCode, $exceptionClass); | |
| 400 | 400 | |
| 401 | 401 | return $this; | 
| 402 | 402 | } | 
| @@ -408,7 +408,7 @@ discard block | ||
| 408 | 408 | */ | 
| 409 | 409 | public function fixture(string $fixtureName, $value) : Suite | 
| 410 | 410 |      { | 
| 411 | - $this->fixtures[$fixtureName] = $value; | |
| 411 | + $this->fixtures[ $fixtureName ] = $value; | |
| 412 | 412 | |
| 413 | 413 | return $this; | 
| 414 | 414 | } | 
| @@ -422,7 +422,7 @@ discard block | ||
| 422 | 422 |      { | 
| 423 | 423 |          Assert::that($this->fixtures)->keyExists($fixtureName, "The fixture ({$fixtureName}) does not exist."); | 
| 424 | 424 | |
| 425 | - return $this->fixtures[$fixtureName]; | |
| 425 | + return $this->fixtures[ $fixtureName ]; | |
| 426 | 426 | } | 
| 427 | 427 | |
| 428 | 428 | |
| @@ -442,7 +442,7 @@ discard block | ||
| 442 | 442 | */ | 
| 443 | 443 | public function getLogger() : Logger | 
| 444 | 444 |      { | 
| 445 | - if ( ! $this->logger ) | |
| 445 | + if ( ! $this->logger) | |
| 446 | 446 |          { | 
| 447 | 447 | $this->logger = new Logger(); | 
| 448 | 448 | } | 
| @@ -479,7 +479,7 @@ discard block | ||
| 479 | 479 | * @param string $exceptionClass | 
| 480 | 480 | * @throws AssertionFailedException | 
| 481 | 481 | */ | 
| 482 | - public function __construct(string $testName, Closure $test, string $successMessage='', int $exceptionCode=0, string $exceptionClass='') | |
| 482 | + public function __construct(string $testName, Closure $test, string $successMessage = '', int $exceptionCode = 0, string $exceptionClass = '') | |
| 483 | 483 |      { | 
| 484 | 484 | $this->setTestName($testName); | 
| 485 | 485 | $this->setTest($test); | 
| @@ -514,7 +514,7 @@ discard block | ||
| 514 | 514 | */ | 
| 515 | 515 | public function getSuccessMessage() : string | 
| 516 | 516 |      { | 
| 517 | - if ( ! $this->successMessage ) | |
| 517 | + if ( ! $this->successMessage) | |
| 518 | 518 |          { | 
| 519 | 519 |              return "Successfully run {$this->testName}"; | 
| 520 | 520 | } | 
| @@ -667,21 +667,21 @@ discard block | ||
| 667 | 667 | /** | 
| 668 | 668 | * @var array $logLevels List of supported levels | 
| 669 | 669 | */ | 
| 670 | - static protected $logLevels = [ | |
| 671 | - self::EMERGENCY => [1, self::WHITE, self::RED, self::DEFAULT, 'EMERG'], | |
| 672 | - self::ALERT => [2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT'], | |
| 673 | - self::CRITICAL => [3, self::RED, self::DEFAULT, self::BOLD , 'CRIT'], | |
| 674 | - self::ERROR => [4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR'], | |
| 675 | - self::WARNING => [5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN'], | |
| 676 | - self::NOTICE => [6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE'], | |
| 677 | - self::INFO => [7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO'], | |
| 678 | - self::DEBUG => [8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG'], | |
| 670 | + static protected $logLevels = [ | |
| 671 | + self::EMERGENCY => [ 1, self::WHITE, self::RED, self::DEFAULT, 'EMERG' ], | |
| 672 | + self::ALERT => [ 2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT' ], | |
| 673 | + self::CRITICAL => [ 3, self::RED, self::DEFAULT, self::BOLD, 'CRIT' ], | |
| 674 | + self::ERROR => [ 4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR' ], | |
| 675 | + self::WARNING => [ 5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN' ], | |
| 676 | + self::NOTICE => [ 6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE' ], | |
| 677 | + self::INFO => [ 7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO' ], | |
| 678 | + self::DEBUG => [ 8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG' ], | |
| 679 | 679 | ]; | 
| 680 | 680 | |
| 681 | 681 | /** | 
| 682 | 682 | * @var array | 
| 683 | 683 | */ | 
| 684 | - static protected $colours = [ | |
| 684 | + static protected $colours = [ | |
| 685 | 685 | 'fore' => [ | 
| 686 | 686 | self::BLACK => '0;30', | 
| 687 | 687 | self::DARK_GRAY => '1;30', | 
| @@ -712,7 +712,7 @@ discard block | ||
| 712 | 712 | self::CYAN => '46', | 
| 713 | 713 | self::LIGHT_GRAY => '47', | 
| 714 | 714 | ], | 
| 715 | - self::BOLD => [], | |
| 715 | + self::BOLD => [ ], | |
| 716 | 716 | ]; | 
| 717 | 717 | |
| 718 | 718 | /** | 
| @@ -722,7 +722,7 @@ discard block | ||
| 722 | 722 | * @param bool $gzipFile | 
| 723 | 723 | * @param bool $addDate | 
| 724 | 724 | */ | 
| 725 | - public function __construct($resource=STDOUT, string $level=self::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true) | |
| 725 | + public function __construct($resource = STDOUT, string $level = self::INFO, bool $useLocking = false, bool $gzipFile = false, bool $addDate = true) | |
| 726 | 726 |      { | 
| 727 | 727 | $this->resource = $resource; | 
| 728 | 728 | $this->setLogLevel($level); | 
| @@ -737,7 +737,7 @@ discard block | ||
| 737 | 737 | * @param string $message | 
| 738 | 738 | * @param array $context | 
| 739 | 739 | */ | 
| 740 | - public function emergency(string $message, array $context=[]) | |
| 740 | + public function emergency(string $message, array $context = [ ]) | |
| 741 | 741 |      { | 
| 742 | 742 | $this->log(self::EMERGENCY, $message, $context); | 
| 743 | 743 | } | 
| @@ -751,7 +751,7 @@ discard block | ||
| 751 | 751 | * @param string $message | 
| 752 | 752 | * @param array $context | 
| 753 | 753 | */ | 
| 754 | - public function alert(string $message, array $context=[]) | |
| 754 | + public function alert(string $message, array $context = [ ]) | |
| 755 | 755 |      { | 
| 756 | 756 | $this->log(self::ALERT, $message, $context); | 
| 757 | 757 | } | 
| @@ -764,7 +764,7 @@ discard block | ||
| 764 | 764 | * @param string $message | 
| 765 | 765 | * @param array $context | 
| 766 | 766 | */ | 
| 767 | - public function critical(string $message, array $context=[]) | |
| 767 | + public function critical(string $message, array $context = [ ]) | |
| 768 | 768 |      { | 
| 769 | 769 | $this->log(self::CRITICAL, $message, $context); | 
| 770 | 770 | } | 
| @@ -776,7 +776,7 @@ discard block | ||
| 776 | 776 | * @param string $message | 
| 777 | 777 | * @param array $context | 
| 778 | 778 | */ | 
| 779 | - public function error(string $message, array $context=[]) | |
| 779 | + public function error(string $message, array $context = [ ]) | |
| 780 | 780 |      { | 
| 781 | 781 | $this->log(self::ERROR, $message, $context); | 
| 782 | 782 | } | 
| @@ -790,7 +790,7 @@ discard block | ||
| 790 | 790 | * @param string $message | 
| 791 | 791 | * @param array $context | 
| 792 | 792 | */ | 
| 793 | - public function warning(string $message, array $context=[]) | |
| 793 | + public function warning(string $message, array $context = [ ]) | |
| 794 | 794 |      { | 
| 795 | 795 | $this->log(self::WARNING, $message, $context); | 
| 796 | 796 | } | 
| @@ -801,7 +801,7 @@ discard block | ||
| 801 | 801 | * @param string $message | 
| 802 | 802 | * @param array $context | 
| 803 | 803 | */ | 
| 804 | - public function notice(string $message, array $context=[]) | |
| 804 | + public function notice(string $message, array $context = [ ]) | |
| 805 | 805 |      { | 
| 806 | 806 | $this->log(self::NOTICE, $message, $context); | 
| 807 | 807 | } | 
| @@ -814,7 +814,7 @@ discard block | ||
| 814 | 814 | * @param string $message | 
| 815 | 815 | * @param array $context | 
| 816 | 816 | */ | 
| 817 | - public function info(string $message, array $context=[]) | |
| 817 | + public function info(string $message, array $context = [ ]) | |
| 818 | 818 |      { | 
| 819 | 819 | $this->log(self::INFO, $message, $context); | 
| 820 | 820 | } | 
| @@ -825,7 +825,7 @@ discard block | ||
| 825 | 825 | * @param string $message | 
| 826 | 826 | * @param array $context | 
| 827 | 827 | */ | 
| 828 | - public function debug(string $message, array $context=[]) | |
| 828 | + public function debug(string $message, array $context = [ ]) | |
| 829 | 829 |      { | 
| 830 | 830 | $this->log(self::DEBUG, $message, $context); | 
| 831 | 831 | } | 
| @@ -836,7 +836,7 @@ discard block | ||
| 836 | 836 | */ | 
| 837 | 837 | public function setLogFile($resource) : Logger | 
| 838 | 838 |      { | 
| 839 | - $this->resource = $resource; | |
| 839 | + $this->resource = $resource; | |
| 840 | 840 | |
| 841 | 841 | return $this; | 
| 842 | 842 | } | 
| @@ -848,23 +848,23 @@ discard block | ||
| 848 | 848 | * @param bool $bold | 
| 849 | 849 | * @return string | 
| 850 | 850 | */ | 
| 851 | - public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string | |
| 851 | + public static function addColour(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string | |
| 852 | 852 |      { | 
| 853 | 853 | // todo: support bold | 
| 854 | 854 | unset($bold); | 
| 855 | 855 | $coloredString = ''; | 
| 856 | 856 | // Check if given foreground color found | 
| 857 | - if ( isset(static::$colours['fore'][$foregroundColor]) ) | |
| 857 | + if (isset(static::$colours[ 'fore' ][ $foregroundColor ])) | |
| 858 | 858 |          { | 
| 859 | - $coloredString .= "\033[" . static::$colours['fore'][$foregroundColor] . "m"; | |
| 859 | + $coloredString .= "\033[".static::$colours[ 'fore' ][ $foregroundColor ]."m"; | |
| 860 | 860 | } | 
| 861 | 861 | // Check if given background color found | 
| 862 | - if ( isset(static::$colours['back'][$backgroundColor]) ) | |
| 862 | + if (isset(static::$colours[ 'back' ][ $backgroundColor ])) | |
| 863 | 863 |          { | 
| 864 | - $coloredString .= "\033[" . static::$colours['back'][$backgroundColor] . "m"; | |
| 864 | + $coloredString .= "\033[".static::$colours[ 'back' ][ $backgroundColor ]."m"; | |
| 865 | 865 | } | 
| 866 | 866 | // Add string and end coloring | 
| 867 | - $coloredString .= $string . "\033[0m"; | |
| 867 | + $coloredString .= $string."\033[0m"; | |
| 868 | 868 | |
| 869 | 869 | return $coloredString; | 
| 870 | 870 | } | 
| @@ -876,7 +876,7 @@ discard block | ||
| 876 | 876 | * @param bool $bold | 
| 877 | 877 | * @return string | 
| 878 | 878 | */ | 
| 879 | - public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string | |
| 879 | + public function colourize(string $string, string $foregroundColor = '', string $backgroundColor = '', bool $bold = false) : string | |
| 880 | 880 |      { | 
| 881 | 881 | return static::addColour($string, $foregroundColor, $backgroundColor, $bold); | 
| 882 | 882 | } | 
| @@ -887,11 +887,11 @@ discard block | ||
| 887 | 887 | */ | 
| 888 | 888 | public function setLogLevel(string $level) : Logger | 
| 889 | 889 |      { | 
| 890 | - if ( ! isset(static::$logLevels[$level]) ) | |
| 890 | + if ( ! isset(static::$logLevels[ $level ])) | |
| 891 | 891 |          { | 
| 892 | 892 |              throw new \InvalidArgumentException("Log level is invalid"); | 
| 893 | 893 | } | 
| 894 | - $this->level = static::$logLevels[$level][0]; | |
| 894 | + $this->level = static::$logLevels[ $level ][ 0 ]; | |
| 895 | 895 | |
| 896 | 896 | return $this; | 
| 897 | 897 | } | 
| @@ -935,25 +935,25 @@ discard block | ||
| 935 | 935 | * @param string|object $message If an object is passed it must implement __toString() | 
| 936 | 936 | * @param array $context Placeholders to be substituted in the message | 
| 937 | 937 | */ | 
| 938 | - public function log($level, $message, array $context=[]) | |
| 938 | + public function log($level, $message, array $context = [ ]) | |
| 939 | 939 |      { | 
| 940 | - $level = isset(static::$logLevels[$level]) ? $level : self::INFO; | |
| 941 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$level]; | |
| 940 | + $level = isset(static::$logLevels[ $level ]) ? $level : self::INFO; | |
| 941 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $level ]; | |
| 942 | 942 | unset($style); | 
| 943 | - if ( $logLevel > $this->level ) | |
| 943 | + if ($logLevel > $this->level) | |
| 944 | 944 |          { | 
| 945 | - return ; | |
| 945 | + return; | |
| 946 | 946 | } | 
| 947 | - if ( is_callable($this->formatter) ) | |
| 947 | + if (is_callable($this->formatter)) | |
| 948 | 948 |          { | 
| 949 | - $message = $this->formatter->__invoke(static::$logLevels[$level][4], $message, $context); | |
| 949 | + $message = $this->formatter->__invoke(static::$logLevels[ $level ][ 4 ], $message, $context); | |
| 950 | 950 | } | 
| 951 | 951 | else | 
| 952 | 952 |          { | 
| 953 | 953 | $message = $this->formatMessage($level, $message, $context); | 
| 954 | 954 | } | 
| 955 | 955 | $this->lastLogEntry = $message; | 
| 956 | - $this->write($this->colourize($message, $fore, $back) . PHP_EOL); | |
| 956 | + $this->write($this->colourize($message, $fore, $back).PHP_EOL); | |
| 957 | 957 | } | 
| 958 | 958 | |
| 959 | 959 | /** | 
| @@ -963,8 +963,8 @@ discard block | ||
| 963 | 963 | */ | 
| 964 | 964 | public static function style(string $style, string $message) : string | 
| 965 | 965 |      { | 
| 966 | - $style = isset(static::$logLevels[$style]) ? $style : self::INFO; | |
| 967 | - list($logLevel, $fore, $back, $style) = static::$logLevels[$style]; | |
| 966 | + $style = isset(static::$logLevels[ $style ]) ? $style : self::INFO; | |
| 967 | + list($logLevel, $fore, $back, $style) = static::$logLevels[ $style ]; | |
| 968 | 968 | unset($logLevel, $style); | 
| 969 | 969 | |
| 970 | 970 | return static::addColour($message, $fore, $back); | 
| @@ -976,14 +976,14 @@ discard block | ||
| 976 | 976 | * @param array $context | 
| 977 | 977 | * @return string | 
| 978 | 978 | */ | 
| 979 | - protected function formatMessage(string $level, string $message, array $context=[]) : string | |
| 979 | + protected function formatMessage(string $level, string $message, array $context = [ ]) : string | |
| 980 | 980 |      { | 
| 981 | 981 | # Handle objects implementing __toString | 
| 982 | - $message = (string) $message; | |
| 983 | - $message .= empty($context) ? '' : PHP_EOL . json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | |
| 984 | -        $data               = $this->addDate ? ['date' => date('Y-m-d H:i:s')] : []; | |
| 985 | - $data['level'] = strtoupper(str_pad(static::$logLevels[$level][4], 5, ' ', STR_PAD_RIGHT)); | |
| 986 | - $data['message'] = $message; | |
| 982 | + $message = (string)$message; | |
| 983 | + $message .= empty($context) ? '' : PHP_EOL.json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | |
| 984 | +        $data               = $this->addDate ? [ 'date' => date('Y-m-d H:i:s') ] : [ ]; | |
| 985 | + $data[ 'level' ] = strtoupper(str_pad(static::$logLevels[ $level ][ 4 ], 5, ' ', STR_PAD_RIGHT)); | |
| 986 | + $data[ 'message' ] = $message; | |
| 987 | 987 | |
| 988 | 988 | return implode($this->separator, $data); | 
| 989 | 989 | } | 
| @@ -996,12 +996,12 @@ discard block | ||
| 996 | 996 | public function write(string $content) | 
| 997 | 997 |      { | 
| 998 | 998 | $resource = $this->getResource(); | 
| 999 | - if ( $this->useLocking ) | |
| 999 | + if ($this->useLocking) | |
| 1000 | 1000 |          { | 
| 1001 | 1001 | flock($resource, LOCK_EX); | 
| 1002 | 1002 | } | 
| 1003 | 1003 | gzwrite($resource, $content); | 
| 1004 | - if ( $this->useLocking ) | |
| 1004 | + if ($this->useLocking) | |
| 1005 | 1005 |          { | 
| 1006 | 1006 | flock($resource, LOCK_UN); | 
| 1007 | 1007 | } | 
| @@ -1013,14 +1013,14 @@ discard block | ||
| 1013 | 1013 | */ | 
| 1014 | 1014 | protected function getResource() | 
| 1015 | 1015 |      { | 
| 1016 | - if ( is_resource($this->resource) ) | |
| 1016 | + if (is_resource($this->resource)) | |
| 1017 | 1017 |          { | 
| 1018 | 1018 | return $this->resource; | 
| 1019 | 1019 | } | 
| 1020 | 1020 | $fileName = $this->resource; | 
| 1021 | 1021 | $this->closeLocally = true; | 
| 1022 | 1022 | $this->resource = $this->openResource(); | 
| 1023 | - if ( ! is_resource($this->resource) ) | |
| 1023 | + if ( ! is_resource($this->resource)) | |
| 1024 | 1024 |          { | 
| 1025 | 1025 |              throw new \Exception("The resource ({$fileName}) could not be opened"); | 
| 1026 | 1026 | } | 
| @@ -1041,7 +1041,7 @@ discard block | ||
| 1041 | 1041 | */ | 
| 1042 | 1042 | protected function openResource() | 
| 1043 | 1043 |      { | 
| 1044 | - if ( $this->gzipFile ) | |
| 1044 | + if ($this->gzipFile) | |
| 1045 | 1045 |          { | 
| 1046 | 1046 | return gzopen($this->resource, 'a'); | 
| 1047 | 1047 | } |