Completed
Pull Request — master (#8)
by Klochok
15:06
created

ActionCalculateAction::__invoke()   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\sale\Close;
4
5
use hiqdev\billing\hiapi\action\ActionRepository;
6
use hiqdev\billing\hiapi\action\Calculate\ActionCalculateCommand;
7
use hiqdev\php\billing\action\Action;
8
9
class ActionCalculateAction
10
{
11
    /**
12
     * @var ActionRepository
13
     */
14
    private $repo;
15
16
    public function __construct(ActionRepository $repo)
17
    {
18
        $this->repo = $repo;
19
    }
20
21
    public function __invoke(ActionCalculateCommand $command): Action
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\action\Action. 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
//        $action = new Action();
25
//         $this->repo->calculate($action);
26
27
//        return $action;
28
    }
29
30
    protected function checkRequiredInput(ActionCalculateCommand $command): void
31
    {
32
        if (empty($command->customer)) {
0 ignored issues
show
Bug Best Practice introduced by
The property customer does not exist on hiqdev\billing\hiapi\act...\ActionCalculateCommand. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            throw new RequiredInputException('customer');
0 ignored issues
show
Bug introduced by
The type hiqdev\billing\hiapi\sal...\RequiredInputException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
        }
35
        if (empty($command->target)) {
0 ignored issues
show
Bug Best Practice introduced by
The property target does not exist on hiqdev\billing\hiapi\act...\ActionCalculateCommand. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
            throw new RequiredInputException('target');
37
        }
38
    }
39
}
40