Passed
Branch 0.2 (92feb3)
by Lars
03:29
created

BlogController::getBlog()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Blog;
6
use App\BlogArticle;
7
use App\Helper\FormatHelper;
8
9
/**
10
 * Class BlogController
11
 * @package App\Http\Controllers
12
 */
13
class BlogController extends Controller
14
{
15
    public function index()
16
    {
17
        return FormatHelper::formatData(Blog::all());
18
    }
19
20
    public function getBlogWithArticles($blogHash)
21
    {
22
        $blog = new Blog();
23
        $blogResult = $blog->where("hash", $blogHash)->first();
24
25
        if ($blogResult != null) {
26
            $blogArticle = new BlogArticle();
27
            $blogResult["articles"] = $blogArticle->where("blogHash", $blogHash)->orderBy("created_at")->get();
28
29
            return FormatHelper::formatData($blogResult);
30
        } else {
31
            return FormatHelper::formatData(array("errorCode" => "not-found"), false, 404);
32
        }
33
    }
34
35
    public function getArticle($articleHash)
36
    {
37
        $article = new BlogArticle();
38
        $articleResult = $article->where("hash", $articleHash)->first();
39
40
        if ($articleResult != null) {
41
            return FormatHelper::formatData($articleResult);
42
        } else {
43
            return FormatHelper::formatData(array("errorCode" => "not-found"), false, 404);
44
        }
45
    }
46
}