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 (#4)
by Choraimy
06:30
created

Pushwoosh::getApplicationCode()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace NotificationChannels\Pushwoosh;
4
5
use GuzzleHttp\ClientInterface;
6
use GuzzleHttp\Exception\GuzzleException;
7
use GuzzleHttp\Psr7\Request;
8
use NotificationChannels\Pushwoosh\Exceptions\PushwooshException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, NotificationChannels\Pushwoosh\PushwooshException. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type NotificationChannels\Pus...ions\PushwooshException 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...
9
10
class Pushwoosh
11
{
12
    protected $application;
13
    protected $client;
14
    protected $token;
15
16
    /**
17
     * Create a new Pushwoosh API client.
18
     *
19
     * @param \GuzzleHttp\ClientInterface $client
20
     * @param string $application
21
     * @param string $token
22
     * @return void
23
     */
24 45
    public function __construct(ClientInterface $client, string $application, string $token)
25
    {
26 45
        $this->application = $application;
27 45
        $this->client = $client;
28 45
        $this->token = $token;
29 45
    }
30
31
    /**
32
     * Create the given message in the Pushwoosh API.
33
     *
34
     * @param \NotificationChannels\Pushwoosh\PushwooshPendingMessage $message
35
     * @return string[]
36
     */
37 45
    public function createMessage(PushwooshPendingMessage $message)
38
    {
39 45
        $headers = ['Accept' => 'application/json', 'Content-Type' => 'application/json'];
40 45
        $payload = \GuzzleHttp\json_encode(['request' => $message]);
41 45
        $request = new Request('POST', 'https://cp.pushwoosh.com/json/1.3/createMessage', $headers, $payload);
42
43
        try {
44 45
            $response = $this->client->send($request);
45
        } catch (GuzzleException $exception) {
46
            throw PushwooshException::failedTransmission($exception);
47
        }
48
49 45
        $response = \GuzzleHttp\json_decode($response->getBody()->getContents());
50
51 45
        if (isset($response->status_code) && $response->status_code !== 200) {
52 15
            throw PushwooshException::apiError($response);
53
        }
54
55 30
        if (isset($response->response->UnknownDevices)) {
56 15
            throw PushwooshException::unknownDevices($response);
57
        }
58
59 15
        $message->wasSent();
60
61 15
        if (isset($response->response->Messages)) {
62
            # Pushwoosh will not assign IDs to messages sent to less than 10 unique devices
63 4
            return array_map(function (string $identifier) {
64 15
                return $identifier !== 'CODE_NOT_AVAILABLE' ? $identifier : null;
65 15
            }, $response->response->Messages);
66
        }
67
68
        return [];
69
    }
70
71
    /**
72
     * Get the Pushwoosh API token.
73
     *
74
     * @return string
75
     */
76 45
    public function getApiToken()
77
    {
78 45
        return $this->token;
79
    }
80
81
    /**
82
     * Get the Pushwoosh application code.
83
     *
84
     * @return string
85
     */
86 45
    public function getApplicationCode()
87
    {
88 45
        return $this->application;
89
    }
90
91
    /**
92
     * Send the message.
93
     *
94
     * @param \NotificationChannels\Pushwoosh\PushwooshMessage $message
95
     * @return \NotificationChannels\Pushwoosh\PushwooshPendingMessage
96
     */
97
    public function send(PushwooshMessage $message)
98
    {
99
        return (new PushwooshPendingMessage($this))->queue($message);
100
    }
101
}
102