FeedbackManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 5
Metric Value
wmc 6
c 7
b 0
f 5
lcom 1
cbo 6
dl 0
loc 67
ccs 24
cts 24
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFeedback() 0 6 2
A createFeedback() 0 14 1
A countFeedbacksPerStatus() 0 3 1
A getProjectFeedbacks() 0 3 1
A getProjectFeedbacksByAuthor() 0 6 1
1
<?php
2
3
namespace Developtech\AgilityBundle\Manager;
4
5
use Doctrine\ORM\EntityManager;
6
7
use Developtech\AgilityBundle\Model\ProjectModel;
8
use Developtech\AgilityBundle\Model\FeedbackModel;
9
10
use Developtech\AgilityBundle\Entity\Feedback;
11
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
14
use Developtech\AgilityBundle\Utils\Slugger;
15
16
use Symfony\Component\Security\Core\User\UserInterface;
17
18
class FeedbackManager extends JobManager {
19
20
    /**
21
     * @param ProjectModel $project
22
     * @return array
23
     */
24 1
    public function getProjectFeedbacks(ProjectModel $project) {
25 1
        return $this->em->getRepository(Feedback::class)->findByProject($project);
26
    }
27
28
    /**
29
    * @param ProjectModel $project
30
    * @param UserInterface $author
31
    * @param array $orderBy
32
    * @param integer $limit
33
    * @param integer $offset
34
    * @return array
35
    */
36 1
    public function getProjectFeedbacksByAuthor(ProjectModel $project, UserInterface $author, $orderBy = null, $limit = null, $offset = null) {
37 1
        return $this->em->getRepository(Feedback::class)->findBy([
38 1
            'project' => $project,
39
            'author' => $author
40 1
        ], $orderBy, $limit, $offset);
41
    }
42
43
    /**
44
     * @param integer $id
45
     * @return FeedbackModel
46
     */
47 2
    public function getFeedback($id) {
48 2
        if(($feedback = $this->em->getRepository(Feedback::class)->find($id)) === null) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
49 1
            throw new NotFoundHttpException('Feedback not found');
50
        }
51 1
        return $feedback;
52
    }
53
54
    /**
55
     * @param ProjectModel $project
56
     * @param string $name
57
     * @param string $description
58
     * @param UserInterface $author
59
     * @return FeedbackModel
60
     */
61 1
    public function createFeedback(ProjectModel $project, $name, $description, UserInterface $author) {
62
        $feedback =
63 1
            (new Feedback())
64 1
            ->setName($name)
65 1
            ->setSlug($this->slugger->slugify($name))
66 1
            ->setDescription($description)
67 1
            ->setProject($project)
68 1
            ->setAuthor($author)
69 1
            ->setStatus(Feedback::STATUS_OPEN)
70 1
        ;
71 1
        $this->em->persist($feedback);
72 1
        $this->em->flush();
73 1
        return $feedback;
74
    }
75
76
    /**
77
     * @param ProjectModel $project
78
     * @param integer $status
79
     * @return integer
80
     */
81 1
    public function countFeedbacksPerStatus(ProjectModel $project, $status) {
82 1
        return $this->em->getRepository(Feedback::class)->countPerStatus($project, $status);
83
    }
84
}
85