GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#35)
by Dwight
01:58
created

FeedbackService::openConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2.2559
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
use Exception;
6
use ZendService\Apple\Apns\Client\Feedback as Client;
7
use NotificationChannels\Apn\Exception\ConnectionFailed;
8
9
class FeedbackService
10
{
11
    /**
12
     * The feedback client instance.
13
     *
14
     * @var \ZendService\Apple\Apns\Client\Feedback
15
     */
16
    protected $client;
17
18
    /**
19
     * The connection environment.
20
     *
21
     * @var int
22
     */
23
    protected $environment;
24
25
    /**
26
     * The connection certificate.
27
     *
28
     * @var string
29
     */
30
    protected $certificate;
31
32
    /**
33
     * The connection pass phrase.
34
     *
35
     * @var stirng
36
     */
37
    protected $passPhrase;
38
39
    /**
40
     * Create feedback service instance.
41
     *
42
     * @param  \ZendService\Apple\Apns\Client\Feedback  $client
43
     * @param  string  $environment
44
     * @param  string  $certificate
45
     * @param  string|null  $passPhrase
46
     */
47 1
    public function __construct(Client $client, $environment, $certificate, $passPhrase = null)
48
    {
49 1
        $this->client = $client;
50 1
        $this->environment = $environment;
0 ignored issues
show
Documentation Bug introduced by
The property $environment was declared of type integer, but $environment is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
51 1
        $this->certificate = $certificate;
52 1
        $this->passPhrase = $passPhrase;
0 ignored issues
show
Documentation Bug introduced by
It seems like $passPhrase can also be of type string. However, the property $passPhrase is declared as type object<NotificationChannels\Apn\stirng>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
53 1
    }
54
55
    /**
56
     * Get feedback from the Apple Feedback Service about failed deliveries.
57
     *
58
     * @return array|ApnFeedback[]
59
     * @throws Exceptions\ConnectionFailed
60
     */
61 1
    public function get()
62
    {
63 1
        $this->openConnection();
64
65 1
        $feedback = $this->fetchFeedback();
66
67 1
        $this->client->close();
68
69 1
        return $feedback;
70
    }
71
72
    /**
73
     * Open the connection to the feedback service.
74
     *
75
     * @return void
76
     * @throws \NotificationChannels\Apn\Exception\ConnectionFailed
77
     */
78 1 View Code Duplication
    protected function openConnection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        try {
81 1
            $this->client->open($this->environment, $this->certificate, $this->passPhrase);
82
        } catch (Exception $exception) {
83
            throw ConnectionFailed::create($exception);
84
        }
85 1
    }
86
87
    /**
88
     * Fetch the feedback from APNS and collect our feedback object.
89
     *
90
     * @return array
91
     */
92 1
    protected function fetchFeedback()
93
    {
94 1
        $feedback = [];
95
96
        /** @var FeedbackResponse $response */
97 1
        foreach ($this->client->feedback() as $response) {
98 1
            $feedback[] = new ApnFeedback($response->getToken(), $response->getTime());
99
        }
100
101 1
        return $feedback;
102
    }
103
}
104