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

FeedRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 44
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findHighestFrequencyValue() 0 9 1
A findOneByOriginAndReaderOptions() 0 16 1
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