Completed
Push — master ( a7385b...36e950 )
by Ronan
23s queued 11s
created

Uid::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * Class Uid:
7
 * Switzerland Business Orgs VAT Number (UID) Validation
8
 * Business Identification Number (BID) or Unternehmens-Identifikationsnummer (UID).
9
 *
10
 * @see https://vatstack.com/articles/switzerland-vat-number-validation
11
 * @see https://www.estv.admin.ch/estv/fr/home/mehrwertsteuer/fachinformationen/steuerpflicht/unternehmens-identifikationsnummer--uid-.html
12
 * @see https://www.ech.ch/de/dokument/57be808d-9a03-4e9e-a2c5-65f08ca78e44
13
 */
14
class Uid implements IsoCodeInterface
15
{
16
    const HYPHENS = [' ', '.', '-', '—']; // regular dash, authentic hyphen (rare!) and space
17
18
    /**
19
     * @param mixed $uid - Swiss Business Identification Number
20
     *
21
     * @return bool
22
     */
23
    public static function validate($uid)
24
    {
25
        $multipliers = [5, 4, 3, 2, 7, 6, 5, 4];
26
        $result = 0;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
        $uid = Utils::unDecorate(strval($uid), self::HYPHENS);
28
29
        if (false !== strpos($uid, 'CHE', 0) || false !== strpos($uid, 'ADM', 0)) {
30
            $uid = substr(strval($uid), 3, 9);
31
        }
32
33
        $uid = substr($uid, 0, 9);
34
35
        return Utils::LuhnWithWeights($uid, 9, $multipliers, 11, self::HYPHENS);
36
    }
37
}
38