DropAnomaly   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 14 3
A __construct() 0 4 1
1
<?php
2
3
namespace Phperf\Pipeline\Vector;
4
5
class DropAnomaly implements VectorProcessor
6
{
7
    private $deviation;
8
    private $prevValue;
9
    /** @var VectorProcessor */
10
    private $processor;
11
12
    public function __construct($deviation = 0.5)
13
    {
14
        $this->deviation = $deviation;
15
        $this->processor = new MovingAverage(6);
16
    }
17
18
    public function value($value)
19
    {
20
        if (null !== $this->prevValue) {
21
            $delta = abs($value - $this->prevValue);
22
            $allowedDelta = abs($this->deviation * $this->prevValue);
23
            if ($delta > $allowedDelta) {
24
                return null;
25
            } else {
26
                $this->prevValue = $this->processor->value($value);
27
                return $value;
28
            }
29
        } else {
30
            $this->prevValue = $this->processor->value($value);
31
            return $value;
32
        }
33
    }
34
}