Passed
Push — master ( 5b31c8...ce99ce )
by AHMED JOHARI
02:52
created

AbstractConnector::setConnectorId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace Joesama\Webhook\Connectors;
3
4
use GuzzleHttp\Exception\BadResponseException;
5
use GuzzleHttp\Exception\TransferException;
6
use GuzzleHttp\Psr7\Response;
7
use GuzzleHttp\RequestOptions;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
abstract class AbstractConnector
12
{
13
    /**
14
     * Web Hook connector id.
15
     *
16
     * @var string
17
     */
18
    private $webHookConnectorId;
19
20
    /**
21
     * Define request content type.
22
     *
23
     * @return string
24
     */
25 1
    public function webHookContentType(): string
26
    {
27 1
        return RequestOptions::JSON;
28
    }
29
30
    /**
31
     * Define additional handling HTTP request response.
32
     *
33
     * @param ResponseInterface $response
34
     * @param RequestInterface  $request
35
     * @return mixed
36
     */
37
    public function webHookResponse(ResponseInterface $response, RequestInterface $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

37
    public function webHookResponse(ResponseInterface $response, /** @scrutinizer ignore-unused */ RequestInterface $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $responseContent = $response->getBody()->getContents();
40
        
41
        if (($jsonResponse = json_decode($responseContent, true)) === null) {
42
            return $responseContent;
43
        }
44
45
        return $jsonResponse;
46
    }
47
48
    /**
49
     * Define additional handling for exceptions.
50
     *
51
     * @param TransferException $exception
52
     * @param RequestInterface  $request
53
     * @return mixed
54
     */
55
    public function webHookException(TransferException $exception, RequestInterface $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

55
    public function webHookException(TransferException $exception, /** @scrutinizer ignore-unused */ RequestInterface $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        if ($exception instanceof BadResponseException) {
58
            $response = new Response(
59
                $exception->getResponse()->getStatusCode(),
60
                $exception->getResponse()->getHeaders(),
61
                $exception->getResponse()->getBody()->getContents(),
62
                $exception->getResponse()->getProtocolVersion(),
63
                $exception->getResponse()->getReasonPhrase()
64
            );
65
        } else {
66
            $response = new Response(500, [], $exception->getMessage());
67
        }
68
69
        return $response;
70
    }
71
72
    /**
73
     * Save data to data storage.
74
     *
75
     * @param array $logData
76
     * @return void
77
     */
78
    public function webHookSavingData(array $logData): void
0 ignored issues
show
Unused Code introduced by
The parameter $logData is not used and could be removed. ( Ignorable by Annotation )

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

78
    public function webHookSavingData(/** @scrutinizer ignore-unused */ array $logData): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        //@TODO: Implement saving logic here..
81
    }
82
83
    /**
84
     * Set connector id.
85
     *
86
     * @param string $connectorId
87
     */
88 1
    public function setConnectorId(string $connectorId): void
89
    {
90 1
        $this->webHookConnectorId = $connectorId;
91 1
    }
92
93
    /**
94
     * Set connector id.
95
     *
96
     * @return string|null
97
     */
98 1
    public function getConnectorId(): ?string
99
    {
100 1
        return $this->webHookConnectorId;
101
    }
102
}
103