Passed
Push — master ( 3d849e...cbcce5 )
by
unknown
01:06 queued 12s
created

ZipCode::setValue()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 16
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Talentify\ValueObject\Geography\Address\ByCountry\Us;
6
7
use Talentify\ValueObject\Geography\Address\PostalCode;
8
use Talentify\ValueObject\StringUtils;
9
10
/**
11
 * @see https://en.wikipedia.org/wiki/ZIP_Code
12
 */
13
class ZipCode extends PostalCode
14
{
15
    public function setValue(string $value): void
16
    {
17
        $value = StringUtils::trimSpacesWisely($value);
18
        $changedValue = StringUtils::removeNonWordCharacters($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $value of Talentify\ValueObject\St...moveNonWordCharacters() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
        $changedValue = StringUtils::removeNonWordCharacters(/** @scrutinizer ignore-type */ $value);
Loading history...
19
        $characters = StringUtils::countCharacters($changedValue);
20
21
        if ($characters == 4) {
22
            $value = '0' . $value;
23
            $characters++;
24
        }
25
26
        if (empty($value) || $characters != 5 && $characters != 9) {
27
            throw new \InvalidArgumentException(sprintf('The value "%s" is not a valid postal code.', $value));
28
        }
29
30
        parent::setValue($value);
31
    }
32
}
33