Completed
Push — master ( b03623...4b47de )
by Sebastian
07:26 queued 03:26
created

ArticleRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTopLevel() 0 6 1
A findByUrl() 0 6 1
A findSpecialArticle() 0 9 1
1
<?php
2
3
namespace App\Repositories;
4
5
use App\Models\Article;
6
use App\Models\Enums\SpecialArticle;
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Facades\Cache;
9
10
class ArticleRepository
11
{
12
    public static function getTopLevel(): Collection
13
    {
14
        return Article::where('parent_id', null)
15
            ->orderBy('order_column')
16
            ->get();
17
    }
18
19
    public static function findByUrl(string $url): Article
20
    {
21
        return Article::online()
22
            ->where('url->'.content_locale(), $url)
23
            ->firstOrFail();
24
    }
25
26
    public static function findSpecialArticle(SpecialArticle $specialArticle): Article
27
    {
28
        return Cache::rememberForever(
29
            "article.specialArticle.{$specialArticle}",
30
            function () use ($specialArticle) {
31
                return Article::where('technical_name', $specialArticle)->firstOrFail();
32
            }
33
        );
34
    }
35
}
36