Completed
Push — master ( a2bd00...ff1505 )
by Jean
02:44
created

CommandLineParameterValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
crap 12
1
<?php
2
/**
3
 * @author Jean Silva <[email protected]>
4
 * @license MIT
5
 */
6
namespace Jeancsil\FlightSpy\Validator;
7
8
use Jeancsil\FlightSpy\Command\Entity\Parameter;
9
use Symfony\Component\Console\Input\InputInterface;
10
11
class CommandLineParameterValidator implements ValidatorInterface
12
{
13
    /**
14
     * @var InputInterface
15
     */
16
    private $input;
17
18
    /**
19
     * @param $instance
20
     * @return $this
21
     */
22
    public function setTarget($instance)
23
    {
24
        if (!$instance instanceof InputInterface) {
25
            throw new \LogicException(
26
                sprintf('$instance must be instance of InputInterface. %s given', $instance)
27
            );
28
        }
29
30
        $this->input = $instance;
31
32
        return $this;
33
    }
34
35
    /**
36
     * @throw ValidationException
37
     */
38
    public function validate()
39
    {
40
        $configFile = $this->input->getOption(Parameter::FILE);
41
42
        if (!$configFile || !file_exists($configFile)) {
43
            throw new \InvalidArgumentException(sprintf('File not found: %s', $configFile));
44
        }
45
    }
46
}
47