Completed
Pull Request — master (#11)
by Davide
01:03
created

Config   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 72
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 1
A getConfig() 0 4 1
A setConfig() 0 4 1
A getConfigInput() 0 4 1
1
<?php
2
3
namespace DavidePastore\Slim\Config;
4
5
/**
6
 * Config for Slim.
7
 */
8
class Config
9
{
10
    /**
11
     * The \Noodlehaus\Config object.
12
     *
13
     * @var \Noodlehaus\Config
14
     */
15
    protected $config;
16
17
    /**
18
     * The input for the config object.
19
     *
20
     * @var string|array
21
     */
22
    protected $configInput;
23
24
    /**
25
     * Create new Config service provider.
26
     *
27
     * @param string|array|ArrayAccess $configInput
28
     */
29
    public function __construct($configInput)
30
    {
31
        $this->configInput = $configInput;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configInput can also be of type object<DavidePastore\Slim\Config\ArrayAccess>. However, the property $configInput is declared as type string|array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32
    }
33
34
    /**
35
     * Config middleware invokable class.
36
     *
37
     * @param \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
38
     * @param \Psr\Http\Message\ResponseInterface      $response PSR7 response
39
     * @param callable                                 $next     Next middleware
40
     *
41
     * @return \Psr\Http\Message\ResponseInterface
42
     */
43
    public function __invoke($request, $response, $next)
44
    {
45
        $this->config = new \Noodlehaus\Config($this->configInput);
46
47
        return $next($request, $response);
48
    }
49
50
    /**
51
     * Get the config object.
52
     *
53
     * @return \Noodlehaus\Config
54
     */
55
    public function getConfig()
56
    {
57
        return $this->config;
58
    }
59
60
    /**
61
     * Set config.
62
     *
63
     * @param \Noodlehaus\Config $config The validators array.
64
     */
65
    public function setConfig($config)
66
    {
67
        $this->config = $config;
68
    }
69
70
    /**
71
     * Get config input.
72
     *
73
     * @return string|array|ArrayAccess The config input.
74
     */
75
    public function getConfigInput()
76
    {
77
        return $this->configInput;
78
    }
79
}
80