CommandLineParameterValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 36
ccs 0
cts 17
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTarget() 0 12 2
A validate() 0 8 3
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