ESJudger::verdict()   B
last analyzed

Complexity

Conditions 9
Paths 24

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 12
nc 24
nop 3
dl 0
loc 25
rs 8.0555
c 0
b 0
f 0
1
<?php
2
/**
3
 * Expand/Shrink judger
4
 * User: moyo
5
 * Date: 2018/6/11
6
 * Time: 4:08 PM
7
 */
8
9
namespace Carno\Pool\Chips;
10
11
use Carno\Pool\Options;
12
13
trait ESJudger
14
{
15
    /**
16
     * @param Options $options
17
     * @param int $idle
18
     * @param int $busy
19
     * @return int
20
     */
21
    protected function verdict(Options $options, int $idle, int $busy) : int
22
    {
23
        if ($options->maxIdle < $options->minIdle) {
24
            $options->maxIdle = $options->minIdle;
25
        }
26
27
        if ($idle === $options->minIdle || $idle === $options->maxIdle) {
28
            goto KEEPS;
29
        }
30
31
        if ($idle < $options->minIdle) {
32
            return min($busy + $options->minIdle, $options->overall);
33
        }
34
35
        if ($idle > $options->maxIdle) {
36
            return min($busy + $options->maxIdle, $options->overall);
37
        }
38
39
        KEEPS:
40
41
        if ($options->minIdle === 0) {
42
            return $busy ? $busy + $options->maxIdle : ($idle ? 0 : $options->initial);
43
        }
44
45
        return min($idle + $busy, $options->overall);
46
    }
47
}
48