Completed
Push — master ( 723e15...20e580 )
by Mia
03:35
created

CRSSFeed::getFeed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 13
nc 2
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * A factory wrapper for creating  objects of external RSS libs.
4
 * 
5
 */
6
7
namespace Miax\RSSFeed;
8
use SimplePie;
9
10
//change the cache directory to wherever you want it
11
define('CACHE', __DIR__.'/../webroot/cache/');
12
13
require_once(__DIR__."/simplepie/simplepie_1.3.1.mini.php");
14
15
class CRSSFeed {
16
  
17
  // constructor - initialize SimplePie.
18
  public function __construct($feedArr, $duration = 3600) {
19
      $this->object = new SimplePie();
0 ignored issues
show
Bug introduced by
The property object does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
      $this->object->set_cache_location(CACHE);
21
      $this->object->set_cache_duration($duration);
22
      $this->object->set_feed_url($feedArr);
23
      $this->object->init();
24
  }
25
26
  // return content. 
27
  public function getFeed() {
28
      $feedItems = $this->object->get_items();
29
      $html = "<article>";
30
	    $html .= "<h1>Senaste nytt från IDG</h1>"; //change this to your own headline
31
      foreach($feedItems as $content) {
32
          $html .= "<div class='feed-content'>";
33
		  $html .= "<h2>" . $content->get_title() . "</h2>" ;
34
		  $html .= "<small>Postad ". $content->get_date('Y-m-d | H:i:s')."</small>";
35
          $html .= "<p>" . $content->get_content() . "</p>";
36
          $html .= "<p><a href=" . $content->get_permalink() . ">Läs mer</a>";
37
          $html .= "</div>";
38
      }
39
      $html .= "</article>";
40
          return $html;
41
  }
42
} 
43