DeactivationPassModule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: device
5
 * Date: 09.03.16
6
 * Time: 19:01
7
 */
8
9
namespace AppBundle\Services;
10
11
12
use AppBundle\Entity\ModuleUser;
13
use AppBundle\Entity\PassModule;
14
use Symfony\Bridge\Doctrine\RegistryInterface;
15
16
class DeactivationPassModule
17
{
18
    private $doctrine;
19
20 2
    public function __construct(RegistryInterface $registryInterface)
21
    {
22 2
        $this->doctrine = $registryInterface;
23 2
    }
24
25
    public function deactivation(PassModule $passModule, $finishTime = null)
26
    {
27
        $em = $this->doctrine->getManager();
28
        $moduleUser = $em->getRepository('AppBundle:ModuleUser')
29
            ->find($passModule->getModuleUser());
30
        $module = $em->getRepository('AppBundle:Module')
31
            ->find($moduleUser->getModule());
32
33
        if ($finishTime) {
34
            $passModule->setTimeFinish($finishTime);
35
        }
36
        $passModule->setIsActive(false);
37
        $em->flush();
38
39
        if ($passModule->getPercentResult() >= $module->getPersentSuccess()) {
40
            $moduleUser->setStatus(ModuleUser::STATUS_SUCCESS);
41
            $moduleUser->setRating($passModule->getRating());
42
        } else if ($moduleUser->getCountPassModules() >= $module->getAttempts()){
43
                $moduleUser->setStatus(ModuleUser::STATUS_FAILED);
44
        }
45
        $em->flush();
46
    }
47
48
}
49