PostController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
use Flaviozantut\Storage\Posts\PostRepositoryInterface;
4
5
class PostController extends \BaseController
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7 1
    public function __construct(PostRepositoryInterface $post)
8
    {
9 1
        $this->post = $post;
10 1
    }
11
12
    /**
13
     * Display a listing of the resource.
14
     *
15
     * @return Response
16
     */
17 1
    public function articles()
18
    {
19 1
        $current = Input::get('page', 1) - 1;
20 1
        $articles = array_chunk($this->post->all('article'), Config::get('skorry.paginate'));
21 1
        if (!count($articles)) {
22 1
            $data = (new \Parsedown())->parse(\File::get(base_path().'/readme.md'));
23
24 1
            return View::make('hello', compact('data'));
25
        }
26
        if (!array_key_exists($current, $articles)) {
27
            App::abort(404);
28
        }
29
        $articles = $articles[$current];
30
        $paginator = Paginator::make($articles, count($this->post->all('article')), Config::get('skorry.paginate'));
31
32
        return View::make('posts.articles', compact('articles', 'paginator'));
33
    }
34
35
    public function get($type, $permalink)
36
    {
37
        $article = $this->post->find(['permalink' => $permalink]);
38
39
        if ($article->type != $type) {
40
            App::abort(404);
41
        }
42
43
        return View::make('posts.post', compact('article'));
44
    }
45
}
46