1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace BEAR\Package\Provide\Logger; |
||
6 | |||
7 | use BEAR\AppMeta\AbstractAppMeta; |
||
8 | use Monolog\Formatter\LineFormatter; |
||
9 | use Monolog\Handler\StreamHandler; |
||
10 | use Monolog\Logger; |
||
11 | use Ray\Di\ProviderInterface; |
||
12 | |||
13 | /** @implements ProviderInterface<Logger> */ |
||
14 | class MonologProvider implements ProviderInterface |
||
15 | { |
||
16 | public function __construct( |
||
17 | private AbstractAppMeta $appMeta, |
||
18 | ) { |
||
19 | 5 | } |
|
20 | |||
21 | 5 | /** |
|
22 | 5 | * {@inheritDoc} |
|
23 | */ |
||
24 | public function get(): Logger |
||
25 | { |
||
26 | $format = "[%datetime%] %level_name%: %message% %context%\n"; |
||
27 | 5 | $stream = new StreamHandler($this->appMeta->logDir . '/app.log'); |
|
28 | $stream->setFormatter(new LineFormatter($format)); |
||
29 | 5 | ||
30 | return new Logger($this->appMeta->name, [$stream]); |
||
0 ignored issues
–
show
|
|||
31 | } |
||
32 | } |
||
33 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: