RootAggregate::instance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Application Service Class
5
 * @package Ticaje_BookingApi
6
 * @author  Hector Luis Barrientos <[email protected]>
7
 */
8
9
namespace Ticaje\BookingApi\Application\Service\Provider\Package;
10
11
use Ticaje\BookingApi\Application\Signatures\Provider\Package\PackageProviderSignature;
12
use Ticaje\BookingApi\Application\Signatures\Repository\PackageRepositoryInterface;
13
use Ticaje\Contract\Persistence\Entity\EntityInterface;
14
use Ticaje\Contract\Persistence\Repository\RepositoryInterface as BaseRepositoryInterface;
15
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface;
16
17
/**
18
 * Class RootAggregate
19
 * @package Ticaje\BookingApi\Application\Service\Provider
20
 */
21
class RootAggregate implements PackageProviderSignature
22
{
23
    /** @var PackageRepositoryInterface $packageRepository */
24
    private $packageRepository;
25
26
    /** @var EntityInterface $package */
27
    private $package;
28
29
    /**
30
     * Package constructor.
31
     *
32
     * @param BaseRepositoryInterface $packageRepository
33
     */
34
    public function __construct(
35
        BaseRepositoryInterface $packageRepository
36
    ) {
37
        $this->packageRepository = $packageRepository;
0 ignored issues
show
Documentation Bug introduced by
$packageRepository is of type Ticaje\Contract\Persiste...ory\RepositoryInterface, but the property $packageRepository was declared to be of type Ticaje\BookingApi\Applic...kageRepositoryInterface. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function instance(UseCaseCommandInterface $command): PackageProviderSignature
44
    {
45
        $productId = $command->getProductId();
0 ignored issues
show
Bug introduced by
The method getProductId() does not exist on Ticaje\Hexagonal\Applica...UseCaseCommandInterface. It seems like you code against a sub-type of Ticaje\Hexagonal\Applica...UseCaseCommandInterface such as Ticaje\BookingApi\Applic...and\DisabledDaysCommand or Ticaje\BookingApi\Applic...etPickupLocationCommand or Ticaje\BookingApi\Applic...Command\GetPriceCommand or Ticaje\BookingApi\Applic...mmand\GetPackageCommand or Ticaje\BookingApi\Applic...\GetAvailabilityCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        /** @scrutinizer ignore-call */ 
46
        $productId = $command->getProductId();
Loading history...
46
        $storeId = $command->getStoreId();
0 ignored issues
show
Bug introduced by
The method getStoreId() does not exist on Ticaje\Hexagonal\Applica...UseCaseCommandInterface. It seems like you code against a sub-type of Ticaje\Hexagonal\Applica...UseCaseCommandInterface such as Ticaje\BookingApi\Applic...and\DisabledDaysCommand or Ticaje\BookingApi\Applic...etPickupLocationCommand or Ticaje\BookingApi\Applic...Command\GetPriceCommand or Ticaje\BookingApi\Applic...mmand\GetPackageCommand or Ticaje\BookingApi\Applic...\GetAvailabilityCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        /** @scrutinizer ignore-call */ 
47
        $storeId = $command->getStoreId();
Loading history...
47
        $this->package = $this->packageRepository->getByProductAndStore($productId, $storeId);
48
49
        return $this;
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function getAvailability(int $from, int $to): bool
56
    {
57
        // @todo implementation
58
    }
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 boolean. 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...
59
60
    /**
61
     * @inheritDoc
62
     */
63
    public function getDepartureDays(): array
64
    {
65
        $result = unserialize($this->package->getDepartureDays());
0 ignored issues
show
Bug introduced by
The method getDepartureDays() does not exist on Ticaje\Contract\Persistence\Entity\EntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        $result = unserialize($this->package->/** @scrutinizer ignore-call */ getDepartureDays());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
67
        return array_map(function ($value) {
68
            return $value - 1;
69
        }, $result);
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function getNumberOfNights(): int
76
    {
77
        return (int)$this->package->getNumberOfNights();
0 ignored issues
show
Bug introduced by
The method getNumberOfNights() does not exist on Ticaje\Contract\Persistence\Entity\EntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        return (int)$this->package->/** @scrutinizer ignore-call */ getNumberOfNights();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function getDateTo(): string
84
    {
85
        return $this->package->getDateTo();
0 ignored issues
show
Bug introduced by
The method getDateTo() does not exist on Ticaje\Contract\Persistence\Entity\EntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        return $this->package->/** @scrutinizer ignore-call */ getDateTo();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
    }
87
}
88