bearsunday /
BEAR.Package
| 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 Override; |
||
| 12 | use Ray\Di\ProviderInterface; |
||
| 13 | |||
| 14 | /** @implements ProviderInterface<Logger> */ |
||
| 15 | final class MonologProvider implements ProviderInterface |
||
| 16 | { |
||
| 17 | public function __construct( |
||
| 18 | private AbstractAppMeta $appMeta, |
||
| 19 | ) { |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * {@inheritDoc} |
||
| 24 | */ |
||
| 25 | #[Override] |
||
| 26 | public function get(): Logger |
||
| 27 | { |
||
| 28 | $format = "[%datetime%] %level_name%: %message% %context%\n"; |
||
| 29 | $stream = new StreamHandler($this->appMeta->logDir . '/app.log'); |
||
| 30 | $stream->setFormatter(new LineFormatter($format)); |
||
| 31 | |||
| 32 | return new Logger($this->appMeta->name, [$stream]); |
||
|
0 ignored issues
–
show
|
|||
| 33 | } |
||
| 34 | } |
||
| 35 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: