TimelineService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimelineSearchResults() 0 3 1
A getTimelineEntries() 0 6 1
A getTimelineService() 0 7 2
A getTimelineEntry() 0 3 1
1
<?php
2
3
namespace Osnova\Services\Timeline\Traits;
4
5
use Osnova\Api\ApiProvider;
6
use Osnova\Services\Timeline\Entry;
7
use Osnova\Services\Timeline\Interfaces\TimelineOwnerInterface;
8
use Osnova\Services\Timeline\Requests\TimelineRequest;
9
use Osnova\Services\Timeline\Timeline;
10
11
trait TimelineService
12
{
13
    /** @var Timeline|null */
14
    private $timeline;
15
16
    /**
17
     * Get the resource API Provider instance.
18
     *
19
     * @return ApiProvider
20
     */
21
    abstract public function getApiProvider();
22
23
    /**
24
     * Get the timeline service instance.
25
     *
26
     * @return Timeline
27
     */
28
    public function getTimelineService()
29
    {
30
        if (is_null($this->timeline)) {
31
            return $this->timeline = new Timeline($this->getApiProvider());
32
        }
33
34
        return $this->timeline;
35
    }
36
37
    /**
38
     * Get timeline entries list.
39
     * This is a proxy method for Timeline::getTimeline().
40
     *
41
     * @param TimelineOwnerInterface $owner   Timeline owner.
42
     * @param TimelineRequest        $request = null Timeline request parameters.
43
     *
44
     * @see Timeline::getTimeline()
45
     *
46
     * @return array|Entry[]
47
     */
48
    public function getTimelineEntries(TimelineOwnerInterface $owner, TimelineRequest $request = null)
49
    {
50
        return $this->getTimelineService()->getTimeline(
51
            $owner,
52
            $request ?? new TimelineRequest(),
53
            $this
0 ignored issues
show
Bug introduced by
$this of type Osnova\Services\Timeline\Traits\TimelineService is incompatible with the type Osnova\OsnovaResource|null expected by parameter $resource of Osnova\Services\Timeline\Timeline::getTimeline(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
            /** @scrutinizer ignore-type */ $this
Loading history...
54
        );
55
    }
56
57
    /**
58
     * Get timeline search results.
59
     * This is a proxy method for Timeline::getTimelineSearchResults().
60
     *
61
     * @param string $query   Query string.
62
     * @param string $orderBy Ordering method (`relevant` or `date`).
63
     * @param int    $page    = 1 Results page.
64
     *
65
     * @see Timeline::getTimelineSearchResults()
66
     *
67
     * @return array|Entry[]
68
     */
69
    public function getTimelineSearchResults(string $query, string $orderBy = 'relevant', int $page = 1)
70
    {
71
        return $this->getTimelineService()->getTimelineSearchResults($query, $orderBy, $page, $this);
0 ignored issues
show
Bug introduced by
$this of type Osnova\Services\Timeline\Traits\TimelineService is incompatible with the type Osnova\OsnovaResource|null expected by parameter $resource of Osnova\Services\Timeline...TimelineSearchResults(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
        return $this->getTimelineService()->getTimelineSearchResults($query, $orderBy, $page, /** @scrutinizer ignore-type */ $this);
Loading history...
72
    }
73
74
    /**
75
     * Get timeline entry by ID.
76
     * This is a proxy method for Timeline::getTimelineEntry().
77
     *
78
     * @param int $id Entry ID.
79
     *
80
     * @see Timeline::getTimeline()
81
     *
82
     * @return Entry|null
83
     */
84
    public function getTimelineEntry($id)
85
    {
86
        return $this->getTimelineService()->getTimelineEntry($id, $this);
0 ignored issues
show
Bug introduced by
$this of type Osnova\Services\Timeline\Traits\TimelineService is incompatible with the type Osnova\OsnovaResource|null expected by parameter $resource of Osnova\Services\Timeline...ine::getTimelineEntry(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

86
        return $this->getTimelineService()->getTimelineEntry($id, /** @scrutinizer ignore-type */ $this);
Loading history...
87
    }
88
}
89