SendCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 18 3
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