SimotelApi::call()   A
last analyzed

Complexity

Conditions 3
Paths 6

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 18
rs 9.7998
1
<?php
2
3
namespace Hsy\SimotelConnect;
4
5
6
use Illuminate\Support\Facades\Http;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Http 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...
7
8
class SimotelApi
9
{
10
    private $message = "";
11
12
    private function call($query)
13
    {
14
        $user = config("simotel.simotelApi.user");
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

14
        $user = /** @scrutinizer ignore-call */ config("simotel.simotelApi.user");
Loading history...
15
        $pass = config("simotel.simotelApi.pass");
16
        $apiServer = config("simotel.simotelApi.apiUrl");
17
18
        try {
19
            $endpoint = $apiServer . "/" . $query;
20
            $response = Http::withBasicAuth($user, $pass)->post($endpoint);
21
            $res = $response->json();
22
            $this->message = $res["message"];
23
            if ($res["ok"] == 1)
24
                return true;
25
            return false;
26
27
        } catch (\Exception $e) {
28
            $this->message = $e->getMessage();
29
            return false;
30
        }
31
32
    }
33
34
    public function getMessage()
35
    {
36
        return $this->message;
37
    }
38
39
    public function addToQueue($queue, $source, $agent, $penalty = 0)
40
    {
41
        $query = "queue/add/?queue={$queue}&source={$source}&agent={$agent}&penalty={$penalty}";
42
        return $this->call($query);
43
    }
44
45
    public function removeFromQueue($queue, $agent)
46
    {
47
        $query = "/queue/remove/?queue={$queue}&agent={$agent}";
48
        return $this->call($query);
49
    }
50
51
    public function pauseInQueue($queue, $agent)
52
    {
53
        $query = "/queue/pause/?queue={$queue}&agent={$agent}";
54
        return $this->call($query);
55
    }
56
57
    public function resumeInQueue($queue, $agent)
58
    {
59
        $query = "/queue/resume/?queue={$queue}&agent={$agent}";
60
        return $this->call($query);
61
    }
62
}
63