Completed
Push — master ( 73f026...dc38fa )
by Sebastian
04:16
created

NewsItemDbRepository::findNext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace App\Repositories\Database;
4
5
use App\Foundation\Repositories\DbRepository;
6
use App\Models\NewsItem;
7
use App\Repositories\NewsItemRepository;
8
use Illuminate\Contracts\Pagination\Paginator;
9
use Illuminate\Support\Collection;
10
11
class NewsItemDbRepository extends DbRepository implements NewsItemRepository
12
{
13
    public function getAll() : Collection
14
    {
15
        return $this->query()
16
            ->orderBy('publish_date', 'desc')
17
            ->nonDraft()
18
            ->get();
19
    }
20
21
    public function getLatest(int $amount) : Collection
22
    {
23
        return $this->query()
24
            ->orderBy('publish_date', 'desc')
25
            ->online()
26
            ->take($amount)
27
            ->get();
28
    }
29
30
    /**
31
     * @return \App\Models\NewsItem|null
32
     */
33
    public function findNext(NewsItem $newsItem)
34
    {
35
        return $this->query()
36
            ->online()
37
            ->where('publish_date', '>', $newsItem->publish_date)
0 ignored issues
show
Documentation introduced by
The property publish_date does not exist on object<App\Models\NewsItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
            ->orderBy('publish_date', 'desc')
39
            ->first();
40
    }
41
42
    /**
43
     * @return \App\Models\NewsItem|null
44
     */
45
    public function findPrevious(NewsItem $newsItem)
46
    {
47
        return $this->query()
48
            ->online()
49
            ->where('publish_date', '<', $newsItem->publish_date)
0 ignored issues
show
Documentation introduced by
The property publish_date does not exist on object<App\Models\NewsItem>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
            ->orderBy('publish_date', 'desc')
51
            ->first();
52
    }
53
54
    public function paginate(int $perPage) : Paginator
55
    {
56
        return $this->query()
57
            ->online()
58
            ->simplePaginate($perPage);
59
    }
60
}
61