Completed
Push — master ( 4d2666...6cd91c )
by Phecho
06:30 queued 03:12
created

FeedController::feedAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 16
rs 9.4286
cc 3
eloc 9
nc 2
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 36 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of Gitamin.
5
 * 
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers;
13
14
use Gitamin\Facades\Setting;
15
use Gitamin\Models\Issue;
16
use Gitamin\Models\ProjectNamespace;
17
use GrahamCampbell\Markdown\Facades\Markdown;
18
use Illuminate\Routing\Controller;
19
use Illuminate\Support\Str;
20
use Roumen\Feed\Facades\Feed;
21
22
class FeedController extends Controller
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
23
{
24
    /**
25
    * Feed facade.
26
    *
27
    * @var Roumen\Feed\Facades\Feed
28
    */
29
    private $feed;
30
31
    /**
32
    * Create a new feed controller instance.
33
    *
34
    * @return void
35
    */
36
    public function __construct()
37
    {
38
        $this->feed = Feed::make();
39
        $this->feed->title = Setting::get('app_name');
40
        $this->feed->description = trans('gitamin.feed');
41
        $this->feed->link = Str::canonicalize(Setting::get('app_domain'));
42
        $this->feed->setDateFormat('datetime');
43
    }
44
45
    /**
46
     * Generates an Atom feed of all issues.
47
     *
48
     * @param \Gitamin\Models\ProjectTeam|null $namespace
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function atomAction(ProjectNamespace $namespace = null)
53
    {
54
        return $this->feedAction($namespace, false);
55
    }
56
57
    /**
58
     * Generates a Rss feed of all issues.
59
     *
60
     * @param \Gitamin\Models\ProjectTeam|null $group
61
     *
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function rssAction(ProjectNamespace $namespace = null)
65
    {
66
        $this->feed->lang = Setting::get('app_locale');
67
68
        return $this->feedAction($namespace, true);
69
    }
70
71
    /**
72
     * Generates a feed of all issues.
73
     *
74
     * @param \Gitamin\Models\ProjectTeam|null $namespace
75
     * @param bool                             $isRss
76
     *
77
     * @return \Illuminate\Http\Response
78
     */
79
    private function feedAction(ProjectNamespace &$namespace, $isRss)
80
    {
81
        if ($namespace->exists) {
82
            $namespace->projects->map(function ($project) {
83
                $project->issues()->visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) {
84
                    $this->feedAddItem($issue, $isRss);
85
                });
86
            });
87
        } else {
88
            Issue::visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) use ($isRss) {
89
                $this->feedAddItem($issue, $isRss);
90
            });
91
        }
92
93
        return $this->feed->render($isRss ? 'rss' : 'atom');
94
    }
95
96
    /**
97
     * Adds an item to the feed.
98
     *
99
     * @param \Gitamin\Models\Issue     $issue
100
     * @param bool                      $isRss
101
     */
102
    private function feedAddItem($issue, $isRss)
103
    {
104
        $this->feed->add(
105
            $issue->name,
106
            Setting::get('app_name'),
107
            Str::canonicalize(route('issue', ['id' => $issue->id])),
108
            $isRss ? $issue->created_at->toRssString() : $issue->created_at->toAtomString(),
109
            $isRss ? $issue->message : Markdown::convertToHtml($issue->message)
110
        );
111
    }
112
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected EOF, expecting T_FUNCTION
Loading history...