isResponsePayloadCommunicationTokenExists()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Zed\ArvatoRss\Business\Api\Adapter\ApiCall\Logger;
9
10
use Orm\Zed\ArvatoRss\Persistence\SpyArvatoRssApiCallLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\ArvatoRss\Persis...\SpyArvatoRssApiCallLog 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 stdClass;
12
13
class ApiCallLogger implements ApiCallLoggerInterface
14
{
15
    protected const RESPONSE_DECISION = 'Decision';
16
    protected const RESPONSE_COMMUNICATION_TOKEN = 'CommunicationToken';
17
18
    /**
19
     * @param string $orderReference
20
     * @param string $type
21
     * @param string $resultCode
22
     * @param array $requestPayload
23
     * @param \stdClass $responsePayload
24
     *
25
     * @return void
26
     */
27
    public function log(
28
        $orderReference,
29
        $type,
30
        $resultCode,
31
        array $requestPayload,
32
        stdClass $responsePayload
33
    ) {
34
        $callLog = new SpyArvatoRssApiCallLog();
35
        $callLog->setOrderReference($orderReference)
36
            ->setCallType($type)
37
            ->setResultCode($resultCode)
38
            ->setRequestPayload(
39
                print_r($requestPayload, true)
40
            )
41
            ->setResponsePayload(
42
                print_r($responsePayload, true)
43
            );
44
45
        if ($this->isResponsePayloadCommunicationTokenExists($responsePayload)) {
46
            $callLog->setCommunicationToken($responsePayload->Decision->CommunicationToken);
47
        }
48
49
        $callLog->save();
50
    }
51
52
    /**
53
     * @param \stdClass $responsePayload
54
     *
55
     * @return bool
56
     */
57
    protected function isResponsePayloadCommunicationTokenExists(stdClass $responsePayload): bool
58
    {
59
        return property_exists($responsePayload, static::RESPONSE_DECISION)
60
            && property_exists($responsePayload->Decision, static::RESPONSE_COMMUNICATION_TOKEN);
61
    }
62
}
63