Passed
Push — master ( a8b983...5b3176 )
by Adrien
10:48
created

ImageRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 35
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilenames() 0 9 1
A getFilenamesForDimensionUpdate() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use PDO;
8
9
class ImageRepository extends AbstractRepository
10
{
11
    /**
12
     * Returns all unique filename in DB
13
     *
14
     * @return string[]
15
     */
16
    public function getFilenames(): array
17
    {
18
        $filenames = $this->getEntityManager()->getConnection()->createQueryBuilder()
19
            ->from('image')
20
            ->select('DISTINCT CONCAT("data/images/", filename)')
21
            ->where('filename != ""')
22
            ->orderBy('filename')->execute()->fetchAll(PDO::FETCH_COLUMN);
23
24
        return $filenames;
25
    }
26
27
    /**
28
     * Returns all filename in DB and their id and sizes
29
     *
30
     * @return string[]
31
     */
32
    public function getFilenamesForDimensionUpdate(): array
33
    {
34
        $filenames = $this->getEntityManager()->getConnection()->createQueryBuilder()
35
            ->from('image')
36
            ->addSelect('id')
37
            ->addSelect('width')
38
            ->addSelect('height')
39
            ->addSelect('CONCAT("data/images/", filename) AS filename')
40
            ->where('filename != ""')
41
            ->orderBy('filename')->execute()->fetchAll();
42
43
        return $filenames;
44
    }
45
}
46