Skip to content

Commit 5fe139a

Browse files
committed
- chore: force native functions
- chore: use PHP 8 types
1 parent ddc7c58 commit 5fe139a

6 files changed

Lines changed: 27 additions & 27 deletions

File tree

Processors/Cli.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@
1313
namespace Koded\Logging\Processors;
1414

1515
/**
16-
* Log processor for CLI apps.
16+
* Log processor for CLI.
1717
*
1818
*/
1919
class Cli extends Processor
2020
{
21-
/** @var string Message format */
22-
protected $format = '> [timestamp][levelname] - message';
21+
protected string $format = '> [timestamp][levelname] - message';
2322

2423
/** @var resource */
2524
private $handle;
2625

2726
public function __construct(array $settings)
2827
{
2928
parent::__construct($settings);
30-
$this->handle = defined('STDERR') ? STDERR : fopen('php://stderr', 'w');
29+
$this->handle = \defined('STDERR') ? STDERR : \fopen('php://stderr', 'w');
3130
}
3231

3332
protected function process(array $message): void
3433
{
35-
fwrite($this->handle, strtr($this->format, $message) . PHP_EOL);
34+
\fwrite($this->handle, \strtr($this->format, $message) . PHP_EOL);
3635
}
3736
}

Processors/ErrorLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class ErrorLog extends Processor
2020
{
2121
protected function process(array $message): void
2222
{
23-
error_log(strtr($this->format, $message), 0);
23+
\error_log(strtr($this->format, $message), 0);
2424
}
2525
}

Processors/File.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*/
3232
class File extends Processor
3333
{
34-
private $dir = '';
35-
private $ext = '';
34+
private string $dir = '';
35+
private string $ext = '';
3636

3737
/**
3838
* {@inheritdoc}
@@ -41,15 +41,15 @@ public function __construct(array $settings)
4141
{
4242
parent::__construct($settings);
4343

44-
umask(umask() | 0002);
44+
\umask(\umask() | 0002);
4545
$this->ext = (string)($settings['extension'] ?? '.log');
46-
$this->dir = rtrim((string)$settings['dir'], '/');
46+
$this->dir = \rtrim((string)$settings['dir'], '/');
4747

48-
if (false === is_dir($this->dir)) {
48+
if (false === \is_dir($this->dir)) {
4949
throw FileProcessorException::directoryDoesNotExist($this->dir);
5050
}
5151

52-
if (false === is_writable($this->dir)) {
52+
if (false === \is_writable($this->dir)) {
5353
throw FileProcessorException::directoryIsNotWritable($this->dir);
5454
}
5555

@@ -60,10 +60,10 @@ protected function process(array $message): void
6060
{
6161
try {
6262
// The filename should be calculated at the moment of writing
63-
$dir = $this->dir . date('Y/m');
64-
is_dir($dir) || mkdir($dir, 0775, true);
63+
$dir = $this->dir . \date('Y/m');
64+
\is_dir($dir) || \mkdir($dir, 0775, true);
6565

66-
file_put_contents($dir . '/' . date('d') . $this->ext, strtr($this->format, $message) . PHP_EOL,
66+
\file_put_contents($dir . '/' . \date('d') . $this->ext, \strtr($this->format, $message) . PHP_EOL,
6767
FILE_APPEND);
6868

6969
// @codeCoverageIgnoreStart
@@ -78,20 +78,21 @@ protected function process(array $message): void
7878
class FileProcessorException extends KodedException
7979
{
8080
private const
81-
E_DIRECTORY_DOES_NOT_EXIST = 1, E_DIRECTORY_NOT_WRITABLE = 2;
81+
E_DIRECTORY_DOES_NOT_EXIST = 1,
82+
E_DIRECTORY_NOT_WRITABLE = 2;
8283

83-
protected $messages = [
84+
protected array $messages = [
8485
self::E_DIRECTORY_DOES_NOT_EXIST => 'Log directory ":dir" must exist',
8586
self::E_DIRECTORY_NOT_WRITABLE => 'Log directory ":dir" must be writable',
8687
];
8788

88-
public static function directoryDoesNotExist(string $directory): self
89+
public static function directoryDoesNotExist(string $directory): static
8990
{
90-
return new self(self::E_DIRECTORY_DOES_NOT_EXIST, [':dir' => $directory]);
91+
return new static(static::E_DIRECTORY_DOES_NOT_EXIST, [':dir' => $directory]);
9192
}
9293

93-
public static function directoryIsNotWritable(string $directory): self
94+
public static function directoryIsNotWritable(string $directory): static
9495
{
95-
return new self(self::E_DIRECTORY_NOT_WRITABLE, [':dir' => $directory]);
96+
return new static(static::E_DIRECTORY_NOT_WRITABLE, [':dir' => $directory]);
9697
}
9798
}

Processors/Memory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class Memory extends Processor
2020
{
2121
protected function process(array $message): void
2222
{
23-
$this->formatted .= PHP_EOL . strtr($this->format, $message);
23+
$this->formatted .= PHP_EOL . \strtr($this->format, $message);
2424
}
2525
}

Processors/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class Processor
2727
/**
2828
* @var string The log message format.
2929
*/
30-
protected $format = 'timestamp [levelname]: message';
30+
protected string $format = 'timestamp [levelname]: message';
3131

3232
/**
3333
* @var string Keeps all formatted log messages in this property.

Processors/Syslog.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class Syslog extends Processor
2323
{
24-
protected $format = '[levelname] message';
24+
protected string $format = '[levelname] message';
2525

2626
protected function process(array $message): void
2727
{
@@ -37,10 +37,10 @@ protected function process(array $message): void
3737
];
3838

3939
try {
40-
openlog(null, LOG_CONS, LOG_USER);
41-
syslog($levels[$message['level']] ?? LOG_DEBUG, strtr($this->format, $message));
40+
\openlog(null, LOG_CONS, LOG_USER);
41+
\syslog($levels[$message['level']] ?? LOG_DEBUG, \strtr($this->format, $message));
4242
} finally {
43-
closelog();
43+
\closelog();
4444
}
4545
}
4646
}

0 commit comments

Comments
 (0)