PhotoRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A reorderPhotos() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Repository;
6
7
use App\Entity\Photo;
8
use App\Entity\Property;
9
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
10
use Doctrine\Persistence\ManagerRegistry;
11
12
/**
13
 * @method Photo|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method Photo|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method Photo[]    findAll()
16
 * @method Photo[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
final class PhotoRepository extends ServiceEntityRepository
19
{
20
    public function __construct(ManagerRegistry $registry)
21
    {
22
        parent::__construct($registry, Photo::class);
23
    }
24
25
    public function reorderPhotos(Property $property, array $ids): void
26
    {
27
        $i = 1;
28
29
        foreach ($ids as $id) {
30
            $this->createQueryBuilder('i')
31
                ->update('App\Entity\Photo', 'p')
32
                ->set('p.sort_order', $i)
33
                ->where('p.id = ?1')
34
                ->andWhere('p.property = ?2')
35
                ->setParameter(1, $id)
36
                ->setParameter(2, $property->getId())
37
                ->getQuery()
38
                ->execute();
39
40
            ++$i;
41
        }
42
    }
43
}
44