Completed
Pull Request — master (#34)
by Cas
08:40
created

FeedRepository::findHighestFrequencyValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace TreeHouse\IoBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class FeedRepository extends EntityRepository
8
{
9
    /**
10
     * Returns the highest frequency value, meaning the actual value: the
11
     * frequency is stored as number of hours, so a higher number actually means
12
     * a smaller frequency.
13
     *
14
     * @return int
15
     */
16
    public function findHighestFrequencyValue()
17
    {
18
        return $this
19
            ->createQueryBuilder('f')
20
            ->select('MAX(f.frequency)')
21
            ->getQuery()
22
            ->getSingleScalarResult()
23
        ;
24
    }
25
26
    /**
27
     * Returns a feed that matches the given origin and reader options
28
     *
29
     * @param int $originId
30
     * @param array $readerOptions
31
     *
32
     * @return Feed|null
33
     */
34
    public function findOneByOriginAndReaderOptions(
35
        $originId,
36
        array $readerOptions
37
    ) {
38
        return $this
39
            ->createQueryBuilder('f')
40
            ->where('f.origin = :origin')
41
            ->andWhere('f.readerOptions = :readerOptions')
42
            ->setParameters([
43
                'origin' => $originId,
44
                'readerOptions' => json_encode($readerOptions),
45
            ])
46
            ->getQuery()
47
            ->getOneOrNullResult()
48
        ;
49
    }
50
}
51