DisabledDaysProvider::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 13
rs 10
c 1
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;
10
11
use Exception;
12
use Ticaje\BookingApi\Application\Signatures\Provider\DisabledDaysGatewaySignature;
13
use Ticaje\BookingApi\Application\Signatures\Provider\DisabledDaysProviderSignature;
14
use Ticaje\BookingApi\Domain\Policies\Calendar\Disabling\CQRS\Query;
15
use Ticaje\BookingApi\Domain\Policies\Calendar\Disabling\CQRS\QuerySignature;
16
use Ticaje\Contract\Application\Service\ServiceLocatorInterface;
17
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface;
18
19
/**
20
 * Class DisabledDaysProvider
21
 * @package Ticaje\BookingApi\Application\Service\Provider
22
 */
23
class DisabledDaysProvider implements DisabledDaysProviderSignature
24
{
25
    /** @var ServiceLocatorInterface */
26
    private $serviceLocator;
27
28
    /** @var DisabledDaysGatewaySignature */
29
    private $disabledDaysGatewaySignature;
30
31
    /**
32
     * DisabledDaysProvider constructor.
33
     *
34
     * @param ServiceLocatorInterface      $serviceLocator
35
     * @param DisabledDaysGatewaySignature $disabledDaysGatewaySignature
36
     */
37
    public function __construct(
38
        ServiceLocatorInterface $serviceLocator,
39
        DisabledDaysGatewaySignature $disabledDaysGatewaySignature)
40
    {
41
        $this->serviceLocator = $serviceLocator;
42
        $this->disabledDaysGatewaySignature = $disabledDaysGatewaySignature;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function execute(UseCaseCommandInterface $command)
49
    {
50
        $items = $this->disabledDaysGatewaySignature->execute($command);
51
52
        return $this->transform($items, $command->getFormat());
0 ignored issues
show
Bug introduced by
The method getFormat() 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

52
        return $this->transform($items, $command->/** @scrutinizer ignore-call */ getFormat());
Loading history...
53
    }
54
55
    /**
56
     * @param array $items
57
     * @param       $format
58
     *
59
     * @return string
60
     */
61
    private function transform(array $items, $format): string
62
    {
63
        /** @var QuerySignature $domainFetcher */
64
        $domainFetcher = $this->serviceLocator->get(Query::class, ['format' => $format]);
0 ignored issues
show
Unused Code introduced by
The call to Ticaje\Contract\Applicat...LocatorInterface::get() has too many arguments starting with array('format' => $format). ( Ignorable by Annotation )

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

64
        /** @scrutinizer ignore-call */ 
65
        $domainFetcher = $this->serviceLocator->get(Query::class, ['format' => $format]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
65
        foreach ($items as $item) {
66
            try {
67
                $domainFetcher->interpret($item->getRule(), $item->getType());
68
            } catch (Exception $exception) {
69
                // Log properly
70
            }
71
        }
72
73
        return json_encode($domainFetcher->fetchList());
74
    }
75
}
76