ArticleRepository::getTopLevel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace App\Repositories;
4
5
use Exception;
6
use App\Models\Article;
7
use Illuminate\Support\Collection;
8
use App\Models\Enums\SpecialArticle;
9
use Illuminate\Support\Facades\Cache;
10
11
class ArticleRepository
12
{
13
    public static function getTopLevel(): Collection
14
    {
15
        return Article::where('parent_id', null)
16
            ->orderBy('order_column')
17
            ->get();
18
    }
19
20
    public static function findBySlug(string $slug): Article
21
    {
22
        $article = Article::where('slug->'.content_locale(), $slug)
23
            ->first();
24
25
        abort_unless($article, 404);
26
27
        return $article;
28
    }
29
30
    public static function findSpecialArticle(string $specialArticle): Article
31
    {
32
        return Cache::rememberForever(
33
            "article.specialArticle.{$specialArticle}",
34
            function () use ($specialArticle) {
35
                $article = Article::where('technical_name', $specialArticle)->first();
36
37
                if (! $article) {
38
                    throw new Exception("There is no article with technical_name `{$specialArticle}`");
39
                }
40
41
                return $article;
42
            }
43
        );
44
    }
45
}
46