StreamHandlerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 29.73 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 11
loc 37
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 11 11 1
A getStream() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Handler;
6
7
use Exception;
8
use Monolog\Handler\StreamHandler;
9
use Monolog\Logger;
10
use Psr\Container\ContainerInterface;
11
use WShafer\PSR11MonoLog\ContainerAwareInterface;
12
use WShafer\PSR11MonoLog\ContainerTrait;
13
use WShafer\PSR11MonoLog\FactoryInterface;
14
15
class StreamHandlerFactory implements FactoryInterface, ContainerAwareInterface
16
{
17
    use ContainerTrait;
18
19
    /** @var ContainerInterface */
20
    protected $container;
21
22
    /**
23
     * @param array $options
24
     * @return StreamHandler
25
     * @throws Exception
26
     */
27 3 View Code Duplication
    public function __invoke(array $options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29 3
        $stream         = $this->getStream($options['stream'] ?? null);
30
31 3
        $level          = (int)     ($options['level']          ?? Logger::DEBUG);
32 3
        $bubble         = (bool) ($options['bubble']         ?? true);
33 3
        $filePermission = (int)     ($options['filePermission'] ?? 0644);
34 3
        $useLocking     = (bool) ($options['useLocking']     ?? true);
35
36 3
        return new StreamHandler($stream, $level, $bubble, $filePermission, $useLocking);
37
    }
38
39 3
    protected function getStream($stream)
40
    {
41 3
        if ($this->container->has($stream)) {
42 1
            return $this->container->get($stream);
43
        }
44
45 2
        if (is_resource($stream)) {
46 1
            return $stream;
47
        }
48
49 1
        return (string) $stream;
50
    }
51
}
52