AddCarDocumentCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 15 1
1
<?php
2
3
namespace Madkom\RegistryApplication\Application\CarManagement\Command\Car;
4
5
use Madkom\RegistryApplication\Application\CarManagement\Command\CommandInterface;
6
use Madkom\RegistryApplication\Application\CarManagement\DocumentDTO;
7
use Madkom\RegistryApplication\Domain\CarManagement\DocumentFactory;
8
use Madkom\RegistryApplication\Infrastructure\CarManagement\CarInMemoryRepository;
9
10
class AddCarDocumentCommand implements CommandInterface
11
{
12
    private $preparedDocument;
13
    private $repository;
14
    private $carId;
15
16
    public function __construct(CarInMemoryRepository $repository, $carId, DocumentDTO $preparedDocument)
17
    {
18
        $this->preparedDocument = $preparedDocument;
19
        $this->repository = $repository;
20
        $this->carId = $carId;
21
    }
22
23
    public function execute()
24
    {
25
        $document = new DocumentFactory();
26
        $carDocument = $document->create(DocumentFactory::CAR_DOCUMENT,
27
                                            $this->preparedDocument->docId,
28
                                            $this->preparedDocument->title,
29
                                            $this->preparedDocument->description,
30
                                            $this->preparedDocument->source
31
        );
32
33
        $car = $this->repository->find($this->carId);
34
        $car->addCarDocument($carDocument);
0 ignored issues
show
Bug introduced by
It seems like $carDocument defined by $document->create(\Madko...eparedDocument->source) on line 26 can also be of type null or object<Madkom\RegistryAp...nces\InsuranceDocument>; however, Madkom\RegistryApplicati...t\Car::addCarDocument() does only seem to accept object<Madkom\RegistryAp...Management\CarDocument>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
35
36
        $this->repository->add($car);
37
    }
38
}
39