TopicService::majPositions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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