NewsManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Manager\Project;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
7
use App\Entity\Project\{
8
    Project,
9
    News
10
};
11
12
class NewsManager
13
{
14
    /** @var EntityManagerInterface **/
15
    protected $em;
16
    
17
    public function __construct(EntityManagerInterface $em)
18
    {
19
        $this->em = $em;
20
    }
21
    
22
    public function getProjectNews(Project $project): array
23
    {
24
        return $this->em->getRepository(News::class)->findByProject($project, ['createdAt' => 'DESC']);
0 ignored issues
show
Bug introduced by
The method findByProject() does not exist on App\Repository\Project\NewsRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        return $this->em->getRepository(News::class)->/** @scrutinizer ignore-call */ findByProject($project, ['createdAt' => 'DESC']);
Loading history...
25
    }
26
    
27
    public function create(Project $project, string $category, array $data): News
28
    {
29
        $news =
30
            (new News())
31
            ->setProject($project)
32
            ->setCategory($category)
33
            ->setData($data)
34
        ;
35
        $this->em->persist($news);
36
        $this->em->flush();
37
        return $news;
38
    }
39
}