Completed
Push — master ( 26115e...2315ce )
by Ronan
05:22
created

Grai::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 13
nc 5
nop 1
1
<?php
2
3
namespace IsoCodes;
4
5
/**
6
 * Class Grai for Global Returnable Asset Identifier, from GS1
7
 * Used for the management of reusable transport items, transport equipment, and tools.
8
 *
9
 * @link http://www.gs1.org/grai
10
 * @link http://www.gs1.org/docs/idkeys/GS1_GRAI_Executive_Summary.pdf
11
 * @link https://en.wikipedia.org/wiki/Global_Returnable_Asset_Identifier
12
 */
13
class Grai extends Gtin13 implements IsoCodeInterface
14
{
15
    /**
16
     * @param mixed $grai
17
     *
18
     * @return bool
19
     */
20
    public static function validate($grai)
21
    {
22
        if (strlen($grai) < 13) {
23
            return false;
24
        }
25
        $grai = self::unDecorate($grai);
26
        if (0 !== (int) $grai[0]) {
27
            return false;
28
        }
29
        $grai = substr($grai, 1, strlen($grai) - 1);
30
        if (strlen($grai) > 29) {
31
            return false;
32
        }
33
        $gtin13 = substr($grai, 0, 13);
34
        if (!ctype_alnum(substr($grai, 13, strlen($grai)))) {
35
            return false;
36
        }
37
38
        return parent::check($gtin13, 13); // optional serial component not to be checked
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (check() instead of validate()). Are you sure this is correct? If so, you might want to change this to $this->check().

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...
39
    }
40
}
41