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 (#12)
by
unknown
02:31
created

Address::mustHaveAsAsciiString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace ShippoClient\Entity;
4
5
use TurmericSpice\Container;
6
use TurmericSpice\ReadableAttributes;
7
8
class Address extends ObjectInformation
9
{
10
    use ReadableAttributes {
11
        mayHaveAsString as public getZip;
12
        mayHaveAsString as public getCountry;
13
        mayHaveAsString as public getPhone;
14
        mayHaveAsString as public getEmail;
15
        mayHaveAsString as public getIp;
16
        mayHaveAsString as public getMetadata;
17
        mayHaveAsArray  as public getMessages;
18
    }
19
20
    public function getName()
21
    {
22
        return $this->mayHaveAsAsciiString('name');
23
    }
24
25
    public function getCompany()
26
    {
27
        return $this->mayHaveAsAsciiString('company');
28
    }
29
30
    public function getStreet1()
31
    {
32
        return $this->mayHaveAsAsciiString('street1');
33
    }
34
35
    public function getStreet2()
36
    {
37
        return $this->mayHaveAsAsciiString('street2');
38
    }
39
40
    public function getStreetNo()
41
    {
42
        return $this->mayHaveAsAsciiString('street_no');
43
    }
44
45
    public function getCity()
46
    {
47
        return $this->mayHaveAsAsciiString('city');
48
    }
49
50
    public function getState()
51
    {
52
        return $this->mayHaveAsAsciiString('state');
53
    }
54
55 View Code Duplication
    public function getIsResidential()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $is_residential = $this->attributes->mayHave('is_residential')->value();
0 ignored issues
show
Bug introduced by
The property attributes 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...
58
        if ($is_residential === null) {
59
            return null;
60
        }
61
62
        return (bool)$is_residential;
63
    }
64
65
    private function mayHaveAsAsciiString($propertyName, callable $validate = null)
66
    {
67
        return $this->transliterateToAscii(
68
            $this->attributes->mayHave($propertyName)->asString($validate)
69
        );
70
    }
71
72
    private function mustHaveAsAsciiString($propertyName, callable $validate = null)
73
    {
74
        return $this->transliterateToAscii(
75
            $this->attributes->mustHave($propertyName)->asString($validate)
76
        );
77
    }
78
79
    private function transliterateToAscii($str)
80
    {
81
        $ret = '';
82
        foreach (preg_split('//u', $str) as $ch) {
83
            $ch = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $ch);
84
            if (strlen($ch) > 1) {
85
                $ch = preg_replace('/[^0-9A-Za-z]/', '', $ch);
86
            }
87
            $ret .= $ch;
88
        }
89
        return $ret;
90
    }
91
}
92