Rules   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 41
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A match() 0 15 4
1
<?php
2
3
namespace Recca0120\Twzipcode;
4
5
use Recca0120\Twzipcode\Storages\File;
6
use Recca0120\Twzipcode\Contracts\Storage;
7
8
class Rules
9
{
10
    /**
11
     * $storage.
12
     *
13
     * @var \Recca0120\Twzipcode\Contracts\Storage
14
     */
15
    protected $storage;
16
17
    /**
18
     * __construct.
19
     *
20
     * @param \Recca0120\Twzipcode\Contracts\Storage $storage
21
     */
22 9
    public function __construct(Storage $storage = null)
23
    {
24 9
        $this->storage = $storage ?: new File();
25 9
    }
26
27
    /**
28
     * match.
29
     *
30
     * @param string $address
31
     * @return string
32
     */
33 7
    public function match($address)
34
    {
35 7
        $address = is_a($address, Address::class) === true ? $address : new Address($address);
36 7
        $zip3 = $this->storage->zip3($address);
0 ignored issues
show
Bug introduced by
It seems like $address defined by is_a($address, \Recca012...pcode\Address($address) on line 35 can also be of type string; however, Recca0120\Twzipcode\Contracts\Storage::zip3() does only seem to accept object<Recca0120\Twzipcode\Address>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
37
38 7
        if (empty($zip3) === true) {
39
            return;
40
        }
41
42 7
        $rule = $this->storage->rules($zip3)->find(function ($rule) use ($address) {
0 ignored issues
show
Bug introduced by
The method find cannot be called on $this->storage->rules($zip3) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43 7
            return $rule->match($address);
44 7
        });
45
46 7
        return is_null($rule) === false ? $rule->zip5() : $zip3;
47
    }
48
}
49