InteractiveProcess   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
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 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A updatePipe() 0 4 1
A updateWaitStrategy() 0 4 1
A run() 0 12 2
A getProcess() 0 4 1
1
<?php
2
3
namespace Dock\IO\Process;
4
5
use Dock\IO\Process\Pipe\Pipe;
6
use Dock\IO\Process\WaitStrategy\WaitStrategy;
7
use Symfony\Component\Process\Process;
8
9
class InteractiveProcess
10
{
11
    /**
12
     * @var Pipe
13
     */
14
    private $pipe;
15
    /**
16
     * @var WaitStrategy
17
     */
18
    private $waitStrategy;
19
    /**
20
     * @var Process
21
     */
22
    private $process;
23
24
    /**
25
     * @param Process      $process
26
     * @param Pipe         $pipe
27
     * @param WaitStrategy $waitStrategy
28
     */
29
    public function __construct(Process $process, Pipe $pipe, WaitStrategy $waitStrategy)
30
    {
31
        $this->pipe = $pipe;
32
        $this->waitStrategy = $waitStrategy;
33
        $this->process = $process;
34
    }
35
36
    /**
37
     * @param Pipe $pipe
38
     */
39
    public function updatePipe(Pipe $pipe)
40
    {
41
        $this->pipe = $pipe;
42
    }
43
44
    /**
45
     * @param WaitStrategy $waitStrategy
46
     */
47
    public function updateWaitStrategy(WaitStrategy $waitStrategy)
48
    {
49
        $this->waitStrategy = $waitStrategy;
50
    }
51
52
    /**
53
     * Run the process.
54
     */
55
    public function run()
56
    {
57
        $this->process->start(function ($type, $buffer) {
58
            if (Process::ERR === $type) {
59
                $this->pipe->error($buffer);
60
            } else {
61
                $this->pipe->output($buffer);
62
            }
63
        });
64
65
        $this->waitStrategy->wait($this->process);
66
    }
67
68
    /**
69
     * @return Process
70
     */
71
    public function getProcess()
72
    {
73
        return $this->process;
74
    }
75
}
76