LastInstance::__construct()   B
last analyzed

Complexity

Conditions 11
Paths 36

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 12
c 1
b 0
f 0
nc 36
nop 1
dl 0
loc 21
ccs 13
cts 13
cp 1
crap 11
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace kalanis\kw_auth_sources\Access\SourcesAdapters;
4
5
6
use kalanis\kw_accounts\AccountsException;
7
use kalanis\kw_accounts\Interfaces;
8
9
10
/**
11
 * Class LastInstance
12
 * @package kalanis\kw_auth_sources\Access\SourcesAdapters
13
 * Set that by its last known instance
14
 */
15
class LastInstance extends AAdapter
16
{
17
    /**
18
     * @param mixed ...$params
19
     * @throws AccountsException
20
     */
21 2
    public function __construct(...$params)
22
    {
23 2
        foreach ($params as $param) {
24 2
            if (is_object($param)) {
25 2
                if ($param instanceof Interfaces\IAuth) {
26 2
                    $this->auth = $param;
27
                }
28 2
                if ($param instanceof Interfaces\IProcessAccounts) {
29 2
                    $this->accounts = $param;
30
                }
31 2
                if ($param instanceof Interfaces\IProcessClasses) {
32 1
                    $this->classes = $param;
33
                }
34 2
                if ($param instanceof Interfaces\IProcessGroups) {
35 2
                    $this->groups = $param;
36
                }
37
            }
38
        }
39
40 2
        if (!($this->auth && $this->accounts && $this->classes && $this->groups)) {
41 1
            throw new AccountsException('You must set all necessary classes in the params first!');
42
        }
43 1
    }
44
}
45