Passed
Push — master ( a3ceaf...637623 )
by Dedipyaman
02:09
created

Required   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 2 1
A getValue() 0 3 1
A __construct() 0 6 2
1
<?php
2
/*
3
 * This file is part of Skletter <https://github.com/2DSharp/Skletter>.
4
 *
5
 * (c) Dedipyaman Das <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Phypes\Type;
12
13
14
use Phypes\Exception\EmptyRequiredValue;
15
16
class Required implements Type
17
{
18
    /**
19
     * @var Type $type
20
     */
21
    private $type;
22
    /**
23
     * Required constructor.
24
     * @param Type $type
25
     * @throws EmptyRequiredValue
26
     */
27
    public function __construct(Type $type)
28
    {
29
        if (empty($type->getValue()))
30
            throw new EmptyRequiredValue('The required type '. get_class($type) . ' cannot have an empty value');
31
32
        $this->type = $type;
33
    }
34
35
    public function __toString(): string
36
    {
37
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. 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...
38
39
    public function getValue()
40
    {
41
        return $this->type->getValue();
42
    }
43
}