CheckCountAnswers   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 30
ccs 0
cts 19
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A checkCount() 0 18 4
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