Completed
Push — 3.x-dev-kit ( cc4dbe )
by
unknown
03:15
created

CreateAndPublishCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
c 3
b 1
f 1
lcom 0
cbo 5
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 16 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NotificationBundle\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class CreateAndPublishCommand extends ContainerAwareCommand
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function configure()
25
    {
26
        $this
27
            ->setName('sonata:notification:create-and-publish')
28
            ->addArgument('type', InputArgument::REQUIRED, 'Type of the notification')
29
            ->addArgument('body', InputArgument::REQUIRED, 'Body of the notification (json)');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @param InputInterface  $input
36
     * @param OutputInterface $output
37
     */
38
    public function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $type = $input->getArgument('type');
41
        $body = json_decode($input->getArgument('body'), true);
42
43
        if (null === $body) {
44
            throw new \InvalidArgumentException('Body does not contain valid json.');
45
        }
46
47
        $this->getContainer()
48
            ->get('sonata.notification.backend')
49
            ->createAndPublish($type, $body)
50
        ;
51
52
        $output->writeln('<info>Done !</info>');
53
    }
54
}
55