General::compileAsArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Request Provider Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AeSdk\Infrastructure\Provider\Request\Builder;
11
12
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\RequestDtoInterface as DtoInterface;
13
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\Builder\PublicBuilderInterface;
14
15
/**
16
 * Class General
17
 * @package Ticaje\AeSdk\Infrastructure\Provider\Request\Builder
18
 */
19
class General implements PublicBuilderInterface
20
{
21
    private $timeStamp;
22
23
    public function __construct()
24
    {
25
        $this->timeStamp = date("Y-m-d H:i:s");
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function compile(DtoInterface $dto): string
32
    {
33
        $result = '';
34
        $params = $this->compileAsArray($dto);
35
        array_walk($params, function ($value, $key) use (&$result) {
36
            $result .= "{$key}=$value&";
37
        });
38
        return $result;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function compileToSignature(DtoInterface $dto): string
45
    {
46
        $publicAsArray = $this->compileAsArray($dto);
47
        return $this->build($publicAsArray, $dto->getRequest());
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

47
        return $this->build($publicAsArray, $dto->/** @scrutinizer ignore-call */ getRequest());
Loading history...
48
    }
49
50
    /**
51
     * @param DtoInterface $dto
52
     * @return array
53
     */
54
    private function compileAsArray(DtoInterface $dto): array
55
    {
56
        return [
57
            'method' => $dto->getApiMethodName(),
0 ignored issues
show
Bug introduced by
The method getApiMethodName() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

57
            'method' => $dto->/** @scrutinizer ignore-call */ getApiMethodName(),
Loading history...
58
            'app_key' => $dto->getAppKey(),
0 ignored issues
show
Bug introduced by
The method getAppKey() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

58
            'app_key' => $dto->/** @scrutinizer ignore-call */ getAppKey(),
Loading history...
59
            'session' => $dto->getAccessToken(),
0 ignored issues
show
Bug introduced by
The method getAccessToken() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

59
            'session' => $dto->/** @scrutinizer ignore-call */ getAccessToken(),
Loading history...
60
            'timestamp' => $this->timeStamp,
61
            'format' => $dto->getResponseFormat(),
0 ignored issues
show
Bug introduced by
The method getResponseFormat() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

61
            'format' => $dto->/** @scrutinizer ignore-call */ getResponseFormat(),
Loading history...
62
            'v' => $dto->getApiVersion(),
0 ignored issues
show
Bug introduced by
The method getApiVersion() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

62
            'v' => $dto->/** @scrutinizer ignore-call */ getApiVersion(),
Loading history...
63
            'sign_method' => $dto->getSignMethod(),
0 ignored issues
show
Bug introduced by
The method getSignMethod() does not exist on Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. ( Ignorable by Annotation )

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

63
            'sign_method' => $dto->/** @scrutinizer ignore-call */ getSignMethod(),
Loading history...
64
        ];
65
    }
66
67
    /**
68
     * @param array $public
69
     * @param array $request
70
     * @return string
71
     */
72
    private function build(array $public, array $request): string
73
    {
74
        $params = array_merge($request, $public);
75
        ksort($params);
76
        $result = '';
77
        array_walk($params, function ($value, $key) use (&$result) {
78
            $result .= $key . $value;
79
        });
80
        return $result;
81
    }
82
}
83