Completed
Pull Request — master (#10)
by Alice
03:35
created

ManagerThread::getMethodName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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->addThread(new TestThread($processName . '_' . $i, []));
51
            sleep(1);
52
        }
53
54
        echo '== end Manage Thread ==' . PHP_EOL;
55
56
        return self::EXIT_STATUS_SUCCESS;
57
    }
58
}