CCPolicy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A ccDecision() 0 18 4
1
<?php
2
/**
3
 * Connections creating policy
4
 * User: moyo
5
 * Date: 2018/6/11
6
 * Time: 3:21 PM
7
 */
8
9
namespace Carno\Pool\Chips;
10
11
use Carno\Pool\Exceptions;
12
use Carno\Pool\Options;
13
14
trait CCPolicy
15
{
16
    use ESJudger;
17
18
    /**
19
     * @var int
20
     */
21
    private $swTimeouts = 0;
22
23
    /**
24
     * @param Options $options
25
     * @param string $identify
26
     * @param int $idle
27
     * @param int $busy
28
     * @param int $waits
29
     */
30
    protected function ccDecision(Options $options, string $identify, int $idle, int $busy, int $waits) : void
31
    {
32
        $current = Exceptions::happened($identify, Exceptions::SW_TIMEOUT);
33
34
        if ($current > $this->swTimeouts) {
35
            $increased = $current - $this->swTimeouts;
36
            $this->swTimeouts = $current;
37
        }
38
39
        $score = $waits / $options->getWaitQMax;
40
        $factor = (float) $options->scaleFactor;
41
        $threshold = $factor / (($increased ?? 0) + 1);
42
43
        if ($score < $threshold) {
44
            return;
45
        }
46
47
        ($target = $this->verdict($options, $idle, $busy)) && $this->resizing($target, 'policy-decision');
0 ignored issues
show
Bug introduced by
It seems like resizing() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        ($target = $this->verdict($options, $idle, $busy)) && $this->/** @scrutinizer ignore-call */ resizing($target, 'policy-decision');
Loading history...
48
    }
49
}
50