TopicService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 27
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A majPositions() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ForumBundle\Service;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use ProjetNormandie\ForumBundle\Entity\Topic;
9
10
class TopicService
11
{
12
    private EntityManagerInterface $em;
13
14
    /**
15
     * TopicService constructor.
16
     * @param EntityManagerInterface $em
17
     */
18
    public function __construct(EntityManagerInterface $em)
19
    {
20
        $this->em = $em;
21
    }
22
23
24
    /**
25
     * @param Topic $topic
26
     */
27
    public function majPositions(Topic $topic): void
28
    {
29
        $list = $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\Message')
30
            ->findBy(['topic' => $topic], ['id' => 'ASC']);
31
        $i = 1;
32
        foreach ($list as $message) {
33
            $message->setPosition($i);
34
            $i++;
35
        }
36
        $this->em->flush();
37
    }
38
}
39