Completed
Push — master ( 526d6e...2376dc )
by Akihito
03:04
created

Map::isProcessing()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.2
cc 4
eloc 6
nc 3
nop 0
1
<?php
2
namespace Ackintosh\Snidel;
3
4
use Ackintosh\Snidel\Token;
5
6
7
class Map
8
{
9
    /** @var Snidel\Token */
10
    private $token;
11
12
    /** @var callable */
13
    private $callable;
14
15
    /** @var array */
16
    private $childPids = array();
17
18
    /** @var int */
19
    private $forkedCount = 0;
20
21
    /** @var int */
22
    private $completedCount = 0;
23
24
    /**
25
     * @param   callable    $callable
26
     * @param   int         $concurrency
27
     */
28
    public function __construct($callable, $concurrency)
29
    {
30
        $this->token = new Token(getmypid(), $concurrency);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Ackintosh\Snidel\To...tmypid(), $concurrency) of type object<Ackintosh\Snidel\Token> is incompatible with the declared type object<Ackintosh\Snidel\Snidel\Token> of property $token.

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...
31
        $this->callable = $callable;
32
    }
33
34
    /**
35
     * returns callable
36
     *
37
     * @return  callable
38
     */
39
    public function getCallable()
40
    {
41
        return $this->callable;
42
    }
43
44
    /**
45
     * returns token
46
     *
47
     * @return  Snidel\Token
48
     */
49
    public function getToken()
50
    {
51
        return $this->token;
52
    }
53
54
    /**
55
     * stacks child Pid
56
     *
57
     * @param   int     $childPid
58
     * @return  void
59
     */
60
    public function addChildPid($childPid)
61
    {
62
        $this->childPids[] = $childPid;
63
    }
64
65
    /**
66
     * returns array of child pid
67
     *
68
     * @return  int[]
69
     */
70
    public function getChildPids()
71
    {
72
        return $this->childPids;
73
    }
74
75
    /**
76
     * has child pid or not
77
     *
78
     * @param   int     $childPid
79
     * @return  bool
80
     */
81
    public function hasChild($childPid)
82
    {
83
        return in_array($childPid, $this->childPids, true);
84
    }
85
86
    /**
87
     * count up the number of forked
88
     *
89
     * @return  void
90
     */
91
    public function countTheForked()
92
    {
93
        $this->forkedCount++;
94
    }
95
96
    /**
97
     * count up the number of completed
98
     *
99
     * @return  void
100
     */
101
    public function countTheCompleted()
102
    {
103
        $this->completedCount++;
104
    }
105
106
    /**
107
     * at that time processing its function or not
108
     *
109
     * @return bool
110
     */
111
    public function isProcessing()
112
    {
113
        if ($this->forkedCount === 0 || $this->completedCount === 0) {
114
            return true;
115
        }
116
117
        if ($this->forkedCount === $this->completedCount) {
118
            return false;
119
        }
120
121
        return true;
122
    }
123
}
124