Passed
Push — develop ( 211c11...b276cd )
by Baptiste
01:42
created

Config   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 0 6 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Config;
5
6
use Innmind\Config\Exception\SchemaNotParseable;
7
8
final class Config
9
{
10
    private $structures;
11
    private $properties;
12
13 5
    public function __construct(
14
        Structures $structures = null,
15
        Properties $properties = null
16
   ) {
17 5
        $this->structures = $structures ?? new Structures;
18 5
        $this->properties = $properties ?? new Properties;
19 5
    }
20
21 5
    public function build(array $schema): Structure
22
    {
23
        try {
24 5
            return $this->structures->build($schema, $this->properties);
25 3
        } catch (SchemaNotParseable $e) {
26 3
            SchemaNotParseable::rethrow($e);
1 ignored issue
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Innmind\Config\Structure. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
27
        }
28
    }
29
}
30