PostController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 42.86%
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 41
ccs 9
cts 21
cp 0.4286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A articles() 0 17 3
A get() 0 10 2
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