Completed
Pull Request — master (#8)
by Daniel
04:09 queued 01:56
created

Capabilities   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 20 2
A getSupportedComparators() 0 4 1
A canSetParent() 0 4 1
1
<?php
2
3
namespace Psi\Component\ObjectAgent;
4
5
final class Capabilities
6
{
7
    private $supportedComparators;
8
    private $setParent;
9
10
    private function __construct()
11
    {
12
        // this class cannot be instantiated with "new".
13
    }
14
15
    public static function create(array $capabilities): Capabilities
16
    {
17
        $defaults = [
18
            'supported_comparators' => [],
19
            'can_set_parent' => false,
20
        ];
21
22
        if ($diff = array_diff(array_keys($capabilities), array_keys($defaults))) {
23
            throw new \InvalidArgumentException(sprintf(
24
                'Unknown capabilities: "%s". Valid capabilities: "%s"',
25
                implode('", "', $diff), implode('", "', array_keys($defaults))
26
            ));
27
        }
28
29
        $instance = new self();
30
        $instance->supportedComparators = $capabilities['supported_comparators'];
31
        $instance->setParent = $capabilities['can_set_parent'];
32
33
        return $instance;
34
    }
35
36
    public function getSupportedComparators(): array
37
    {
38
        return $this->supportedComparators;
39
    }
40
41
    public function canSetParent(): bool
42
    {
43
        return $this->setParent;
44
    }
45
}
46