SendCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace DoS\SMSBundle\Command;
4
5
use SmsSender\Exception\WrappedException;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class SendCommand extends ContainerAwareCommand
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('dos:sms:send')
18
            ->setDescription('Send sms.')
19
            ->addArgument('number', InputArgument::REQUIRED, 'Which number you want to send to?')
20
            ->addArgument('message', InputArgument::REQUIRED, 'What is message you want to send?')
21
            ->addOption('originator', 'o', InputOption::VALUE_OPTIONAL, 'Originator required for some provider.', 'DoS')
22
        ;
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $number = $input->getArgument('number');
28
        $message = $input->getArgument('message');
29
        $originator = $input->getOption('originator');
30
31
        $sender = $this->getContainer()->get('dos.sms.sender');
32
33
        try {
34
            $result = $sender->send($number, $message, $originator);
35
        } catch (WrappedException $e) {
36
            $result = $e->getWrappedException()->getMessage();
37
        } catch (\Exception $e) {
38
            $result = $e->getMessage();
39
        }
40
41
        $output->writeln(($result));
42
    }
43
}
44