XcodeLicenseErrorCatcherDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Dock\Installer\System\Catcher;
4
5
use Dock\IO\UserInteraction;
6
use SRIO\ChainOfResponsibility\ChainContext;
7
use SRIO\ChainOfResponsibility\ChainProcessInterface;
8
use Symfony\Component\Process\Exception\ProcessFailedException;
9
10
class XcodeLicenseErrorCatcherDecorator implements ChainProcessInterface
11
{
12
    /**
13
     * @var ChainProcessInterface
14
     */
15
    private $process;
16
17
    /**
18
     * @var UserInteraction
19
     */
20
    private $userInteraction;
21
22
    /**
23
     * @param UserInteraction       $userInteraction
24
     * @param ChainProcessInterface $process
25
     */
26
    public function __construct(UserInteraction $userInteraction, ChainProcessInterface $process)
27
    {
28
        $this->process = $process;
29
        $this->userInteraction = $userInteraction;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function execute(ChainContext $context)
36
    {
37
        try {
38
            $this->process->execute($context);
39
        } catch (ProcessFailedException $e) {
40
            $processOutput = $e->getProcess()->getOutput();
41
            if (strpos($processOutput, 'Agreeing to the Xcode/iOS license requires admin privileges, please re-run') !== false) {
42
                $this->userInteraction->writeTitle('You need to agree Xcode license.');
43
                $this->userInteraction->write('Run `xcode-select --install` to fix the problem and run this command again.');
44
45
                throw $e;
46
            }
47
        }
48
    }
49
}
50