CwpAtomFeed::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 9
dl 0
loc 23
rs 9.9332
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace CWP\Core\Feed;
4
5
/**
6
 * CwpAtomFeed class
7
 *
8
 * This class is used to create an Atom feed.
9
 * @todo Improve documentation
10
 * @package cwp-core
11
 */
12
use SilverStripe\Control\Controller;
13
use SilverStripe\Control\RSS\RSSFeed;
14
use SilverStripe\Core\Convert;
15
use SilverStripe\ORM\FieldType\DBHTMLText;
16
use SilverStripe\ORM\SS_List;
17
use SilverStripe\View\Requirements;
18
19
class CwpAtomFeed extends RSSFeed
20
{
21
    public function __construct(
22
        SS_List $entries,
23
        $link,
24
        $title,
25
        $description = null,
26
        $titleField = "Title",
27
        $descriptionField = "Content",
28
        $authorField = null,
29
        $lastModified = null,
30
        $etag = null
31
    ) {
32
        parent::__construct(
33
            $entries,
34
            $link,
35
            $title,
36
            $description,
37
            $titleField,
38
            $descriptionField,
39
            $authorField,
40
            $lastModified
41
        );
42
43
        $this->setTemplate(__CLASS__);
44
    }
45
46
    /**
47
     * Include an link to the feed
48
     *
49
     * @param string $url URL of the feed
50
     * @param string $title Title to show
51
     */
52
    public static function linkToFeed($url, $title = null)
53
    {
54
        $title = Convert::raw2xml($title);
55
        Requirements::insertHeadTags(
56
            '<link rel="alternate" type="application/atom+xml" title="' . $title .
57
            '" href="' . $url . '" />'
58
        );
59
    }
60
61
    /**
62
     * Output the feed to the browser
63
     *
64
     * @return DBHTMLText
65
     */
66
    public function outputToBrowser()
67
    {
68
        $output = parent::outputToBrowser();
69
        $response = Controller::curr()->getResponse();
70
        $response->addHeader("Content-Type", "application/atom+xml");
71
72
        return $output;
73
    }
74
}
75