DebuggerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 6 2
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDebug/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2018 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDebug\Factory;
11
12
use WebinoDebug\Debugger\DebuggerInterface;
13
use WebinoDebug\Options\ModuleOptions;
14
use WebinoDebug\Service\Debugger;
15
use WebinoDebug\Service\NullDebugger;
16
use Zend\ServiceManager\FactoryInterface;
17
use Zend\ServiceManager\ServiceLocatorInterface;
18
19
/**
20
 * Factory for a debugger
21
 */
22
class DebuggerFactory implements FactoryInterface
23
{
24
    /**
25
     * Debugger service name
26
     */
27
    const SERVICE = 'Debugger';
28
29
    /**
30
     * @param ServiceLocatorInterface $services
31
     * @return DebuggerInterface
32
     */
33
    public function createService(ServiceLocatorInterface $services)
34
    {
35
        /* @var $modules ModuleOptions */
36
        $options = $services->get(ModuleOptions::class);
37
        return $options->isEnabled() ? new Debugger($options) : new NullDebugger;
0 ignored issues
show
Bug introduced by
It seems like $options defined by $services->get(\WebinoDe...s\ModuleOptions::class) on line 36 can also be of type object; however, WebinoDebug\Service\Debugger::__construct() does only seem to accept array|object<WebinoDebug...s\DebuggerOptions>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38
    }
39
}
40