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
Push — master ( e87f76...5c1085 )
by Tyler
02:08
created

SMSHandler::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 19
ccs 12
cts 13
cp 0.9231
rs 9.4285
cc 3
eloc 12
nc 3
nop 10
crap 3.004

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Tylercd100\Monolog\Handler;
4
5
use Exception;
6
use Monolog\Handler\SocketHandler;
7
use Monolog\Logger;
8
use Tylercd100\Monolog\Formatter\SMSFormatter;
9
10
abstract class SMSHandler extends SocketHandler
11
{
12
13
    /**
14
     * @var string
15
     */
16
    protected $authToken;
17
18
    /**
19
     * @var string
20
     */
21
    protected $authId;
22
23
    /**
24
     * @var string
25
     */
26
    protected $fromNumber;
27
28
    /**
29
     * @var string
30
     */
31
    protected $toNumber;
32
33
    /**
34
     * @var string
35
     */
36
    protected $host;
37
38
    /**
39
     * @var string
40
     */
41
    protected $version;
42
43
    /**
44
     * @param string $authToken  Plivo API Auth Token
45
     * @param string $authId     Plivo API Auth ID
46
     * @param string $fromNumber The phone number that will be shown as the sender ID
47
     * @param string $toNumber   The phone number to which the message will be sent
48
     * @param int    $level      The minimum logging level at which this handler will be triggered
49
     * @param bool   $bubble     Whether the messages that are handled can bubble up the stack or not
50
     * @param bool   $useSSL     Whether to connect via SSL.
51
     * @param string $host       The Plivo server hostname.
52
     * @param string $version    The Plivo API version (default PlivoHandler::API_V1)
53
     * @param string $limit      The character limit
54
     */
55 30
    public function __construct($authToken, $authId, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = null, $limit = 160)
56
    {
57
58 30
        if(empty($version)){
59
            throw new Exception('API Version is empty');
60
        }
61
62 30
        $connectionString = $useSSL ? 'ssl://'.$host.':443' : $host.':80';
63 30
        parent::__construct($connectionString, $level, $bubble);
64
65 30
        $this->authToken  = $authToken;
66 30
        $this->authId     = $authId;
67 30
        $this->fromNumber = $fromNumber;
68 30
        $this->toNumber   = $toNumber;
69 30
        $this->host       = $host;
70 30
        $this->version    = $version;
71 30
        $this->limit      = $limit;
0 ignored issues
show
Bug introduced by
The property limit does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
72
73 30
    }
74
75
    /**
76
     * {@inheritdoc}
77
     *
78
     * @param  array  $record
79
     * @return string
80
     */
81 24
    protected function generateDataStream($record)
82
    {
83 24
        $content = $this->buildContent($record);
84 24
        return $this->buildHeader($content) . $content;
85
    }
86
87
    /**
88
     * Builds the body of API call
89
     *
90
     * @param  array  $record
91
     * @return string
92
     */
93
    abstract protected function buildContent($record);
94
95
    /**
96
     * Builds the URL for the API call
97
     * 
98
     * @return string
99
     */
100
    abstract protected function buildRequestUrl();
101
102
    /**
103
     * Builds the header of the API call
104
     *
105
     * @param  string $content
106
     * @return string
107
     */
108 24
    private function buildHeader($content)
109
    {
110 24
        $auth = base64_encode($this->authId.":".$this->authToken);
111
112 24
        $header = $this->buildRequestUrl();
113
114 24
        $header .= "Host: {$this->host}\r\n";
115 24
        $header .= "Authorization: Basic ".$auth."\r\n";;
116 24
        $header .= "Content-Type: application/json\r\n";
117 24
        $header .= "Content-Length: " . strlen($content) . "\r\n";
118 24
        $header .= "\r\n";
119 24
        return $header;
120
    }
121
122
123
124
    /**
125
     * {@inheritdoc}
126
     *
127
     * @param array $record
128
     */
129 24
    protected function write(array $record)
130
    {
131 24
        parent::write($record);
132 24
        $this->closeSocket();
133 24
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 6
    protected function getDefaultFormatter()
139
    {
140 6
        return new SMSFormatter();
141
    }
142
}