ProdMonologProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 3
dl 0
loc 11
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Logger;
6
7
use BEAR\AppMeta\AbstractAppMeta;
8
use Monolog\Handler\ErrorLogHandler;
9
use Monolog\Logger;
10
use Override;
11
use Ray\Di\ProviderInterface;
12
13
/** @implements ProviderInterface<Logger> */
14
final class ProdMonologProvider implements ProviderInterface
15
{
16
    public function __construct(
17
        private AbstractAppMeta $appMeta,
18
    ) {
19
    }
20
21
    #[Override]
22
    public function get(): Logger
23
    {
24
        return new Logger($this->appMeta->name, [new ErrorLogHandler()]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Monolog\Logge...ler\ErrorLogHandler())) returns the type Monolog\Logger which is incompatible with the return type mandated by Ray\Di\ProviderInterface::get() of Ray\Di\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
25
    }
26
}
27