Completed
Push — master ( eb9a89...bc6a95 )
by Greg
438:19 queued 421:28
created

RealtimeOutputHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 3 1
A handleOutput() 0 8 2
1
<?php
2
namespace Consolidation\SiteProcess\Util;
3
4
use Consolidation\SiteAlias\AliasRecord;
5
use Symfony\Component\Process\Process;
6
use Consolidation\Config\Util\Interpolator;
7
use Symfony\Component\Console\Input\OutputInterface;
8
9
/**
10
 * RealtimeOutput can be provided to a process object when you want
11
 * to display the output of the running command as it is being produced.
12
 */
13
class RealtimeOutputHandler
14
{
15
    protected $stdout;
16
    protected $stderr;
17
18
    /**
19
     * Provide the output streams to use for stdout and stderr
20
     */
21
    public function __construct(OutputInterface $stdout, OutputInterface $stderr)
22
    {
23
        $this->stdout = $stdout;
24
        $this->stderr = $stderr;
25
    }
26
27
    /**
28
     * This gives us an opportunity to adapt to the settings of the
29
     * process object (e.g. do we need to do anything differently if
30
     * it is in tty mode, etc.)
31
     */
32
    public function configure(Process $process)
0 ignored issues
show
Unused Code introduced by
The parameter $process is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
    }
35
36
    /**
37
     * Helper method when you want real-time output from a Process call.
38
     * @param string $type
39
     * @param string $buffer
40
     */
41
    public function handleOutput($type, $buffer)
42
    {
43
        if (Process::ERR === $type) {
44
            $this->stdout->write($buffer);
45
        } else {
46
            $this->stderr->write($buffer);
47
        }
48
    }
49
}
50