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

CommentCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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