Issues (324)

src/Manager/Community/NewsManager.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Manager\Community;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
7
use App\Entity\Community\{
8
    Community,
9
    News
10
};
11
12
class NewsManager
13
{
14
    /** @var EntityManagerInterface **/
15
    protected $em;
16
    
17 1
    public function __construct(EntityManagerInterface $em)
18
    {
19 1
        $this->em = $em;
20 1
    }
21
    
22
    public function getCommunityNews(Community $community): array
23
    {
24
        return $this->em->getRepository(News::class)->findByCommunity($community, ['createdAt' => 'DESC']);
0 ignored issues
show
The method findByCommunity() does not exist on App\Repository\Community\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 */ findByCommunity($community, ['createdAt' => 'DESC']);
Loading history...
25
    }
26
    
27 1
    public function create(Community $community, string $category, array $data): News
28
    {
29
        $news =
30 1
            (new News())
31 1
            ->setCommunity($community)
32 1
            ->setCategory($category)
33 1
            ->setData($data)
34
        ;
35 1
        $this->em->persist($news);
36 1
        $this->em->flush();
37 1
        return $news;
38
    }
39
}