Failed Conditions
Push — master ( 34a070...6c283c )
by Adrien
05:56
created

ImageRepository::getFilenamesForDimensionUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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