Completed
Push — master ( 46961e...b2acd3 )
by Axel
04:17 queued 01:11
created

FeedbackManager::getProjectFeedbacks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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