Skip to content

Commit

Permalink
Cleanup code with php cs fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
8ctopus committed Dec 28, 2023
1 parent bf80458 commit 7cbe129
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 70 deletions.
4 changes: 1 addition & 3 deletions src/ApixLogException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@

use Exception;

class ApixLogException extends Exception
{
}
class ApixLogException extends Exception {}
2 changes: 1 addition & 1 deletion src/LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LogEntry
* @param string $message message
* @param mixed[] $context context
*/
public function __construct(string|int $level, string $message, array $context = [])
public function __construct(int|string $level, string $message, array $context = [])
{
$this->timestamp = time();

Expand Down
4 changes: 2 additions & 2 deletions src/Logger/AbstractLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public static function getLevelName(int $levelCode) : string
*
* @return void
*
* @throws \Psr\Log\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function log(mixed $level, Stringable|string $message, array $context = []) : void
public function log(mixed $level, string|Stringable $message, array $context = []) : void
{
$this->process(new LogEntry($level, (string) $message, $context));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/ErrorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function write(LogEntry|string $log) : bool
*
* @return null|string
*/
public function getDestination() : string|null
public function getDestination() : null|string
{
return $this->destination;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Format/ConsoleColorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ protected function tearDown() : void

public function testGetFormatReturnsStandardFormat() : void
{
static::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
self::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
}

public function testSetFormat() : void
{
$format = new ConsoleColors();
$this->logger->setFormat($format);

static::assertSame($this->logger->getFormat(), $format);
self::assertSame($this->logger->getFormat(), $format);
}

public function testFormatInterfaceExample() : void
Expand All @@ -45,6 +45,6 @@ public function testFormatInterfaceExample() : void
$this->logger->setFormat($format);

$this->logger->error('hello {who}', ['who' => 'world']);
static::assertSame(date('[Y-m-d H:i:s]') . ' [01;31mERROR hello world[0m' . PHP_EOL, $this->logger->getItems()[0]);
self::assertSame(date('[Y-m-d H:i:s]') . ' [01;31mERROR hello world[0m' . PHP_EOL, $this->logger->getItems()[0]);
}
}
6 changes: 3 additions & 3 deletions tests/Format/InterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ protected function tearDown() : void

public function testGetFormatReturnsStandardFormat() : void
{
static::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
self::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
}

public function testSetFormat() : void
{
$formatter = new MyJsonFormatter();
$this->logger->setFormat($formatter);
static::assertSame($this->logger->getFormat(), $formatter);
self::assertSame($this->logger->getFormat(), $formatter);
}

public function testFormatInterfaceExample() : void
Expand All @@ -53,7 +53,7 @@ public function testFormatInterfaceExample() : void
$this->logger->setFormat($formatter);
$this->logger->error('hello {who}', ['who' => 'world']);

static::assertMatchesRegularExpression(
self::assertMatchesRegularExpression(
'@\{"timestamp":.*\,"name":"error"\,"levelCode":3\,"message":"hello world","context":\{"who":"world"\}\}@',
$this->logger->getItems()[0]
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Format/StandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function tearDown() : void

public function testGetFormatReturnsStandardFormat() : void
{
static::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
self::assertInstanceOf('\Apix\Log\Format\Standard', $this->logger->getFormat());
}

public function testFormatInterfaceExample() : void
Expand All @@ -51,6 +51,6 @@ public function testFormatInterfaceExample() : void
'file' => tmpfile(),
]);

static::assertSame(date('[Y-m-d H:i:s]') . ' ERROR hello world 18 true {"key1":"2","key2":true}' . PHP_EOL, $this->logger->getItems()[0]);
self::assertSame(date('[Y-m-d H:i:s]') . ' ERROR hello world 18 true {"key1":"2","key2":true}' . PHP_EOL, $this->logger->getItems()[0]);
}
}
10 changes: 5 additions & 5 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ public function testUsages() : void

$date = date('[Y-m-d H:i:s]');

static::assertSame($date . ' ALERT Running out of beers 5 left, recharge: true [type: resource]' . PHP_EOL, $urgent_logs[0]);
self::assertSame($date . ' ALERT Running out of beers 5 left, recharge: true [type: resource]' . PHP_EOL, $urgent_logs[0]);

$prefixException = 'Exception: Boo! in ';

static::assertStringStartsWith($date . ' CRITICAL OMG saw ' . $prefixException, $urgent_logs[1]);
self::assertStringStartsWith($date . ' CRITICAL OMG saw ' . $prefixException, $urgent_logs[1]);

$app_logger->flushDeferredLogs();

$app_logs = $this->getLogs($app_logger, false);

static::assertStringStartsWith($date . ' CRITICAL OMG saw ' . $prefixException, $app_logs[0]);
self::assertStringStartsWith($date . ' CRITICAL OMG saw ' . $prefixException, $app_logs[0]);

static::assertStringContainsString($date . ' ERROR ' . $prefixException, $app_logs[0]);
self::assertStringContainsString($date . ' ERROR ' . $prefixException, $app_logs[0]);

static::assertSame([$date . ' INFO Something happened -> ["xyz"]' . PHP_EOL], $this->getLogs($debug_logger));
self::assertSame([$date . ' INFO Something happened -> ["xyz"]' . PHP_EOL], $this->getLogs($debug_logger));
}
}
4 changes: 2 additions & 2 deletions tests/LogEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function testConstructor() : void
'b' => false,
]);

static::assertSame(date('[Y-m-d H:i:s]') . ' EMERGENCY test' . PHP_EOL, (string) $entry);
self::assertSame(date('[Y-m-d H:i:s]') . ' EMERGENCY test' . PHP_EOL, (string) $entry);

$entry = new LogEntry(0, 'test', [
'a' => 1,
'b' => false,
]);

static::assertSame(date('[Y-m-d H:i:s]') . ' EMERGENCY test' . PHP_EOL, (string) $entry);
self::assertSame(date('[Y-m-d H:i:s]') . ' EMERGENCY test' . PHP_EOL, (string) $entry);
}
}
6 changes: 3 additions & 3 deletions tests/Logger/ErrorLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testWriteString() : void

$content = file_get_contents($this->dest);

static::assertStringContainsString($message, $content);
self::assertStringContainsString($message, $content);
}

public function testWriteObject() : void
Expand All @@ -69,8 +69,8 @@ public function testWriteObject() : void

$content = file_get_contents($this->dest);

static::assertStringContainsString((string) $test, $content);
static::assertSame($destination, $logger->getDestination());
self::assertStringContainsString((string) $test, $content);
self::assertSame($destination, $logger->getDestination());
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Logger/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testConstructor() : void
{
$logger = new File($this->dest);

static::assertInstanceOf(File::class, $logger);
self::assertInstanceOf(File::class, $logger);
}

public function testThrowsInvalidArgumentExceptionWhenFileCannotBeCreated() : void
Expand Down
2 changes: 1 addition & 1 deletion tests/Logger/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function testThrowsInvalidArgumentException() : void
public function testConstructor() : void
{
new Mail('foo@bar.com', 'CC: some@somewhere.com');
static::assertTrue(true);
self::assertTrue(true);
}
}
2 changes: 1 addition & 1 deletion tests/Logger/RuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testAbstractLogger() : void
$this->logger->debug('msg1', $context);
$this->logger->error('msg2', $context);

static::assertSame(
self::assertSame(
[
date('[Y-m-d H:i:s]') . ' DEBUG msg1' . PHP_EOL,
date('[Y-m-d H:i:s]') . ' ERROR msg2' . PHP_EOL,
Expand Down
2 changes: 1 addition & 1 deletion tests/Logger/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getLogs() : array
public function testWrite() : void
{
$this->logger->info('test');
static::assertSame(date('[Y-m-d H:i:s]') . ' INFO test', $this->getLogs()[0]);
self::assertSame(date('[Y-m-d H:i:s]') . ' INFO test', $this->getLogs()[0]);
}

public function testInvalidResource() : void
Expand Down
Loading

0 comments on commit 7cbe129

Please sign in to comment.