AbstractApiCall   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildJsonRequestFromTransferObject() 0 5 1
A logApiException() 0 5 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\Zed\AfterPay\Business\Api\Adapter\ApiCall;
9
10
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
11
use Spryker\Shared\Log\LoggerTrait;
12
use SprykerEco\Zed\AfterPay\Business\Exception\ApiHttpRequestException;
13
14
class AbstractApiCall
15
{
16
    use LoggerTrait;
17
18
    /**
19
     * @var \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Converter\TransferToCamelCaseArrayConverterInterface
20
     */
21
    protected $transferConverter;
22
23
    /**
24
     * @var \SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilEncodingServiceInterface
25
     */
26
    protected $utilEncoding;
27
28
    /**
29
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $requestTransfer
30
     *
31
     * @return string
32
     */
33
    protected function buildJsonRequestFromTransferObject(AbstractTransfer $requestTransfer): string
34
    {
35
        $requestArray = $this->transferConverter->convert($requestTransfer);
36
37
        return $this->utilEncoding->encodeJson($requestArray);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->utilEncodi...codeJson($requestArray) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
38
    }
39
40
    /**
41
     * @param \SprykerEco\Zed\AfterPay\Business\Exception\ApiHttpRequestException $apiHttpRequestException
42
     *
43
     * @return void
44
     */
45
    protected function logApiException(ApiHttpRequestException $apiHttpRequestException): void
46
    {
47
        $this->getLogger()->error(
48
            $apiHttpRequestException->getDetailedMessage(),
49
            ['exception' => $apiHttpRequestException],
50
        );
51
    }
52
}
53