PassControl   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 1
cbo 4
dl 0
loc 42
ccs 0
cts 23
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B process() 0 24 2
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