Completed
Branch develop (b9c805)
by Pavel
06:33
created
src/AppBundle/Services/PassManager.php 3 patches
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -1,23 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace AppBundle\Services;
3 3
 
4
-use AppBundle\Entity\Comment;
5 4
 use AppBundle\Entity\ModuleUser;
6 5
 use AppBundle\Entity\PassModule;
7 6
 use AppBundle\Form\AnswerForPassType;
8
-use AppBundle\Form\CommentType;
9 7
 use AppBundle\Traits\GenerateOutput;
10 8
 use Faker\Provider\cs_CZ\DateTime;
11
-use Knp\Component\Pager\PaginatorInterface;
12
-use Proxies\__CG__\AppBundle\Entity\Module;
13 9
 use Symfony\Bridge\Doctrine\RegistryInterface;
14 10
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
15 11
 use Symfony\Component\Form\FormFactoryInterface;
16
-use Symfony\Component\HttpFoundation\RedirectResponse;
17 12
 use Symfony\Component\HttpFoundation\Request;
18
-use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
19
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
20
-use Symfony\Component\Routing\RouterInterface;
21 13
 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22 14
 
23 15
 class PassManager
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         $dateEstimate = $pass->getTimeStart()
82 82
             ->modify("+{$pass->getTimePeriod()} minutes");
83 83
 
84
-        if($nowDate > $dateEstimate){
84
+        if ($nowDate > $dateEstimate) {
85 85
          //   $pass->setIsActive(false);
86 86
         //    $this->doctrine->getEntityManager()->flush();
87 87
             $this->deactivation->deactivation($pass);
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
             $firstQuestionForPass = $this->doctrine->getRepository('AppBundle:Question')
138 138
                 ->getFirstQuestionForPass($passModule->getId());
139 139
 
140
-            if(null === $firstQuestionForPass)
140
+            if (null === $firstQuestionForPass)
141 141
                 return $this->generateOutput('error', 500, 'This module does not have any questions ;(');
142 142
 
143 143
             $passModule->setCurrentQuestion($firstQuestionForPass);
144 144
             $this->doctrine->getEntityManager()->flush();
145 145
         }
146 146
 
147
-        if(!($passModule->getIsActive())){
147
+        if (!($passModule->getIsActive())) {
148 148
             return $this->generateOutput('error', 403, 'This pass is not active ;(');
149 149
         }
150 150
 
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
             'idPassModule' => $idPassModule,
162 162
             'answers' => $currentQuestion->getAnswers()->toArray()
163 163
         ]);
164
-        $form->add('submit', SubmitType::class, ['label' => 'Save', 'attr' => [ 'class' => 'btn btn-primary' ]]);
164
+        $form->add('submit', SubmitType::class, [ 'label' => 'Save', 'attr' => [ 'class' => 'btn btn-primary' ] ]);
165 165
 
166
-        $currentNumberQuestion = $passModule->getCountPassedQuestions()+1;
166
+        $currentNumberQuestion = $passModule->getCountPassedQuestions() + 1;
167 167
 
168 168
         return $this->generateOutput('ok', 200, [
169 169
             $form,
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -56,8 +56,9 @@  discard block
 block discarded – undo
56 56
             return $this->generateOutput('error', 403, 'You do not have access to this module');
57 57
         }
58 58
 
59
-        if ($moduleUser->getAttempts() == $moduleUser->getModule()->getAttempts())
60
-            return $this->generateOutput('error', 403, 'Your attempts are exhausted');
59
+        if ($moduleUser->getAttempts() == $moduleUser->getModule()->getAttempts()) {
60
+                    return $this->generateOutput('error', 403, 'Your attempts are exhausted');
61
+        }
61 62
 
62 63
         $lastPass = $moduleUser->getPassModules()->last();
63 64
 
@@ -68,8 +69,9 @@  discard block
 block discarded – undo
68 69
 
69 70
         $time_residue = $this->checkDatePass($lastPass);
70 71
 
71
-        if (!$time_residue)
72
-            $this->identPass($idModule);
72
+        if (!$time_residue) {
73
+                    $this->identPass($idModule);
74
+        }
73 75
 
74 76
         return $this->generateOutput('redirect_to_pass', 301, $lastPass->getId());
75 77
     }
@@ -137,8 +139,9 @@  discard block
 block discarded – undo
137 139
             $firstQuestionForPass = $this->doctrine->getRepository('AppBundle:Question')
138 140
                 ->getFirstQuestionForPass($passModule->getId());
139 141
 
140
-            if(null === $firstQuestionForPass)
141
-                return $this->generateOutput('error', 500, 'This module does not have any questions ;(');
142
+            if(null === $firstQuestionForPass) {
143
+                            return $this->generateOutput('error', 500, 'This module does not have any questions ;(');
144
+            }
142 145
 
143 146
             $passModule->setCurrentQuestion($firstQuestionForPass);
144 147
             $this->doctrine->getEntityManager()->flush();
@@ -150,8 +153,9 @@  discard block
 block discarded – undo
150 153
 
151 154
         $time_residue = $this->checkDatePass($passModule);
152 155
 
153
-        if (!$time_residue)
154
-            return $this->generateOutput('error', 403, 'This pass is overdue ;(');
156
+        if (!$time_residue) {
157
+                    return $this->generateOutput('error', 403, 'This pass is overdue ;(');
158
+        }
155 159
 
156 160
 
157 161
         $currentQuestion = $passModule->getCurrentQuestion();
Please login to merge, or discard this patch.
src/AppBundle/OAuthProvider/LoginUserProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     {
42 42
         $em = $this->em;
43 43
         $type = $response->getResourceOwner()->getName();
44
-        $user = $em->getRepository('AppBundle:User')->findOneBy(['email' => $response->getEmail()]);
44
+        $user = $em->getRepository('AppBundle:User')->findOneBy([ 'email' => $response->getEmail() ]);
45 45
         if ($user === null) {
46 46
             $user = new User();
47 47
             $user->setEmail($response->getEmail())
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function loadUserByUsername($username)
91 91
     {
92
-        $user = $this->em->getRepository('AppBundle:User')->findOneBy(['email' => $username]);
92
+        $user = $this->em->getRepository('AppBundle:User')->findOneBy([ 'email' => $username ]);
93 93
         if (!$user) {
94 94
             throw new UsernameNotFoundException(sprintf("User '%s' not found.", $username));
95 95
         }
Please login to merge, or discard this patch.
src/AppBundle/Services/CheckAnwers.php 3 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $em = $this->doctrine->getManager();
26 26
         $question = $em->getRepository('AppBundle:Question')
27
-            ->find($data['idQuestion']);
27
+            ->find($data[ 'idQuestion' ]);
28 28
 
29 29
         $originalAnswers = $question->getAnswers();
30 30
         $countOriginalAnswers = $question->getCountAnswers();
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
         foreach ($originalAnswers as $item) {
39 39
             $item->getCorrectly() ? $countAllTrueAnswers++ : null;
40
-            $data["answer_{$item->getId()}"] ? $countAllChecks++ : null;
41
-            if ($item->getCorrectly() === $data["answer_{$item->getId()}"]) {
40
+            $data[ "answer_{$item->getId()}" ] ? $countAllChecks++ : null;
41
+            if ($item->getCorrectly() === $data[ "answer_{$item->getId()}" ]) {
42 42
                 $sumAllCorrect++;
43 43
                 if ($item->getCorrectly())
44 44
                     $sumCorrectChecks++;
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
             $maxCountAnswers = $countAllTrueAnswers;
56 56
         }
57 57
 
58
-        if ($question->getAllIncorrect() || $data['answer_all_incorrect']) {
59
-            if ($question->getAllIncorrect() === $data['answer_all_incorrect'] && $question->getAllIncorrect() === true &&
58
+        if ($question->getAllIncorrect() || $data[ 'answer_all_incorrect' ]) {
59
+            if ($question->getAllIncorrect() === $data[ 'answer_all_incorrect' ] && $question->getAllIncorrect() === true &&
60 60
                 $sumAllCorrect == $countOriginalAnswers
61 61
             )
62 62
                 return $result = 1;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         if ($sumAllCorrect && $sumCorrectChecks && $countAllChecks <= $maxCountAnswers) {
69 69
             // second type question
70 70
             if ($countAllTrueAnswers == 1) {
71
-                $result = (1 / $maxCountAnswers) * ($sumCorrectChecks + ($sumFalseAnswers > 0 ? 0: 1));
71
+                $result = (1 / $maxCountAnswers) * ($sumCorrectChecks + ($sumFalseAnswers > 0 ? 0 : 1));
72 72
             }
73 73
             // third type question
74 74
             elseif ($countAllTrueAnswers > 1) {
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: device
5
- * Date: 04.03.16
6
- * Time: 15:50
7
- */
3
+     * Created by PhpStorm.
4
+     * User: device
5
+     * Date: 04.03.16
6
+     * Time: 15:50
7
+     */
8 8
 
9 9
 namespace AppBundle\Services;
10 10
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@  discard block
 block discarded – undo
40 40
             $data["answer_{$item->getId()}"] ? $countAllChecks++ : null;
41 41
             if ($item->getCorrectly() === $data["answer_{$item->getId()}"]) {
42 42
                 $sumAllCorrect++;
43
-                if ($item->getCorrectly())
44
-                    $sumCorrectChecks++;
43
+                if ($item->getCorrectly()) {
44
+                                    $sumCorrectChecks++;
45
+                }
45 46
             } else {
46 47
                 if ($item->getCorrectly() === false) {
47 48
                     $sumFalseAnswers++;
@@ -58,8 +59,9 @@  discard block
 block discarded – undo
58 59
         if ($question->getAllIncorrect() || $data['answer_all_incorrect']) {
59 60
             if ($question->getAllIncorrect() === $data['answer_all_incorrect'] && $question->getAllIncorrect() === true &&
60 61
                 $sumAllCorrect == $countOriginalAnswers
61
-            )
62
-                return 1;
62
+            ) {
63
+                            return 1;
64
+            }
63 65
 
64 66
             return 0;
65 67
         }
Please login to merge, or discard this patch.
src/AppBundle/Services/CheckAnswerV0.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: device
5
- * Date: 04.03.16
6
- * Time: 15:50
7
- */
3
+     * Created by PhpStorm.
4
+     * User: device
5
+     * Date: 04.03.16
6
+     * Time: 15:50
7
+     */
8 8
 
9 9
 namespace AppBundle\Services;
10 10
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $em = $this->doctrine->getManager();
26 26
         $question = $em->getRepository('AppBundle:Question')
27
-            ->find($data['idQuestion']);
27
+            ->find($data[ 'idQuestion' ]);
28 28
 
29 29
         $originalAnswers = $question->getAnswers();
30 30
         $countOriginalAnswers = count($originalAnswers);
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
         foreach ($originalAnswers as $item) {
39 39
             $item->getCorrectly() ? $countAllTrueAnswers++ : $countAllFalseAnswers++;
40
-            if ($item->getCorrectly() === $data["answer_{$item->getId()}"]) {
40
+            if ($item->getCorrectly() === $data[ "answer_{$item->getId()}" ]) {
41 41
                 if ($item->getCorrectly() === true) {
42 42
                     $sumTrueCorrect++;
43 43
                 }
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
             }
50 50
         }
51 51
         //first type question
52
-        if ($question->getAllIncorrect() || $data['answer_all_incorrect']) {
53
-            if ($question->getAllIncorrect() === $data['answer_all_incorrect'] && $question->getAllIncorrect() === true && $sumTrueCorrect == 0) {
52
+        if ($question->getAllIncorrect() || $data[ 'answer_all_incorrect' ]) {
53
+            if ($question->getAllIncorrect() === $data[ 'answer_all_incorrect' ] && $question->getAllIncorrect() === true && $sumTrueCorrect == 0) {
54 54
 
55 55
                 return $result = 1;
56 56
             }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 //   $result = $sumTrueCorrect != 0 ? ((1 / $countAllTrueAnswers) * $sumTrueCorrect) - ((1 / $countAllFalseAnswers) * $countFalseAnswers) : 0;
75 75
                 $result = $sumAllCorrect != 0 ? ((1 / $countOriginalAnswers) * $sumAllCorrect) : 0;
76 76
             } else {
77
-                $result =  0;
77
+                $result = 0;
78 78
             }
79 79
         }
80 80
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@
 block discarded – undo
64 64
                 $result = $sumTrueCorrect != 0 ? 1 / $sumTrueCorrect / 2 : 0;
65 65
             } elseif ($countFalseAnswers > 1) {
66 66
                 $result = 0;
67
-            }
68
-            else {
67
+            } else {
69 68
                 $result = $sumTrueCorrect != 0 ? 1 / $sumTrueCorrect : 0;
70 69
             }
71 70
             //third type question
Please login to merge, or discard this patch.
src/AppBundle/Services/CheckCountAnswers.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 
35 35
         if ($countTrueAnswers > 3) {
36 36
             $this->session->getFlashBag()->add('notice',
37
-                'You have to add not more than 3 true answers for question '.$question->getTextQuestion());
37
+                'You have to add not more than 3 true answers for question ' . $question->getTextQuestion());
38 38
 
39 39
             return false;
40 40
         }
Please login to merge, or discard this patch.
src/AppBundle/Services/DeactivationPassModule.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: device
5
- * Date: 09.03.16
6
- * Time: 19:01
7
- */
3
+     * Created by PhpStorm.
4
+     * User: device
5
+     * Date: 09.03.16
6
+     * Time: 19:01
7
+     */
8 8
 
9 9
 namespace AppBundle\Services;
10 10
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
         if ($passModule->getPercentResult() >= $module->getPersentSuccess()) {
40 40
             $moduleUser->setStatus(ModuleUser::STATUS_SUCCESS);
41 41
             $moduleUser->setRating($passModule->getRating());
42
-        } else if ($moduleUser->getCountPassModules() >= $module->getAttempts()){
42
+        } else if ($moduleUser->getCountPassModules() >= $module->getAttempts()) {
43 43
                 $moduleUser->setStatus(ModuleUser::STATUS_FAILED);
44 44
                 //$moduleUser->setRating($passModule->getRating());
45 45
         }
Please login to merge, or discard this patch.
src/AppBundle/Services/PassControl.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $rating = $this->checkAnswers->checkAnswers($data);
35 35
         $passModule = $this->doctrine->getRepository('AppBundle:PassModule')
36
-            ->findOneById($data['idPassModule']);
36
+            ->findOneById($data[ 'idPassModule' ]);
37 37
 
38 38
         $passModule->addAnsweredQuestionId($passModule->getCurrentQuestion()->getId());
39 39
 
@@ -43,18 +43,18 @@  discard block
 block discarded – undo
43 43
         $passModule->addRating($rating);
44 44
 
45 45
 
46
-        if($nextQuestionForPass === null) {
46
+        if ($nextQuestionForPass === null) {
47 47
           //  $passModule->setIsActive(false);
48 48
           //  $passModule->setTimeFinish(new \DateTime());
49 49
          //   $this->doctrine->getEntityManager()->flush();
50 50
             $timeFinish = new \DateTime();
51 51
             $this->deactivation->deactivation($passModule, $timeFinish);
52
-            return $this->generateOutput('redirect_to_result', 301, $data['idPassModule']);
52
+            return $this->generateOutput('redirect_to_result', 301, $data[ 'idPassModule' ]);
53 53
         }
54 54
 
55 55
         $passModule->setCurrentQuestion($nextQuestionForPass);
56 56
         $this->doctrine->getEntityManager()->flush();
57 57
 
58
-        return $this->generateOutput('redirect_to_pass', 301, $data['idPassModule']);
58
+        return $this->generateOutput('redirect_to_pass', 301, $data[ 'idPassModule' ]);
59 59
     }
60 60
 }
Please login to merge, or discard this patch.
src/AppBundle/Traits/GenerateOutput.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace AppBundle\Traits;
3 3
 
4
-trait GenerateOutput{
4
+trait GenerateOutput {
5 5
 
6 6
     private function generateOutput($status, $code, $message)
7 7
     {
Please login to merge, or discard this patch.
src/AppBundle/Tests/TestBaseWeb.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@
 block discarded – undo
17 17
     public function setUp()
18 18
     {
19 19
         $this->client = static::createClient();
20
-        $this->runCommand(['command' => 'doctrine:database:create']);
21
-        $this->runCommand(['command' => 'doctrine:schema:update', '--force' => true]);
22
-        $this->runCommand(['command' => 'doctrine:fixtures:load', '--no-interaction' => true]);
20
+        $this->runCommand([ 'command' => 'doctrine:database:create' ]);
21
+        $this->runCommand([ 'command' => 'doctrine:schema:update', '--force' => true ]);
22
+        $this->runCommand([ 'command' => 'doctrine:fixtures:load', '--no-interaction' => true ]);
23 23
 
24 24
     }
25 25
 
26 26
     public function tearDown()
27 27
     {
28
-        $this->runCommand(['command' => 'doctrine:database:drop', '--force' => true]);
28
+        $this->runCommand([ 'command' => 'doctrine:database:drop', '--force' => true ]);
29 29
         $this->client = null;
30 30
     }
31 31
 
32
-    protected function runCommand(array $arguments = [])
32
+    protected function runCommand(array $arguments = [ ])
33 33
     {
34 34
         $application = new Application($this->client->getKernel());
35 35
         $application->setAutoExit(false);
36
-        $arguments['--quiet'] = true;
37
-        $arguments['-e'] = 'test';
36
+        $arguments[ '--quiet' ] = true;
37
+        $arguments[ '-e' ] = 'test';
38 38
         $input = new ArrayInput($arguments);
39 39
         $application->run($input, new ConsoleOutput());
40 40
     }
Please login to merge, or discard this patch.