Issues (31)

src/Controller/CheckInController.php (2 issues)

1
<?php
2
3
namespace ConferenceTools\Checkin\Controller;
4
5
use Carnage\Cqrs\Command\CommandBusInterface;
6
use Carnage\Cqrs\MessageBus\MessageBusInterface;
7
use Carnage\Cqrs\Persistence\ReadModel\RepositoryInterface;
8
use ConferenceTools\Checkin\Domain\Command\Delegate\CheckInDelegate;
9
use ConferenceTools\Checkin\Form\SearchForm;
10
use Doctrine\Common\Collections\Criteria;
11
use Zend\Form\Form;
12
use Zend\Mvc\Controller\AbstractActionController;
13
use Zend\View\Model\ViewModel;
14
15
class CheckInController extends AbstractActionController
16
{
17
    /**
18
     * @var CommandBusInterface
19
     */
20
    private $commandBus;
21
    /**
22
     * @var RepositoryInterface
23
     */
24
    private $repository;
25
26
    public function __construct(MessageBusInterface $commandBus, RepositoryInterface $repository)
27
    {
28
        $this->commandBus = $commandBus;
0 ignored issues
show
Documentation Bug introduced by
$commandBus is of type Carnage\Cqrs\MessageBus\MessageBusInterface, but the property $commandBus was declared to be of type Carnage\Cqrs\Command\CommandBusInterface. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
29
        $this->repository = $repository;
30
    }
31
32
    public function searchAction()
33
    {
34
        $form = new SearchForm();
35
        $form->init();
36
        $results = [];
37
38
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
The method isPost() does not exist on Zend\Stdlib\RequestInterface. It seems like you code against a sub-type of Zend\Stdlib\RequestInterface such as Zend\Http\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        if ($this->getRequest()->/** @scrutinizer ignore-call */ isPost()) {
Loading history...
39
            $data = $this->params()->fromPost();
40
            $form->setData($data);
41
            if ($form->isValid()) {
42
                $data = $form->getData();
43
                $data['purchaserEmail'] = $data['email'];
44
45
                $criteria = Criteria::create();
46
47
                foreach ($data as $key => $search) {
48
                    if (empty($search)) {
49
                        continue;
50
                    }
51
52
                    $criteria->orWhere(Criteria::expr()->contains($key, $search));
53
                }
54
55
                $results = $this->repository->matching($criteria);
56
            }
57
        }
58
59
        return new ViewModel(['form' => $form, 'results' => $results]);
60
    }
61
62
    public function checkinAction()
63
    {
64
        try {
65
            $delegateId = $this->params()->fromRoute('delegateId');
66
            $this->commandBus->dispatch(new CheckInDelegate($delegateId));
67
            $this->flashMessenger()->addInfoMessage('Delegate checked in');
68
        } catch (\Exception $e) {
69
            $this->flashMessenger()->addErrorMessage($e->getMessage());
70
        }
71
72
73
        return $this->redirect()->toRoute('checkin/search', [], ['force_canonical' => true]);
74
    }
75
}