Completed
Push — master ( 6e53b7...20f57d )
by Phecho
06:11 queued 02:59
created

FeedController::atomAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
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\ProjectTeam;
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
23
{
24
    /**
25
    * Instance of Feed.
26
    *
27
    * @var Roumen\Feed\Facades\Feed
28
    */
29
    private $feed;
30
31
    /**
32
    * Whether it is a RSS Feed.
33
    *
34
    * @var bool
35
    */
36
    private $isRss;
37
38
    /**
39
    * Create a new feed controller instance.
40
    *
41
    * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
42
    */
43
    public function __construct()
44
    {
45
        $this->feed = Feed::make();
46
        $this->feed->title = Setting::get('app_name');
47
        $this->feed->description = trans('gitamin.feed');
48
        $this->feed->link = Str::canonicalize(Setting::get('app_domain'));
49
        $this->feed->setDateFormat('datetime');
50
    }
51
52
    /**
53
     * Generates an Atom feed of all issues.
54
     *
55
     * @param \Gitamin\Models\ProjectTeam|null $group
56
     *
57
     * @return \Illuminate\Http\Response
58
     */
59
    public function atomAction(ProjectTeam $group = null)
60
    {
61
        $this->isRss = false;
62
63
        return $this->feedAction($group);
64
    }
65
66
    /**
67
     * Generates an Rss feed of all issues.
68
     *
69
     * @param \Gitamin\Models\ProjectTeam|null $group
70
     *
71
     * @return \Illuminate\Http\Response
72
     */
73
    public function rssAction(ProjectTeam $group = null)
74
    {
75
        $this->isRss = true;
76
        $this->feed->lang = Setting::get('app_locale');
77
78
        return $this->feedAction($group);
79
    }
80
81
    /**
82
     * Generates an Atom feed of all issues.
83
     *
84
     * @param \Gitamin\Models\ProjectTeam|null $group
85
     *
86
     * @return \Illuminate\Http\Response
87
     */
88
    public function feedAction(ProjectTeam $group = null)
89
    {
90
        if ($group->exists) {
91
            $group->projects->map(function ($project) {
0 ignored issues
show
Documentation introduced by
The property projects does not exist on object<Gitamin\Models\ProjectTeam>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
92
                $project->issues()->visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) {
93
                    $this->feedAddItem($issue);
94
                });
95
            });
96
        } else {
97
            Issue::visible()->orderBy('created_at', 'desc')->get()->map(function ($issue) {
0 ignored issues
show
Bug introduced by
The method visible() does not exist on Gitamin\Models\Issue. Did you maybe mean scopeVisible()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
98
                $this->feedAddItem($issue);
99
            });
100
        }
101
102
        return $this->feed->render($this->isRss ? 'rss' : 'atom');
103
    }
104
105
    /**
106
     * Adds an item to the feed.
107
     *
108
     * @param \Gitamin\Models\Issue     $issue
109
     */
110
    private function feedAddItem($issue)
111
    {
112
        $this->feed->add(
113
            $issue->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Gitamin\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
114
            Setting::get('app_name'),
115
            Str::canonicalize(route('issue', ['id' => $issue->id])),
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Gitamin\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
116
            $this->isRss ? $issue->created_at->toRssString() : $issue->created_at->toAtomString(),
0 ignored issues
show
Documentation introduced by
The property created_at does not exist on object<Gitamin\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
117
            $this->isRss ? $issue->message : Markdown::convertToHtml($issue->message)
0 ignored issues
show
Documentation introduced by
The property message does not exist on object<Gitamin\Models\Issue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
        );
119
    }
120
}
121