Test Failed
Pull Request — master (#10)
by Alice
01:55
created

ManagerThread   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethodName() 0 3 1
A getDependencies() 0 3 1
A __construct() 0 4 1
A process() 0 12 2
1
<?php
2
3
namespace Wonderland\Thread\Example\SelfManaging;
4
5
6
use Wonderland\Thread\AbstractThread;
7
use Wonderland\Thread\ThreadPool;
8
9
class ManagerThread extends AbstractThread
10
{
11
    /**
12
     * @var array
13
     */
14
    private $dependencies = [];
15
16
    public function __construct(string $processName, array $dependencies)
17
    {
18
        $this->dependencies = $dependencies;
19
        parent::__construct($processName);
20
    }
21
22
    /**
23
     * Return the name of the method to process during the thread
24
     *
25
     * @return string
26
     */
27
    protected function getMethodName(): string
28
    {
29
        return 'process';
30
    }
31
32
    /**
33
     * Return the list of dependencies that will be passed as parameters of the method referenced by getMethodName
34
     *
35
     * @return array
36
     */
37
    protected function getDependencies(): array
38
    {
39
        return $this->dependencies;
40
    }
41
42
    /**
43
     * @param string     $processName
44
     * @param ThreadPool $pool
45
     * @return int
46
     */
47
    public function process(string $processName, ThreadPool &$pool)
48
    {
49
        for ($i = 0; $i < 10; $i++) {
50
            $pool->addLiveThread(new TestThread($processName . '_' . $i, []));
51
            echo "Added Thread " . $i . PHP_EOL;
52
//            echo count($pool->getRunningThreads()) . PHP_EOL;
53
            sleep(1);
54
        }
55
56
        echo '== end Manage Thread ==' . PHP_EOL;
57
58
        return self::EXIT_STATUS_SUCCESS;
59
    }
60
}