Passed
Branch feature/v2 (61dd95)
by Valentin
05:53
created

StatisticsSource   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findExtract() 0 15 2
A findByEventNameAndDatetime() 0 7 1
1
<?php
2
3
namespace Spiral\Statistics\Database\Sources;
4
5
use Spiral\Database\Builders\Prototypes\AbstractSelect;
6
use Spiral\Database\Injections\Parameter;
7
use Spiral\ORM\Entities\RecordSelector;
8
use Spiral\ORM\Entities\RecordSource;
9
use Spiral\Statistics\Database\Statistics;
10
11
class StatisticsSource extends RecordSource
12
{
13
    const RECORD = Statistics::class;
14
15
    /**
16
     * @param \DateTimeInterface $start
17
     * @param \DateTimeInterface $end
18
     * @param array              $events
19
     * @return RecordSelector
20
     */
21
    public function findExtract(
22
        \DateTimeInterface $start,
23
        \DateTimeInterface $end,
24
        array $events
25
    ): RecordSelector
26
    {
27
        $selector = $this->find()
28
            ->where('timestamp', 'between', $start, $end);
0 ignored issues
show
Unused Code introduced by
The call to RecordSelector::where() has too many arguments starting with 'between'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
30
        if (!empty($events)) {
31
            $selector->where('name', 'IN', new Parameter($events));
0 ignored issues
show
Unused Code introduced by
The call to RecordSelector::where() has too many arguments starting with 'IN'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
32
        }
33
34
        return $selector->orderBy('timestamp', AbstractSelect::SORT_ASC);
35
    }
36
37
    /**
38
     * @param string             $name
39
     * @param \DateTimeInterface $datetime
40
     * @return null|Statistics
41
     */
42
    public function findByEventNameAndDatetime(string $name, \DateTimeInterface $datetime)
43
    {
44
        return $this->findOne([
45
            'name'      => $name,
46
            'timestamp' => $datetime
47
        ]);
48
    }
49
}