AddressAwareTrait::setAddress()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace Germania\Addresses;
3
4
trait AddressAwareTrait
5
{
6
    use AddressProviderTrait;
7
8
9
    /**
10
     * @param AddressProviderInterface|null $address
11
     */
12 4
    public function setAddress(?AddressProviderInterface $address)
13
    {
14 4
        if ($address instanceof AddressInterface):
15 2
            $this->address = $address; 
16
        else:
17 2
            $this->address = $address->getAddress();
0 ignored issues
show
Bug introduced by
It seems like $address is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
18
        endif;
19
20 4
        return $this;
21
    }
22
}
23