Completed
Push — master ( e60a6a...7a7a1d )
by Mia
03:34 queued 12s
created

CRSSFeed::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 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
define('CACHE', __DIR__.'/../../webroot/cache/');
11
require_once(__DIR__."/simplepie/simplepie_1.3.1.mini.php");
12
13
class CRSSFeed {
14
  
15
  // constructor - initialize SimplePie.
16
  public function __construct($feedArr, $duration = 3600) {
17
      $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
      $this->object->set_cache_location(CACHE);
19
      $this->object->set_cache_duration($duration);
20
      $this->object->set_feed_url($feedArr);
21
      $this->object->init();
22
  }
23
24
  // return content. 
25
  public function getFeed() {
26
      $feedItems = $this->object->get_items();
27
      $html = '<article>';
28
	  $html .= "<h1>Senaste nytt fran IDG</h1>";
29
      foreach($feedItems as $content) {
30
          $html .= '<div class="feed-content">';
31
		  $html .= "<h2>" . $content->get_title() . "</h2>" ;
32
		  $html .= "<small>Postad ". $content->get_date('Y-m-d | H:i:s')."</small>";
33
          $html .= "<p>{$content->get_content()}</p>";
34
          $html .= "<p><a href='" . $content->get_permalink() . "'>Läs mer</a>";
35
          $html .= '</div>';
36
      }
37
      $html .= "</article>";
38
          return $html;
39
  }
40
} 
41
42
/*$rss = new SimplePie();
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
  $rss->get_items(1,1);
44
  $feed = new CRSSFeed($rss);
45
  if ($feed->getFeed()){
46
	  print "OK";
47
	  } 
48
	  */
49