PassControl::process()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 24
ccs 0
cts 17
cp 0
rs 8.9713
cc 2
eloc 14
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: device
5
 * Date: 04.03.16
6
 * Time: 15:50
7
 */
8
9
namespace AppBundle\Services;
10
11
12
use AppBundle\Traits\GenerateOutput;
13
use Symfony\Bridge\Doctrine\RegistryInterface;
14
15
class PassControl
16
{
17
    use GenerateOutput;
18
19
    private $doctrine;
20
21
    private $checkAnswers;
22
23
    private $deactivation;
24
25
    public function __construct(RegistryInterface $registryInterface, $checkAnswers, DeactivationPassModule $deactivationPassModule)
26
    {
27
        $this->doctrine = $registryInterface;
28
        $this->checkAnswers = $checkAnswers;
29
        $this->deactivation = $deactivationPassModule;
30
    }
31
32
    public function process(array $data)
33
    {
34
        $rating = $this->checkAnswers->checkAnswers($data);
35
        $passModule = $this->doctrine->getRepository('AppBundle:PassModule')
0 ignored issues
show
Bug introduced by
The method findOneById() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
            ->findOneById($data['idPassModule']);
37
38
        $passModule->addAnsweredQuestionId($passModule->getCurrentQuestion()->getId());
39
40
        $nextQuestionForPass = $this->doctrine->getRepository('AppBundle:Question')
41
            ->getNextQuestionForPass($passModule);
42
43
        $passModule->addRating($rating);
44
45
46
        if($nextQuestionForPass === null) {
47
            $this->deactivation->deactivation($passModule, new \DateTime());
48
            return $this->generateOutput('redirect_to_result', 301, $data['idPassModule']);
49
        }
50
51
        $passModule->setCurrentQuestion($nextQuestionForPass);
52
        $this->doctrine->getManager()->flush();
53
54
        return $this->generateOutput('redirect_to_pass', 301, $data['idPassModule']);
55
    }
56
}
57