CrefoPayNotificationProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
c 1
b 0
f 0
dl 0
loc 69
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processNotification() 0 13 2
A validateMac() 0 7 1
A __construct() 0 8 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Yves\CrefoPay\Processor\Notification;
9
10
use Generated\Shared\Transfer\CrefoPayNotificationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PayNotificationTransfer 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...
11
use SprykerEco\Client\CrefoPay\CrefoPayClientInterface;
12
use SprykerEco\Yves\CrefoPay\Dependency\Service\CrefoPayToCrefoPayApiServiceInterface;
13
use SprykerEco\Yves\CrefoPay\Processor\Notification\Mapper\CrefoPayNotificationProcessorMapperInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
16
class CrefoPayNotificationProcessor implements CrefoPayNotificationProcessorInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    protected const API_FIELD_MAC = 'mac';
22
23
    /**
24
     * @var \SprykerEco\Yves\CrefoPay\Processor\Notification\Mapper\CrefoPayNotificationProcessorMapperInterface
25
     */
26
    protected $mapper;
27
28
    /**
29
     * @var \SprykerEco\Client\CrefoPay\CrefoPayClientInterface
30
     */
31
    protected $crefoPayClient;
32
33
    /**
34
     * @var \SprykerEco\Yves\CrefoPay\Dependency\Service\CrefoPayToCrefoPayApiServiceInterface
35
     */
36
    protected $crefoPayApiService;
37
38
    /**
39
     * @param \SprykerEco\Yves\CrefoPay\Processor\Notification\Mapper\CrefoPayNotificationProcessorMapperInterface $mapper
40
     * @param \SprykerEco\Client\CrefoPay\CrefoPayClientInterface $crefoPayClient
41
     * @param \SprykerEco\Yves\CrefoPay\Dependency\Service\CrefoPayToCrefoPayApiServiceInterface $crefoPayApiService
42
     */
43
    public function __construct(
44
        CrefoPayNotificationProcessorMapperInterface $mapper,
45
        CrefoPayClientInterface $crefoPayClient,
46
        CrefoPayToCrefoPayApiServiceInterface $crefoPayApiService
47
    ) {
48
        $this->mapper = $mapper;
49
        $this->crefoPayClient = $crefoPayClient;
50
        $this->crefoPayApiService = $crefoPayApiService;
51
    }
52
53
    /**
54
     * @param \Symfony\Component\HttpFoundation\Request $request
55
     *
56
     * @return void
57
     */
58
    public function processNotification(Request $request): void
59
    {
60
        if (!$this->validateMac($request)) {
61
            return;
62
        }
63
64
        $notificationTransfer = $this->mapper
65
            ->mapRequestToNotificationTransfer(
66
                $request,
67
                new CrefoPayNotificationTransfer(),
68
            );
69
70
        $this->crefoPayClient->processNotification($notificationTransfer);
71
    }
72
73
    /**
74
     * @param \Symfony\Component\HttpFoundation\Request $request
75
     *
76
     * @return bool
77
     */
78
    protected function validateMac(Request $request): bool
79
    {
80
        $requestParams = $request->request->all();
81
        $macString = $requestParams[static::API_FIELD_MAC];
82
        unset($requestParams[static::API_FIELD_MAC]);
83
84
        return $this->crefoPayApiService->validateMac($requestParams, $macString);
85
    }
86
}
87