LoggerAwareDelegatorFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Logger;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\Log;
9
10
class LoggerAwareDelegatorFactory
11
{
12
    /**
13
     * @return mixed
14
     */
15 4
    public function __invoke(ContainerInterface $container, string $name, callable $callback)
16
    {
17 4
        $instance = $callback();
18 4
        if ($instance instanceof Log\LoggerAwareInterface && $container->has(Log\LoggerInterface::class)) {
19 1
            $instance->setLogger($container->get(Log\LoggerInterface::class));
20
        }
21
22 4
        return $instance;
23
    }
24
}
25