FeedReaderPage::Items()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace eNTiDi\FeedReader;
4
5
use Page;
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Forms\NumericField;
8
use SilverStripe\Forms\TextField;
9
10
/**
11
 * Defines the FeedReaderPage page type.
12
 */
13
class FeedReaderPage extends Page
14
{
15
    private static $table_name = 'FeedReaderPage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
16
17
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
18
        'FeedUrl'    => 'Varchar(254)',
19
        'SummaryLen' => 'Int',
20
        'Expiration' => 'Int'
21
    ];
22
23
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
24
        'SummaryLen' => 255,
25
        'Expiration' => 3600,
26
    ];
27
28
    private $service;
29
30
31
    public function getCMSFields()
32
    {
33
        $t_FeedUrl    = _t(__CLASS__.'.FEED_URL', 'Feed URL');
34
        $t_SummaryLen = _t(__CLASS__.'.SUMMARY_LEN', 'Summary length');
35
        $d_SummaryLen = _t(__CLASS__.'.SUMMARY_LEN_COMMENT', 'Maximum length of the summary field (in bytes) when it is generated programmatically');
36
        $t_Expiration = _t(__CLASS__.'.EXPIRATION', 'Cache timeout');
37
        $d_Expiration = _t(__CLASS__.'.EXPIRATION_COMMENT', 'How many seconds a cached copy must be accessed instead of downloading the real feed');
38
39
        $fields = parent::getCMSFields();
40
        $fields->addFieldsToTab('Root.Feed', [
41
            TextField::create('FeedUrl', $t_FeedUrl),
0 ignored issues
show
Bug introduced by
'FeedUrl' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
            TextField::create(/** @scrutinizer ignore-type */ 'FeedUrl', $t_FeedUrl),
Loading history...
42
            NumericField::create('SummaryLen', $t_SummaryLen)
43
                ->setDescription($d_SummaryLen),
44
            NumericField::create('Expiration', $t_Expiration)
45
                ->setDescription($d_Expiration),
46
        ]);
47
        return $fields;
48
    }
49
50
    public function getService()
51
    {
52
        if (! $this->service) {
53
            $this->service = Injector::inst()->create(
54
                'eNTiDi\FeedReader\FeedReaderService',
55
                $this->FeedUrl,
56
                (int) $this->Expiration
57
            );
58
            $this->service->setSummaryLen($this->SummaryLen);
59
        }
60
        return $this->service;
61
    }
62
63
    public function Items($count = null)
64
    {
65
        $items = $this->getService()->getItems();
66
67
        // When $count is null, limit() will use array_slice(..., 0, null)
68
        // internally, meaning a clone of $items will be returned
69
        return $items->limit($count);
70
    }
71
}
72