InteractiveProcessManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 61
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A enableOutput() 0 9 2
A setProcess() 0 4 1
A run() 0 4 1
A __construct() 0 4 1
A disableOutput() 0 4 1
1
<?php
2
3
namespace Dock\IO\Process;
4
5
use Dock\IO\Process\Pipe\NullPipe;
6
use Dock\IO\Process\Pipe\UserInteractionPipe;
7
use Dock\IO\UserInteraction;
8
9
class InteractiveProcessManager
10
{
11
    /**
12
     * @var InteractiveProcess
13
     */
14
    private $process;
15
16
    /**
17
     * @var UserInteraction
18
     */
19
    private $userInteraction;
20
21
    /**
22
     * @param UserInteraction $userInteraction
23
     */
24
    public function __construct(UserInteraction $userInteraction)
25
    {
26
        $this->userInteraction = $userInteraction;
27
    }
28
29
    /**
30
     * Attach a process.
31
     *
32
     * @param InteractiveProcess $process
33
     */
34
    public function setProcess(InteractiveProcess $process)
35
    {
36
        $this->process = $process;
37
    }
38
39
    /**
40
     * Disable the process output.
41
     */
42
    public function disableOutput()
43
    {
44
        $this->process->updatePipe(new NullPipe());
45
    }
46
47
    /**
48
     * Enable the process output.
49
     *
50
     * @param bool $retroActive
51
     */
52
    public function enableOutput($retroActive = false)
53
    {
54
        $pipe = new UserInteractionPipe($this->userInteraction);
55
        if ($retroActive) {
56
            $pipe->rewind($this->process);
57
        }
58
59
        $this->process->updatePipe($pipe);
60
    }
61
62
    /**
63
     * Run the given process.
64
     */
65
    public function run()
66
    {
67
        $this->process->run();
68
    }
69
}
70