PreImage::compare()   A
last analyzed

Complexity

Conditions 4
Paths 4

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 4
nc 4
nop 2
1
<?php
2
/**
3
 * This file is part of PHP-Yacc package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace PhpYacc\Compress;
11
12
/**
13
 * Class PreImage.
14
 */
15
class PreImage
16
{
17
    /**
18
     * @var int
19
     */
20
    public $index = 0;
21
22
    /**
23
     * @var array
24
     */
25
    public $classes = [];
26
27
    /**
28
     * @var int
29
     */
30
    public $length = 0;
31
32
    /**
33
     * PreImage constructor.
34
     *
35
     * @param int $index
36
     */
37
    public function __construct(int $index)
38
    {
39
        $this->index = $index;
40
    }
41
42
    /**
43
     * @param PreImage $x
44
     * @param PreImage $y
45
     *
46
     * @return int
47
     */
48
    public static function compare(self $x, self $y): int
49
    {
50
        if ($x->length !== $y->length) {
51
            return $x->length - $y->length;
52
        }
53
54
        foreach ($x->classes as $key => $value) {
55
            if ($value !== $y->classes[$key]) {
56
                return $value - $y->classes[$key];
57
            }
58
        }
59
60
        return 0;
61
    }
62
}
63