Conditions | 15 |
Paths | 9 |
Total Lines | 51 |
Lines | 12 |
Ratio | 23.53 % |
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 |
||
25 | protected function execute(InputInterface $input, OutputInterface $output) |
||
26 | { |
||
27 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
28 | |||
29 | $query = $em->createQuery('SELECT fg FROM KIUserBundle:Facegame fg'); |
||
30 | $iterableResult = $query->iterate(); |
||
31 | |||
32 | /** |
||
33 | * @var $facegame Facegame |
||
34 | */ |
||
35 | foreach ($iterableResult as $row) { |
||
36 | $facegame = $row[0]; |
||
37 | $user = $facegame->getUser(); |
||
38 | |||
39 | $achievementCheck = new AchievementCheckEvent(Achievement::GAME_PLAY, $user); |
||
40 | $dispatcher = $this->getContainer()->get('event_dispatcher'); |
||
41 | |||
42 | $dispatcher->dispatch('upont.achievement', $achievementCheck); |
||
43 | |||
44 | $promoUser = (int)$user->getPromo(); |
||
45 | $promoGame = (int)$facegame->getPromo(); |
||
46 | |||
47 | $wrongAnswers = $facegame->getWrongAnswers(); |
||
48 | $duration = $facegame->getDuration(); |
||
49 | |||
50 | if ($wrongAnswers == 0 && $promoGame == $promoUser - 1 && $duration < 60 * 1000) { |
||
51 | |||
52 | $achievementCheck = new AchievementCheckEvent(Achievement::GAME_BEFORE, $user); |
||
53 | $dispatcher->dispatch('upont.achievement', $achievementCheck); |
||
54 | |||
55 | } else if ($wrongAnswers == 0 && $promoGame == $promoUser && $duration < 60 * 1000) { |
||
56 | |||
57 | $achievementCheck = new AchievementCheckEvent(Achievement::GAME_SELF, $user); |
||
58 | $dispatcher->dispatch('upont.achievement', $achievementCheck); |
||
59 | |||
60 | View Code Duplication | } else if ($wrongAnswers == 0 && $promoGame == $promoUser + 1 && $duration < 60 * 1000) { |
|
61 | |||
62 | $achievementCheck = new AchievementCheckEvent(Achievement::GAME_NEXT, $user); |
||
63 | $dispatcher->dispatch('upont.achievement', $achievementCheck); |
||
64 | |||
65 | } |
||
66 | View Code Duplication | if ($wrongAnswers == 0 && $promoGame < $promoUser && $facegame->getHardcore() && $duration < 60 * 1000) { |
|
67 | |||
68 | $achievementCheck = new AchievementCheckEvent(Achievement::GAME_OLD, $user); |
||
69 | $dispatcher->dispatch('upont.achievement', $achievementCheck); |
||
70 | |||
71 | } |
||
72 | |||
73 | $em->detach($row[0]); |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 |