CheckCountAnswers::checkCount()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 9.2
cc 4
eloc 10
nc 6
nop 1
crap 20
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: device
5
 * Date: 26.02.16
6
 * Time: 17:02
7
 */
8
9
namespace AppBundle\Services;
10
11
12
use AppBundle\Entity\Question;
13
use Symfony\Component\HttpFoundation\Session\Session;
14
use Symfony\Component\Routing\RouterInterface;
15
16
class CheckCountAnswers
17
{
18
    private $route;
19
    private $session;
20
21
    public function __construct(RouterInterface $routerInterface, Session $session)
22
    {
23
        $this->route = $routerInterface;
24
        $this->session = $session;
25
    }
26
    public function checkCount(Question $question)
27
    {
28
        $answers = $question->getAnswers();
29
        $countTrueAnswers = 0;
30
31
        foreach ($answers as $item) {
32
            $item->getCorrectly() ? $countTrueAnswers++ : null;
33
        }
34
35
        if ($countTrueAnswers > 3) {
36
            $this->session->getFlashBag()->add('notice',
37
                'You have to add not more than 3 true answers for question '.$question->getTextQuestion());
38
39
            return false;
40
        }
41
42
        return true;
43
    }
44
45
}
46