Passed
Push — 1.1.x ( bc52f7...e8e75c )
by f
12:04
created

CommentCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 19 4
1
<?php
2
3
namespace wapmorgan\UnifiedArchive\Commands;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class CommentCommand extends BaseArchiveCommand
10
{
11
    protected static $defaultName = 'archive:comment';
12
13
    protected function configure()
14
    {
15
        parent::configure();
16
        $this
17
            ->setDescription('Sets comment on archive')
18
            ->setHelp('Sets comment on archive.')
19
            ->addArgument('comment', InputArgument::REQUIRED, 'Comment')
20
        ;
21
    }
22
23
    public function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $archive = $this->getArchive($input, $output);
26
        $comment = $input->getArgument('comment');
27
        if (empty($comment)) {
28
            $comment = null;
29
        }
30
31
        if (!empty($previous_comment = $archive->getComment())) {
32
            $output->writeln('Comment "' . $previous_comment . '" replaced', OutputInterface::OUTPUT_RAW);
33
        } else if ($comment === null) {
34
            $output->writeln('Comment deleted', OutputInterface::OUTPUT_RAW);
35
        } else {
36
            $output->writeln('Comment set', OutputInterface::OUTPUT_RAW);
37
        }
38
39
        $archive->setComment($comment);
40
41
        return 0;
42
    }
43
}
44