SendTicketsMailCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author    Markus Tacker <[email protected]>
5
 * @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/
6
 */
7
8
namespace BCRM\BackendBundle\Command;
9
10
use BCRM\BackendBundle\Entity\Event\Event;
11
use BCRM\BackendBundle\Exception\CommandException;
12
use BCRM\BackendBundle\Service\Event\SendTicketMailCommand;
13
use Doctrine\Common\Util\Debug;
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class SendTicketsMailCommand extends ContainerAwareCommand
19
{
20
    /**
21
     * @var OutputInterface
22
     */
23
    private $output;
24
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('bcrm:tickets:send')
29
            ->setDescription('Send tickets');
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $this->output = $output;
35
        /** @var \BCRM\BackendBundle\Entity\Event\RegistrationRepository $registrationRepo */
36
        /** @var \BCRM\BackendBundle\Entity\Event\EventRepository $eventRepo */
37
        $eventRepo = $this->getContainer()->get('bcrm.backend.repo.event');
38
        $event     = $eventRepo->getNextEvent()->getOrThrow(new CommandException('No event.'));
39
        $this->sendNewTicketNotificationsFor($event);
40
    }
41
42 View Code Duplication
    protected function sendNewTicketNotificationsFor(Event $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        /** @var \BCRM\BackendBundle\Entity\Event\TicketRepository $repo */
45
        $repo = $this->getContainer()->get('bcrm.backend.repo.ticket');
46
        /** @var \LiteCQRS\Bus\CommandBus $commandBus */
47
        $commandBus = $this->getContainer()->get('command_bus');
48
        foreach ($repo->getToNotify($event) as $ticket) {
49
            if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
50
                $this->output->writeln(sprintf('Sending ticket notification for %s', $ticket));
51
            }
52
            $command                = new SendTicketMailCommand();
53
            $command->ticket        = $ticket;
54
            $command->event         = $event;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event of type object<BCRM\BackendBundle\Entity\Event\Event> is incompatible with the declared type object<BCRM\BackendBundle\Service\Event> of property $event.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
            $command->schemeAndHost = $this->getContainer()->getParameter('scheme_and_host');
56
            $commandBus->handle($command);
57
        }
58
    }
59
}
60