CRssfeed::readRSS()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 23
ccs 18
cts 18
cp 1
crap 2
rs 9.0856
c 0
b 0
f 0
1
<?php
2
namespace johe14\Rssfeed;
3
/**
4
 * A class to show a RSS-feed.
5
 *
6
 */
7
class CRssfeed { 
8
   
9
    /**
10
     * Properties
11
     *
12
     */ 
13
    private $options = array();
0 ignored issues
show
Unused Code introduced by
The property $options 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...
14
    private $url;
15
    private $heading;
16
    private $items;
17
     
18
    /**
19
     * Constructor
20
     *
21
     * @param array $options to alter the default behaviour.
22
     */
23 2
    public function __construct($options=array()) {
24 2
       $this->url = $options['url'];
25 2
       $this->heading = $options['heading']; 
26 2
       $this->items = $options['items'];
27 2
    }
28
	
29 1
    public function readRSS(){
30
    	
31 1
       $html = "<article>";
32 1
       $heading = $this->heading; 
33 1
       $html .= "<h1>$heading</h1>";
34 1
       $xml = simplexml_load_file($this->url);
35 1
       for($i = 0; $i < $this->items; $i++){
36 1
	       $title = $xml->channel->item[$i]->title;
37 1
	       $link = $xml->channel->item[$i]->link;
38 1
	       $description = $xml->channel->item[$i]->description;
39 1
	       $pubDate = $xml->channel->item[$i]->pubDate;
40
	       
41
	       // Formatting the date
42 1
           $pubDate= date("D, d M Y H:i:s T", strtotime($pubDate));
43
	       
44 1
           $html .= "<a href='$link'><h3>$title</h3></a>";
45 1
	       $html .= "<small>$pubDate</small><br /><br />";
46 1
           $html .= "$description";
47 1
           $html .= "<hr />";
48 1
       }
49 1
       $html .= "</article>";
50
           
51 1
       return $html;
52
    
53
    }      
54
     
55
}
56