XcodeLicenseErrorCatcherDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 14 3
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