MetaBoxController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMetaBoxBySlugModel() 0 12 2
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Controllers;
4
5
use CSlant\Blog\Api\Services\MetaBoxService;
6
use CSlant\Blog\Api\Services\SlugService;
7
use CSlant\Blog\Core\Constants\AppConstant;
8
use Illuminate\Database\Eloquent\Model;
9
10
class MetaBoxController
11
{
12
    protected MetaBoxService $metaBoxService;
13
14
    protected SlugService $slugService;
15
16
    public function __construct(MetaBoxService $metaBoxService, SlugService $slugService)
17
    {
18
        $this->metaBoxService = $metaBoxService;
19
        $this->slugService = $slugService;
20
    }
21
22
    public function getMetaBoxBySlugModel(
23
        string $model,
24
        string $slug,
25
        string $lang = AppConstant::DEFAULT_LOCALE
26
    ): ?Model {
27
        $slugModel = $this->slugService->getSlugModel($slug, $model);
28
29
        if ($slugModel) {
30
            return $this->metaBoxService->getMetaBoxByModel($model, $slugModel->reference_id, $lang);
31
        }
32
33
        return null;
34
    }
35
}
36