Completed
Push — master ( 315248...bc8f92 )
by Kirill
11:40
created
src/Chrl/AppBundle/Service/GameService.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
     /** @var BuktopuhaBotApi */
27 27
     private $botApi;
28 28
 
29
-	private $config;
29
+    private $config;
30 30
 
31 31
     public function __construct(BuktopuhaBotApi $telegramBotApi, $config, EntityManagerInterface $entityManager)
32 32
     {
33 33
         $this->em = $entityManager;
34 34
         $this->botApi = $telegramBotApi;
35
-		$this->config = $config;
35
+        $this->config = $config;
36 36
     }
37 37
 
38 38
 
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
     }
101 101
 
102 102
 
103
-	/**
104
-	 * Checks if the answer is correct, and asks next question
105
-	 *
106
-	 * @param array $message
107
-	 */
103
+    /**
104
+     * Checks if the answer is correct, and asks next question
105
+     *
106
+     * @param array $message
107
+     */
108 108
     public function checkAnswer($message)
109 109
     {
110 110
         $game = $this->findGame($message);
@@ -140,36 +140,36 @@  discard block
 block discarded – undo
140 140
             } else {
141 141
                 // Incorrect answer
142 142
                 $game->incorrectTries++;
143
-				$hint = $game->hint;
144
-
145
-				if (mb_substr_count($hint,'*','UTF-8') < mb_strlen($hint,'UTF-8')/2) {
146
-					//tell hint
147
-
148
-					$tPos = rand(0,mb_strlen($question->a1,'UTF-8'));
149
-
150
-					while($game->hint == $hint) {
151
-						$hint = mb_substr($hint,0,$tPos-1,'UTF-8').
152
-								mb_substr($question->a1,$tPos,1,'UTF-8').
153
-								mb_substr($hint,$tPos+1,200,'UTF-8');
154
-					}
155
-
156
-					$game->hint = $hint;
157
-
158
-					$this->botApi->sendMessage(
159
-						$game->chatId,
160
-						'<b>Hint</b>: '.$hint,
161
-						'html'
162
-					);
163
-				} else {
164
-					$this->botApi->sendMessage(
165
-						$game->chatId,
166
-						'Noone answered, correct answer was: *'.$question->a1.'*',
167
-						'html'
168
-					);
169
-					$this->em->persist($game);
170
-					$this->em->flush();
171
-					$this->askQuestion($game);
172
-				}
143
+                $hint = $game->hint;
144
+
145
+                if (mb_substr_count($hint,'*','UTF-8') < mb_strlen($hint,'UTF-8')/2) {
146
+                    //tell hint
147
+
148
+                    $tPos = rand(0,mb_strlen($question->a1,'UTF-8'));
149
+
150
+                    while($game->hint == $hint) {
151
+                        $hint = mb_substr($hint,0,$tPos-1,'UTF-8').
152
+                                mb_substr($question->a1,$tPos,1,'UTF-8').
153
+                                mb_substr($hint,$tPos+1,200,'UTF-8');
154
+                    }
155
+
156
+                    $game->hint = $hint;
157
+
158
+                    $this->botApi->sendMessage(
159
+                        $game->chatId,
160
+                        '<b>Hint</b>: '.$hint,
161
+                        'html'
162
+                    );
163
+                } else {
164
+                    $this->botApi->sendMessage(
165
+                        $game->chatId,
166
+                        'Noone answered, correct answer was: *'.$question->a1.'*',
167
+                        'html'
168
+                    );
169
+                    $this->em->persist($game);
170
+                    $this->em->flush();
171
+                    $this->askQuestion($game);
172
+                }
173 173
 
174 174
             }
175 175
 
@@ -178,33 +178,33 @@  discard block
 block discarded – undo
178 178
         }
179 179
     }
180 180
 
181
-	/**
182
-	 * Asks question in the game
183
-	 *
184
-	 * @param Game $game
185
-	 */
181
+    /**
182
+     * Asks question in the game
183
+     *
184
+     * @param Game $game
185
+     */
186 186
 
187 187
     public function askQuestion(Game $game)
188 188
     {
189
-		$question = $this->getRandomQuestion();
189
+        $question = $this->getRandomQuestion();
190 190
 
191
-		$question->played++;
191
+        $question->played++;
192 192
 
193
-		$game->lastQuestion = $question->getId();
194
-		$game->lastQuestionTime = new \DateTime('now');
195
-		$game->incorrectTries = 0;
196
-		$game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8'));
193
+        $game->lastQuestion = $question->getId();
194
+        $game->lastQuestionTime = new \DateTime('now');
195
+        $game->incorrectTries = 0;
196
+        $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8'));
197 197
 
198
-		$this->em->persist($game);
199
-		$this->em->persist($question);
200
-		$this->em->flush();
198
+        $this->em->persist($game);
199
+        $this->em->persist($question);
200
+        $this->em->flush();
201 201
 
202 202
         $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown');
203 203
     }
204 204
 
205 205
     /**
206
-	 * Gets random question from database
207
-	 *
206
+     * Gets random question from database
207
+     *
208 208
      * @return Question
209 209
      * @throws \Doctrine\ORM\NoResultException
210 210
      * @throws \Doctrine\ORM\NonUniqueResultException
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
             if (mb_strtoupper($question->a1, 'UTF-8') == mb_strtoupper($message['text'], 'UTF-8')) {
122 122
                 // Correct answer!
123 123
 
124
-                $user->setPoints($user->getPoints()+$question->price);
124
+                $user->setPoints($user->getPoints() + $question->price);
125 125
                 $this->em->persist($user);
126 126
 
127 127
                 $this->botApi->sendMessage(
@@ -142,15 +142,15 @@  discard block
 block discarded – undo
142 142
                 $game->incorrectTries++;
143 143
 				$hint = $game->hint;
144 144
 
145
-				if (mb_substr_count($hint,'*','UTF-8') < mb_strlen($hint,'UTF-8')/2) {
145
+				if (mb_substr_count($hint, '*', 'UTF-8') < mb_strlen($hint, 'UTF-8') / 2) {
146 146
 					//tell hint
147 147
 
148
-					$tPos = rand(0,mb_strlen($question->a1,'UTF-8'));
148
+					$tPos = rand(0, mb_strlen($question->a1, 'UTF-8'));
149 149
 
150
-					while($game->hint == $hint) {
151
-						$hint = mb_substr($hint,0,$tPos-1,'UTF-8').
152
-								mb_substr($question->a1,$tPos,1,'UTF-8').
153
-								mb_substr($hint,$tPos+1,200,'UTF-8');
150
+					while ($game->hint == $hint) {
151
+						$hint = mb_substr($hint, 0, $tPos - 1, 'UTF-8').
152
+								mb_substr($question->a1, $tPos, 1, 'UTF-8').
153
+								mb_substr($hint, $tPos + 1, 200, 'UTF-8');
154 154
 					}
155 155
 
156 156
 					$game->hint = $hint;
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
 		$game->lastQuestion = $question->getId();
194 194
 		$game->lastQuestionTime = new \DateTime('now');
195 195
 		$game->incorrectTries = 0;
196
-		$game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8'));
196
+		$game->hint = str_repeat('*', mb_strlen($question->a1, 'UTF-8'));
197 197
 
198 198
 		$this->em->persist($game);
199 199
 		$this->em->persist($question);
200 200
 		$this->em->flush();
201 201
 
202
-        $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown');
202
+        $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1, 'UTF-8').' letters)_', 'markdown');
203 203
     }
204 204
 
205 205
     /**
Please login to merge, or discard this patch.
src/Chrl/AppBundle/Entity/Game.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,8 +78,8 @@
 block discarded – undo
78 78
      */
79 79
     public $incorrectTries;
80 80
 
81
-	/**
82
-	 * @ORM\Column(type="string",nullable=true)
83
-	 */
84
-	public $hint;
81
+    /**
82
+     * @ORM\Column(type="string",nullable=true)
83
+     */
84
+    public $hint;
85 85
 }
Please login to merge, or discard this patch.