AdminPageFrameworkLoader_FeedList   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 27
dl 0
loc 67
rs 10
c 0
b 0
f 0
ccs 0
cts 30
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A get() 0 29 5
1
<?php
2
/**
3
 * @package         Admin Page Framework Loader
4
 * @copyright       Copyright (c) 2013-2022, Michael Uno
5
 * @license         http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
 * @since           3.5.0
7
*/
8
9
/**
10
 * Retrieves an array of RSS feed items.
11
 */
12
class AdminPageFrameworkLoader_FeedList {
13
14
    /**
15
     * A container array that stores fetched feed items.
16
     */
17
    protected $_aFeedItems = array();
18
19
    /**
20
     * Stores the feed object.
21
     */
22
    protected $_oFeed;
23
24
25
    /**
26
     * Stores the target URLs.
27
     */
28
    protected $_aURLs = array();
29
30
    /**
31
     * Sets up properties.
32
     *
33
     * @param       array|string        $asURLs     A url of string or urls of array.
34
     */
35
    public function __construct( $asURLs ) {
36
37
        $this->_aURLs = is_array( $asURLs )
38
            ? $asURLs
39
            : ( empty( $asURLs )
40
                ? array()
41
                : ( array ) $asURLs
42
            );
43
44
    }
45
46
    /**
47
     *
48
     * @return      array
49
     */
50
    public function get( $iItems=0 ) {
51
52
        $_aOutput   = array();
53
        $_aURLs     = $this->_aURLs;
54
55
        if ( empty( $_aURLs ) ) {
56
            return $_aOutput;
57
        }
58
59
        $_oFeed     = fetch_feed( $_aURLs );
60
        if ( is_wp_error( $_oFeed ) ) {
61
            return $_aOutput;
62
        }
63
        foreach ( $_oFeed->get_items() as $_oItem ) {
64
            $_aOutput[ $_oItem->get_title() ] = array(
65
                'content'        => $_oItem->get_content(),
66
                'description'    => $_oItem->get_description(),
67
                'title'          => $_oItem->get_title(),
68
                'date'           => $_oItem->get_date( 'j F Y, g:i a' ),
69
                'author'         => $_oItem->get_author(),
70
                'link'           => $_oItem->get_permalink(),    // get_link() may be used as well
71
            );
72
        }
73
74
        if ( $iItems ) {
75
            array_splice( $_aOutput, $iItems );
76
        }
77
78
        return $_aOutput;
79
80
    }
81
82
}
83