Concierge::checkin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
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\Service;
9
10
use BCRM\BackendBundle\Event\Concierge\CheckedInEvent;
11
use BCRM\BackendBundle\Service\Concierge\CheckinCommand;
12
use BCRM\BackendBundle\Service\Concierge\PayRegistrationConciergeCommand;
13
use BCRM\BackendBundle\Entity\PaymentRepository;
14
use BCRM\BackendBundle\Entity\Event\RegistrationRepository;
15
use Endroid\QrCode\QrCode;
16
use LiteCQRS\Bus\CommandBus;
17
use LiteCQRS\Bus\EventMessageBus;
18
use LiteCQRS\Plugin\CRUD\Model\Commands\UpdateResourceCommand;
19
use LiteCQRS\Plugin\CRUD\Model\Commands\CreateResourceCommand;
20
use Symfony\Component\Routing\RouterInterface;
21
use LiteCQRS\Plugin\CRUD\Model\Events\ResourceCreatedEvent;
22
23
class Concierge
24
{
25
    /**
26
     * @var \LiteCQRS\Bus\CommandBus
27
     */
28
    private $commandBus;
29
30
    /**
31
     * @var \LiteCQRS\Bus\EventMessageBus
32
     */
33
    private $eventMessageBus;
34
35
    /**
36
     * @param CommandBus             $commandBus
37
     * @param RouterInterface        $router
0 ignored issues
show
Bug introduced by
There is no parameter named $router. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
38
     * @param PaymentRepository      $paymentRepo
39
     * @param RegistrationRepository $registrationRepo
40
     */
41
    public function __construct(
42
        CommandBus $commandBus,
43
        EventMessageBus $eventMessageBus,
44
        PaymentRepository $paymentRepo,
45
        RegistrationRepository $registrationRepo
46
    )
47
    {
48
        $this->commandBus       = $commandBus;
49
        $this->eventMessageBus  = $eventMessageBus;
50
        $this->paymentRepo      = $paymentRepo;
0 ignored issues
show
Bug introduced by
The property paymentRepo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
        $this->registrationRepo = $registrationRepo;
0 ignored issues
show
Bug introduced by
The property registrationRepo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
    }
53
54
    public function checkin(CheckinCommand $command)
55
    {
56
        $updateCommand        = new UpdateResourceCommand();
57
        $updateCommand->class = '\BCRM\BackendBundle\Entity\Event\Ticket';
58
        $updateCommand->id    = $command->ticket->getId();
59
        $updateCommand->data  = array('checkedIn' => new \DateTime());
60
        $this->commandBus->handle($updateCommand);
61
62
        $event         = new CheckedInEvent();
63
        $event->ticket = $command->ticket;
64
        $this->eventMessageBus->publish($event);
65
    }
66
67
    public function payRegistrationConcierge(PayRegistrationConciergeCommand $command)
68
    {
69
        $createCommand        = new CreateResourceCommand();
70
        $createCommand->class = '\BCRM\BackendBundle\Entity\Payment';
71
        $createCommand->data  = array(
72
            'txId'     => $command->uuid,
73
            'payload'  => [],
74
            'method'   => 'concierge',
75
            'checked'  => new \DateTime(),
76
            'verified' => '1'
77
        );
78
        $this->commandBus->handle($createCommand);
79
80
        $paymentOption = $this->paymentRepo->findByTxId($command->uuid);
81
        if ($paymentOption->isDefined()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
82
83
        }
84
    }
85
86
    public function onResourceCreated(ResourceCreatedEvent $event)
87
    {
88
        if ($event->class !== 'BCRM\BackendBundle\Entity\Payment') {
89
            return;
90
        }
91
        $registrationOption = $this->registrationRepo->findByUuid($event->data['txId']);
92
        if ($registrationOption->isDefined()) {
93
            $payRegistrationCommand               = new \BCRM\BackendBundle\Service\Payment\PayRegistrationCommand();
94
            $payRegistrationCommand->registration = $registrationOption->get();
95
            $payRegistrationCommand->payment      = $this->paymentRepo->findByTxId($event->data['txId'])->get();
96
            $this->commandBus->handle($payRegistrationCommand);
97
        }
98
    }
99
}
100