Completed
Pull Request — develop (#165)
by Robbie
04:15
created

RemoveCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace N98\Magento\Command\GiftCard;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class RemoveCommand extends AbstractGiftCardCommand
11
{
12
    /**
13
     * Setup
14
     * 
15
     * @return void
16
     */
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('giftcard:remove')
21
            ->addArgument('code', InputArgument::REQUIRED, 'Gift card code')
22
            ->setDescription('Remove a gift card account by code');
23
24
        $help = <<<HELP
25
Remove a gift card account by code
26
HELP;
27
        $this->setHelp($help);
28
    }
29
30
    /**
31
     * @param \Symfony\Component\Console\Input\InputInterface $input
32
     * @param \Symfony\Component\Console\Output\OutputInterface $output
33
     * @return void
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $this->detectMagento($output, true);
38
        if (!$this->initMagento()) {
39
            return;
40
        }
41
42
        $this->setAdminArea();
43
44
        $code = $input->getArgument('code');
45
        $card = $this->getGiftcard($code);
46
47
        if (!$card->getId()) {
48
            $output->writeln('<info>No gift card with matching code found</info>');
49
            return;
50
        }
51
52
        $card->delete();
53
54
        $output->writeln('<info>Deleted gift card with code <comment>' . $code . '</comment></info>');
55
    }
56
}
57