Counter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A appendCount() 0 7 2
A sendCount() 0 9 1
1
<?php
2
/*
3
 * This file is part of the phpflo/phpflo package.
4
 *
5
 * (c) Henri Bergius <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PhpFlo\Component;
12
13
use PhpFlo\Component;
14
15
/**
16
 * Class Counter
17
 *
18
 * @package PhpFlo\Component
19
 * @author Henri Bergius <[email protected]>
20
 */
21
class Counter extends Component
22
{
23
    /**
24
     * @var null
25
     */
26
    private $count;
27
28
    public function __construct()
29
    {
30
        $this->inPorts()->add('in', ['datatype' => 'bang']);
31
        $this->outPorts()->add('count', ['datatype' => 'int']);
32
33
        $this->inPorts()->in->on('data', [$this, 'appendCount']);
34
        $this->inPorts()->in->on('disconnect', [$this, 'sendCount']);
35
36
        $this->count = null;
37
    }
38
39
    /**
40
     * @param int|null $data
41
     */
42
    public function appendCount($data)
43
    {
44
        if (is_null($this->count)) {
45
            $this->count = 0;
0 ignored issues
show
Documentation Bug introduced by
It seems like 0 of type integer is incompatible with the declared type null of property $count.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        }
47
        $this->count++;
48
    }
49
50
    public function sendCount()
51
    {
52
        $this->outPorts()
53
            ->count
54
            ->send($this->count)
55
            ->disconnect();
56
57
        $this->count = null;
58
    }
59
}
60