Completed
Push — develop ( 4146c2...e30e33 )
by Chris
35:42
created

CreateFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 88.46%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 0
cbo 4
dl 0
loc 45
ccs 23
cts 26
cp 0.8846
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
B execute() 0 29 3
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 CreateFile extends BaseCommand
19
{
20 3
    protected function configure()
21
    {
22 3
        $this
23 3
            ->setName("createfile")
24 3
            ->setDescription("Creates the file needed for DVC")
25 3
            ->addArgument(
26 3
                'csr',
27 3
                InputArgument::REQUIRED,
28
                'Location of csr file'
29 3
            )
30
        ;
31 3
    }
32
33 2
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 2
        $comodoDecodeCSR = new ComodoDecodeCSR();
36
37
        try {
38 2
            $comodoDecodeCSR->setCSR($this->loadCSR($input, $output));
39 2
        } catch (Exception $e) {
40 1
            $output->writeln('<error>Error!</error>');
41 1
            $output->writeln('Invalid CSR');
42
43 1
            return 3;
44
        }
45
46 1
        $hashes = $comodoDecodeCSR->fetchHashes();
47
48 1
        if (!$hashes) {
49
            $output->writeln('<error>Fail!</error>');
50
            $output->writeln('Unable to fetch hashes');
51
52
            return 2;
53
        }
54
55 1
        $output->writeln('<info>Filename:</info> ' . $hashes['md5'] . '.txt');
56 1
        $output->writeln('<info>Contents:</info>');
57 1
        $output->writeln($comodoDecodeCSR->generateDVC());
58 1
        $output->writeln('<info>URL:</info> http://' . $comodoDecodeCSR->getCN() . '/' . $hashes['md5'] . '.txt');
59
60 1
        return 0;
61
    }
62
}
63