TRow::nhole()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 TRow.
14
 */
15
class TRow
16
{
17
    /**
18
     * @var int
19
     */
20
    public $index;
21
22
    /**
23
     * @var int
24
     */
25
    public $mini;
26
27
    /**
28
     * @var int
29
     */
30
    public $maxi;
31
32
    /**
33
     * @var int
34
     */
35
    public $nent;
36
37
    /**
38
     * TRow constructor.
39
     *
40
     * @param int $index
41
     */
42
    public function __construct(int $index)
43
    {
44
        $this->index = $index;
45
        $this->mini = -1;
46
        $this->maxi = 0;
47
        $this->nent = 0;
48
    }
49
50
    /**
51
     * @return int
52
     */
53
    public function span(): int
54
    {
55
        return $this->maxi - $this->mini;
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function nhole(): int
62
    {
63
        return $this->span() - $this->nent;
64
    }
65
66
    /**
67
     * @param TRow $a
68
     * @param TRow $b
69
     *
70
     * @return int
71
     */
72
    public static function compare(self $a, self $b): int
73
    {
74
        if ($a->nent !== $b->nent) {
75
            return $b->nent - $a->nent;
76
        }
77
        if ($a->span() !== $b->span()) {
78
            return $b->span() - $a->span();
79
        }
80
81
        return $a->mini - $b->mini;
82
    }
83
}
84