Completed
Push — master ( ef4007...299526 )
by Ronan
06:13
created

Iswc::validate()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 21
rs 9.0534
cc 4
eloc 12
nc 5
nop 1
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * Class Iswc for International Standard Musical Work Code (ISWC)
7
 * is a unique identifier for musical works, similar to ISBN. It is adopted as international standard ISO 15707.
8
 *
9
 * @link https://en.wikipedia.org/wiki/International_Standard_Musical_Work_Code
10
 * @link http://www.ismn-international.org/publications/newsletter10/othersys.html
11
 * @link http://jsfiddle.net/sN3TU/
12
 */
13
class Iswc extends Luhn implements IsoCodeInterface
14
{
15
    /**
16
     * @param mixed $iswc
17
     *
18
     * @return bool
19
     */
20
    public static function validate($iswc)
21
    {
22
        if (!((bool) preg_match('/^\s*T[\-.]?(\d)(\d)(\d)[\-.]?(\d)(\d)(\d)[\-.]?(\d)(\d)(\d)[\-.]?(\d)\s*$/i', $iswc))) {
23
            return false;
24
        }
25
        $hyphens = ['‐', '-', '.'];
26
        $iswc = parent::unDecorate($iswc, $hyphens);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (unDecorate() instead of validate()). Are you sure this is correct? If so, you might want to change this to $this->unDecorate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
27
28
        $sum = 1;
29
30
        for ($i = 1; $i <= 9; ++$i) {
31
            $sum = $sum + $i * (int) $iswc[$i];
32
        }
33
34
        $rem = $sum % 10;
35
        if ($rem !== 0) {
36
            $rem = 10 - $rem;
37
        }
38
39
        return (int) $iswc[10] === $rem;
40
    }
41
}
42