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.

Search   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 21
c 1
b 0
f 0
dl 0
loc 78
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A connect() 0 11 2
A suggest() 0 15 3
A query() 0 15 3
1
<?php
2
3
namespace Psonic;
4
5
6
use Psonic\Channels\Channel;
7
use Psonic\Contracts\Client;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Psonic\Client. 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...
8
use Psonic\Commands\Search\QueryCommand;
9
use Psonic\Commands\Search\SuggestCommand;
10
use Psonic\Exceptions\CommandFailedException;
11
use Psonic\Commands\Search\StartSearchChannelCommand;
12
13
class Search extends Channel
14
{
15
    /**
16
     * Search Channel constructor.
17
     * @param Client $client
18
     */
19
    public function __construct(Client $client)
20
    {
21
        parent::__construct($client);
22
    }
23
24
    /**
25
     * @return mixed|Contracts\Response|void
26
     * @throws Exceptions\ConnectionException
27
     */
28
    public function connect($password = 'SecretPassword')
29
    {
30
        parent::connect();
31
32
        $response = $this->send(new StartSearchChannelCommand($password));
33
34
        if ($bufferSize = $response->get('bufferSize')) {
35
            $this->bufferSize = (int)$bufferSize;
36
        }
37
38
        return $response;
39
    }
40
41
    /**
42
     * @param $collection
43
     * @param $bucket
44
     * @param $terms
45
     * @param $limit
46
     * @param $offset
47
     * @param $locale
48
     * @return array
49
     * @throws CommandFailedException
50
     */
51
    public function query($collection, $bucket, $terms, $limit = null, $offset = null, $locale = null): array
52
    {
53
        $response = $this->send(new QueryCommand($collection, $bucket, $terms, $limit, $offset, $locale));
54
55
        if (!$response->getStatus() == 'PENDING') {
56
            throw new CommandFailedException;
57
        }
58
59
        $results = $this->read();
60
61
        if (!$results->getStatus() == 'EVENT') {
62
            throw new CommandFailedException;
63
        }
64
65
        return $results->getResults();
0 ignored issues
show
Bug introduced by
The method getResults() does not exist on Psonic\Contracts\Response. Since it exists in all sub-types, consider adding an abstract or default implementation to Psonic\Contracts\Response. ( Ignorable by Annotation )

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

65
        return $results->/** @scrutinizer ignore-call */ getResults();
Loading history...
66
    }
67
68
    /**
69
     * @param $collection
70
     * @param $bucket
71
     * @param $terms
72
     * @param $limit
73
     * @return array
74
     * @throws CommandFailedException
75
     */
76
    public function suggest($collection, $bucket, $terms, $limit = null): array
77
    {
78
        $response = $this->send(new SuggestCommand($collection, $bucket, $terms, $limit));
79
80
        if (!$response->getStatus() == 'PENDING') {
81
            throw new CommandFailedException;
82
        }
83
84
        $results = $this->read();
85
86
        if (!$results->getStatus() == 'EVENT') {
87
            throw new CommandFailedException;
88
        }
89
90
        return $results->getResults();
91
    }
92
}
93