Check::execute()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 0
cts 18
cp 0
rs 8.9713
cc 3
eloc 14
nc 4
nop 2
crap 12
1
<?php
2
/**
3
 * @author     Chris Hilsdon <[email protected]>
4
 * @package    ComodoDecodeCSR
5
 * @copyright  2016 Xigen
6
 * @license    GNU General Public License v3
7
 * @link       https://github.com/XigenChris/ComodoDecodeCSR
8
 */
9
10
namespace Xigen\Console;
11
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Xigen\ComodoDecodeCSR;
16
use Xigen\Exception;
17
18
class Check extends BaseCommand
19
{
20
    protected function configure()
21
    {
22
        $this
23
            ->setName("check")
24
            ->setDescription("Check if a domain will pass the DVC")
25
            ->addArgument(
26
                'csr',
27
                InputArgument::REQUIRED,
28
                'Location of csr file for this domain'
29
            )
30
        ;
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $comodoDecodeCSR = new ComodoDecodeCSR();
36
37
        try {
38
            $comodoDecodeCSR->setCSR($this->loadCSR($input, $output));
39
            $comodoDecodeCSR->fetchHashes();
40
        } catch (Exception $e) {
41
            $output->writeln('<error>Error!</error>');
42
            $output->writeln('Invalid CSR');
43
44
            return 3;
45
        }
46
47
        if ($comodoDecodeCSR->checkInstalled()) {
48
            $output->writeln('<info>Success!</info> This domain should pass DVC');
49
50
            return 0;
51
        }
52
53
        $output->writeln('<error>Fail!</error> There is something wrong with the validation file');
54
55
        return 2;
56
    }
57
}
58