Completed
Push — master ( 58fc10...4a64a9 )
by Andrii
12:43
created

Action::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hiqdev\billing\hiapi\tools\CleanForTests;
4
5
use hiqdev\billing\hiapi\customer\CustomerRepository;
6
use hiapi\exceptions\domain\RequiredInputException;
7
use hiqdev\php\billing\customer\Customer;
8
9
class Action
10
{
11
    /**
12
     * @var CustomerRepository
13
     */
14
    private $repo;
15
16
    public function __construct(CustomerRepository $repo)
17
    {
18
        $this->repo = $repo;
19
    }
20
21
    public function __invoke(Command $command): Customer
22
    {
23
        $this->checkRequiredInput($command);
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 hiqdev\php\billing\customer\Customer. 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...
24
    }
25
26
    protected function checkRequiredInput(Command $command)
27
    {
28
        if (empty($command->customer_id)) {
29
            if (empty($command->customer)) {
0 ignored issues
show
Bug Best Practice introduced by
The property customer does not exist on hiqdev\billing\hiapi\tools\CleanForTests\Command. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
                throw new RequiredInputException('customer or customer_id');
31
            }
32
        }
33
    }
34
}
35