Completed
Push — master ( 5d0790...aab733 )
by James
02:44
created

NewsHolder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 17 2
A getLumberjackTitle() 0 4 1
A getLumberjackPagesForGridfield() 0 7 1
A stageChildren() 0 4 1
A init() 0 5 1
1
<?php
2
3
class NewsHolder extends Page
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...
4
{
5
6
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
7
    {
8
        $intro = null;
9
10
        $this->beforeUpdateCMSFields(function ($fields) {
11
            $fields->renameField("Content", "Intro Content");
12
      $fields->insertBefore(new Tab($this->getLumberjackTitle()), 'Main');
13
        });
14
15
        $fields = parent::getCMSFields();
16
17
        if ($intro) {
18
            $intro->setRightTitle("Appears at the top of the main ".$this->Title." page, above the list of articles.");
19
        }
20
21
        return $fields;
22
    }
23
24
    public function getLumberjackTitle()
25
    {
26
        return "News Articles";
27
    }
28
    
29
    public function getLumberjackPagesForGridfield($excluded = array())
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
30
  	{
31
  			return NewsArticle::get()->filter(array(
32
  					'ParentID' => $this->ID,
33
  					'ClassName' => $excluded,
34
  			));
35
  	}
36
37
    // Only allows certain children to be created
38
    private static $allowed_children = array('NewsArticle');
0 ignored issues
show
Unused Code introduced by
The property $allowed_children is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
    private static $description = 'Holds News Article pages';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
    private static $icon = "basic-news/images/newspaper-page";
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
41
    
42
    public function stageChildren($showAll = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44
        return $this->__call('stageChildren', array($showAll))->sort(array('MenuTitle'=>'DESC', "Created"=>'DESC'));
45
    }
46
47
    public function init()
48
    {
49
        RSSFeed::linkToFeed($this->Link("rss"), "News RSS Feed");
50
        parent::init();
51
    }
52
}
53
54
55
class NewsHolder_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
56
{
57
58
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
59
        "rss"
60
    );
61
62 View Code Duplication
    public function init()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        RSSFeed::linkToFeed($this->Link() . "rss");
65
        if (Director::fileExists(project() . "/css/news.css")) {
66
            Requirements::css(project() . "/css/news.css");
67
        } else {
68
            Requirements::css("basic-news/css/news.css");
69
        }
70
71
        parent::init();
72
    }
73
    
74
    public function rss()
75
    {
76
        $config = SiteConfig::current_site_config();
77
        // Creates a new RSS Feed list
78
        $rss = new RSSFeed(
79
            $list = NewsArticle::get(), // an SS_List containing your feed items
80
            $link = $this->Link("rss"), // a HTTP link to this feed
81
            $title = $config->Title . " News", // title for this feed, displayed in RSS readers
82
            $description = "All the latest news from ". $config->Title . "." // description
83
        );
84
        // Outputs the RSS feed to the user.
85
        return $rss->outputToBrowser();
86
    }
87
    
88
    // Provides Paginated List of NewsArticles
89
    public function PaginatedPages()
90
    {
91
        $list = new PaginatedList(NewsArticle::get()->filter("ParentID", $this->ID), $this->request);
92
        $list->setPageLength(10);
93
        return $list;
94
    }
95
}
96