Conditions | 9 |
Paths | 7 |
Total Lines | 83 |
Code Lines | 54 |
Lines | 4 |
Ratio | 4.82 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
73 | public function resultAction() |
||
74 | { |
||
75 | $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
||
76 | $user = $this->zfcUserAuthentication()->getIdentity(); |
||
77 | $sg = $this->getGameService(); |
||
78 | |||
79 | $statusMail = null; |
||
80 | |||
81 | $game = $sg->checkGame($identifier); |
||
82 | if (!$game || $game->isClosed()) { |
||
83 | return $this->notFoundAction(); |
||
84 | } |
||
85 | |||
86 | $secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
||
87 | $socialLinkUrl = $this->frontendUrl()->fromRoute( |
||
88 | 'lottery', |
||
89 | array( |
||
90 | 'id' => $game->getIdentifier(), |
||
91 | 'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
||
92 | ), |
||
93 | array('force_canonical' => true) |
||
94 | ).'?key='.$secretKey; |
||
95 | // With core shortener helper |
||
96 | $socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
||
97 | |||
98 | $lastEntry = $sg->findLastInactiveEntry($game, $user); |
||
99 | if (!$lastEntry) { |
||
100 | return $this->redirect()->toUrl( |
||
101 | $this->frontendUrl()->fromRoute( |
||
102 | 'lottery', |
||
103 | array( |
||
104 | 'id' => $game->getIdentifier(), |
||
105 | 'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
||
106 | ), |
||
107 | array('force_canonical' => true) |
||
108 | ) |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | View Code Duplication | if (!$user && !$game->getAnonymousAllowed()) { |
|
113 | $redirect = urlencode( |
||
114 | $this->frontendUrl()->fromRoute( |
||
115 | 'lottery/result', |
||
116 | array('id' => $game->getIdentifier(), 'channel' => $channel) |
||
117 | ) |
||
118 | ); |
||
119 | return $this->redirect()->toUrl( |
||
120 | $this->frontendUrl()->fromRoute( |
||
121 | 'zfcuser/register', |
||
122 | array('channel' => $channel) |
||
123 | ) . '?redirect='.$redirect |
||
124 | ); |
||
125 | } |
||
126 | |||
127 | $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
||
128 | $form->setAttribute('method', 'post'); |
||
129 | |||
130 | if ($this->getRequest()->isPost()) { |
||
131 | $data = $this->getRequest()->getPost()->toArray(); |
||
132 | $form->setData($data); |
||
133 | if ($form->isValid()) { |
||
134 | $result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
||
135 | if ($result) { |
||
136 | $statusMail = true; |
||
137 | $sg->addAnotherChance($game, $user, 1); |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | // buildView must be before sendMail because it adds the game template path to the templateStack |
||
143 | $viewModel = $this->buildView($game); |
||
144 | |||
145 | $this->getGameService()->sendMail($game, $user, $lastEntry); |
||
146 | |||
147 | $viewModel->setVariables(array( |
||
148 | 'statusMail' => $statusMail, |
||
149 | 'form' => $form, |
||
150 | 'socialLinkUrl' => $socialLinkUrl, |
||
151 | 'secretKey' => $secretKey, |
||
152 | )); |
||
153 | |||
154 | return $viewModel; |
||
155 | } |
||
156 | |||
254 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: