Conditions | 4 |
Paths | 4 |
Total Lines | 52 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
99 | public function checkAnswer($message) |
||
100 | { |
||
101 | $game = $this->findGame($message); |
||
102 | $user = $this->getCurrentUser($message); |
||
103 | |||
104 | if ($game->status == 1) { |
||
105 | /** @var Question $question */ |
||
106 | $question = $this->em->getRepository('AppBundle:Question')->find($game->lastQuestion); |
||
107 | |||
108 | if (!$question) { |
||
109 | return; |
||
110 | } |
||
111 | |||
112 | if (mb_strtoupper($question->a1, 'UTF-8') == mb_strtoupper($message['text'], 'UTF-8')) { |
||
113 | // Correct answer! |
||
114 | |||
115 | $user->setPoints($user->getPoints()+$question->price); |
||
116 | $this->em->persist($user); |
||
117 | |||
118 | $this->botApi->sendMessage( |
||
119 | $game->chatId, |
||
120 | 'Correct! @'.$user->getAlias().' gets *'. |
||
121 | $question->price.'* and now has *'.$user->getPoints().'* points!', |
||
122 | 'markdown', |
||
123 | false, |
||
124 | $message['message_id'] |
||
125 | ); |
||
126 | |||
127 | $question->correct++; |
||
128 | $this->em->persist($question); |
||
129 | |||
130 | $question = $this->getRandomQuestion(); |
||
131 | |||
132 | $game->lastQuestion = $question->getId(); |
||
133 | $game->lastQuestionTime = new \DateTime('now'); |
||
134 | $game->incorrectTries = 0; |
||
135 | |||
136 | $this->askQuestion($game, $question); |
||
137 | } else { |
||
138 | // Incorrect answer |
||
139 | $game->incorrectTries++; |
||
140 | $this->botApi->sendMessage( |
||
141 | $game->chatId, |
||
142 | 'Wrong, @'.$user->getAlias().'. Correct answer: *'.$question->a1.'*', |
||
143 | 'markdown' |
||
144 | ); |
||
145 | } |
||
146 | |||
147 | $this->em->persist($game); |
||
148 | $this->em->flush(); |
||
149 | } |
||
150 | } |
||
151 | |||
175 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.