Sms::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Shrikeh\PagerDuty\Entity\ContactMethod\Resource;
4
5
use Shrikeh\PagerDuty\Entity\ContactMethod\Resource;
6
use Shrikeh\PagerDuty\Entity\ContactMethod\Resource\Blacklisted;
7
use Shrikeh\PagerDuty\Entity\ContactMethod\Resource\Blacklistable;
8
use Shrikeh\PagerDuty\Entity\ContactMethod\Resource\Type;
9
10
final class Sms implements Resource, Blacklistable
11
{
12
    use Type;
13
    use Blacklisted;
14
15
    private $countryCode;
16
17
    private $number;
18
19
    public function __construct(
20
        $number,
21
        $countryCode,
22
        $enabled,
23
        $blacklisted = false
24
    ) {
25
        $this->number = $number;
26
        $this->countryCode = $countryCode;
27
        $this->enabled = $enabled;
0 ignored issues
show
Bug introduced by
The property enabled 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...
28
        $this->blacklisted = $blacklisted;
29
    }
30
31
    public function __toString()
32
    {
33
        return $this->render();
34
    }
35
36
    public function countryCode()
37
    {
38
        return $this->countryCode;
39
    }
40
41
    public function number()
42
    {
43
        return $this->number;
44
    }
45
46
    public function enabled()
47
    {
48
        return $this->enabled;
49
    }
50
51
    public function render($prependCountryCode = true)
52
    {
53
        if ($prependCountryCode) {
54
            return sprintf('+%d%d', $this->countryCode, $this->number);
55
        }
56
        return $this->number;
57
    }
58
}
59