CRSSFeed   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 28
ccs 21
cts 21
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getFeed() 0 14 2
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 10 and the first side effect is on line 11.

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 1
define('CACHE', __DIR__.'/../../webroot/cache/');
11 1
require_once(__DIR__."/simplepie/simplepie_1.3.1.mini.php");
12
13
class CRSSFeed {
14
	
15
  // constructor - initialize SimplePie.
16 2
  public function __construct($feedArr, $duration = 3600) {
17 2
      $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...
18 2
      $this->object->set_cache_location(CACHE);
19 2
      $this->object->set_cache_duration($duration);
20 2
      $this->object->set_feed_url($feedArr);
21 2
      $this->object->init();
22 2
	  $this->object->handle_content_type();
23 2
  }
24
25
  // return content. 
26 1
  public function getFeed() {
27 1
      $html = '<article>';
28 1
	  $html .= "<h1>Senaste nytt från IDG</h1>";
29 1
      foreach($this->object->get_items() as $content) {
30 1
          $html .= '<div class="feed-content">';
31 1
		  $html .= "<h2>" . $content->get_title() . "</h2>" ;
32 1
		  $html .= "<small>Postad ". $content->get_date('Y-m-d | H:i:s')."</small>";
33 1
          $html .= "<p>{$content->get_content()}</p>";
34 1
          $html .= "<p><a href='" . $content->get_permalink() . "'>Läs mer</a>";
35 1
          $html .= '</div>';
36 1
      }
37 1
      $html .= "</article>";
38 1
          return $html;
39
  }
40
}