Conditions | 6 |
Paths | 9 |
Total Lines | 47 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | public function createLotteryAction() |
||
18 | { |
||
19 | $service = $this->getAdminGameService(); |
||
20 | $viewModel = new ViewModel(); |
||
21 | $viewModel->setTemplate('playground-game/lottery/lottery'); |
||
22 | |||
23 | $gameForm = new ViewModel(); |
||
24 | $gameForm->setTemplate('playground-game/game/game-form'); |
||
25 | |||
26 | $lottery = new Lottery(); |
||
27 | |||
28 | $form = $this->getServiceLocator()->get('playgroundgame_lottery_form'); |
||
29 | $form->bind($lottery); |
||
30 | $form->get('submit')->setAttribute('label', 'Add'); |
||
31 | $form->setAttribute( |
||
32 | 'action', |
||
33 | $this->url()->fromRoute( |
||
34 | 'admin/playgroundgame/create-lottery', |
||
35 | array('gameId' => 0) |
||
36 | ) |
||
37 | ); |
||
38 | $form->setAttribute('method', 'post'); |
||
39 | |||
40 | $request = $this->getRequest(); |
||
41 | if ($request->isPost()) { |
||
42 | $data = array_replace_recursive( |
||
43 | $this->getRequest()->getPost()->toArray(), |
||
|
|||
44 | $this->getRequest()->getFiles()->toArray() |
||
45 | ); |
||
46 | if (empty($data['prizes'])) { |
||
47 | $data['prizes'] = array(); |
||
48 | } |
||
49 | if (isset($data['drawDate']) && $data['drawDate']) { |
||
50 | $data['drawDate'] = \DateTime::createFromFormat('d/m/Y', $data['drawDate']); |
||
51 | } |
||
52 | $game = $service->create($data, $lottery, 'playgroundgame_lottery_form'); |
||
53 | if ($game) { |
||
54 | $this->flashMessenger()->setNamespace('playgroundgame')->addMessage('The game was created'); |
||
55 | |||
56 | return $this->redirect()->toRoute('admin/playgroundgame/list'); |
||
57 | } |
||
58 | } |
||
59 | $gameForm->setVariables(array('form' => $form, 'game' => $lottery)); |
||
60 | $viewModel->addChild($gameForm, 'game_form'); |
||
61 | |||
62 | return $viewModel->setVariables(array('form' => $form, 'title' => 'Create lottery')); |
||
63 | } |
||
64 | |||
91 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: