CreateAndPublishCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Command;
15
16
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class CreateAndPublishCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function configure(): void
27
    {
28
        $this
29
            ->setName('sonata:notification:create-and-publish')
30
            ->addArgument('type', InputArgument::REQUIRED, 'Type of the notification')
31
            ->addArgument('body', InputArgument::REQUIRED, 'Body of the notification (json)');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function execute(InputInterface $input, OutputInterface $output): void
38
    {
39
        $type = $input->getArgument('type');
40
        $body = json_decode($input->getArgument('body'), true);
41
42
        if (null === $body) {
43
            throw new \InvalidArgumentException('Body does not contain valid json.');
44
        }
45
46
        $this->getContainer()
47
            ->get('sonata.notification.backend')
48
            ->createAndPublish($type, $body)
49
        ;
50
51
        $output->writeln('<info>Done !</info>');
52
    }
53
}
54