Completed
Push — master ( 00e474...9d3fbd )
by Michael
04:26
created

RssfitOledrion   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadModule() 0 10 3
B grabEntries() 0 29 5
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 27 and the first side effect is on line 21.

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link http://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
if (!defined('RSSFIT_ROOT_PATH')) {
21
    exit();
22
}
23
24
/**
25
 * Class RssfitOledrion
26
 */
27
class RssfitOledrion
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
28
{
29
    public $dirname = 'oledrion';
30
    public $modname;
31
    public $grab;
32
33
    /**
34
     * RssfitOledrion constructor.
35
     */
36
    public function __construct()
37
    {
38
    }
39
40
    /**
41
     * @return bool
42
     */
43
    public function loadModule()
0 ignored issues
show
Coding Style introduced by
loadModule uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
44
    {
45
        $mod = $GLOBALS['moduleHandler']->getByDirname($this->dirname);
46
        if (!$mod || !$mod->getVar('isactive')) {
47
            return false;
48
        }
49
        $this->modname = $mod->getVar('name');
50
51
        return $mod;
52
    }
53
54
    /**
55
     * @param $obj
56
     * @return bool
57
     */
58
    public function grabEntries($obj)
59
    {
60
        $ret = false;
61
        include XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
62
        $items = $h_oledrion_products->getRecentProducts(new Oledrion_parameters(array(
0 ignored issues
show
Bug introduced by
The variable $h_oledrion_products does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
63
                                                                                     'start' => 0,
64
                                                                                     'limit' => $this->grab
65
                                                                                 )));
66
        $i     = 0;
67
68
        if (false !== $items && count($items) > 0) {
69
            foreach ($items as $item) {
70
                $ret[$i]['link']      = $ret[$i]['guid'] = $item->getLink();
71
                $ret[$i]['title']     = $item->getVar('product_title', 'n');
72
                $ret[$i]['timestamp'] = $item->getVar('product_submitted');
73
                if (xoops_trim($item->getVar('product_summary')) != '') {
74
                    $description = $item->getVar('product_summary');
75
                } else {
76
                    $description = $item->getVar('product_description');
77
                }
78
                $ret[$i]['description'] = $description;
79
                $ret[$i]['category']    = $this->modname;
80
                $ret[$i]['domain']      = XOOPS_URL . '/modules/' . $this->dirname . '/';
81
                ++$i;
82
            }
83
        }
84
85
        return $ret;
86
    }
87
}
88