Passed
Push — master ( df5caf...cd5737 )
by Michael
02:02
created

Pictures   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
dl 0
loc 85
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
D getAllPictures() 0 30 9
A load() 0 8 2
A __construct() 0 18 3
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 44 and the first side effect is on line 33.

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
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
use Xmf\Request;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
/**
26
 * Protection against inclusion outside the site
27
 */
28
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
29
30
/**
31
 * Includes of form objects and uploader
32
 */
33
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
34
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
35
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
36
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
37
require_once XOOPS_ROOT_PATH . '/modules/adslight/class/Utility.php';
38
39
/**
40
 * light_pictures class.
41
 * $this class is responsible for providing data access mechanisms to the data source
42
 * of XOOPS user class objects.
43
 */
44
class Pictures extends XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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...
45
{
46
    public $db;
47
    // constructor
48
49
    /**
50
     * @param null       $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
51
     * @param null|array $lid
52
     */
53
    public function __construct($id = null, $lid = null)
54
    {
55
        $this->db = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
        $this->initVar('cod_img', XOBJ_DTYPE_INT, null, false, 10);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
57
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
        $this->initVar('date_added', XOBJ_DTYPE_TXTBOX, null, false);
59
        $this->initVar('date_modified', XOBJ_DTYPE_TXTBOX, null, false);
60
        $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 10);
61
        $this->initVar('uid_owner', XOBJ_DTYPE_TXTBOX, null, false);
62
        $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false);
63
        if (!empty($lid)) {
64
            if (is_array($lid)) {
0 ignored issues
show
introduced by
The condition is_array($lid) is always true.
Loading history...
65
                $this->assignVars($lid);
66
            } else {
67
                $this->load((int)$lid);
68
            }
69
        } else {
70
            $this->setNew();
71
        }
72
    }
73
74
    /**
75
     * @param $id
76
     */
77
    public function load($id)
78
    {
79
        global $moduleDirName;
80
        $sql   = 'SELECT * FROM ' . $this->db->prefix('adslight_pictures') . ' WHERE cod_img=' . $id . '';
81
        $myrow = $this->db->fetchArray($this->db->query($sql));
82
        $this->assignVars($myrow);
83
        if (!$myrow) {
84
            $this->setNew();
85
        }
86
    }
87
88
    /**
89
     * @param array  $criteria
90
     * @param bool   $asobject
91
     * @param string $sort
92
     * @param string $cat_order
93
     * @param int    $limit
94
     * @param int    $start
95
     * @return array
96
     * @internal   param string $order
97
     * @deprecated this should be handled through {@see PicturesHandler}
98
     */
99
    public function getAllPictures($criteria = [], $asobject = false, $sort = 'cod_img', $cat_order = 'ASC', $limit = 0, $start = 0)
100
    {
101
        global $moduleDirName;
102
        $db          = \XoopsDatabaseFactory::getDatabaseConnection();
103
        $ret         = [];
104
        $where_query = '';
105
        if (is_array($criteria) && count($criteria) > 0) {
106
            $where_query = ' WHERE';
107
            foreach ($criteria as $c) {
108
                $where_query .= " {$c} AND";
109
            }
110
            $where_query = substr($where_query, 0, -4);
111
        } elseif (!is_array($criteria) && $criteria) {
112
            $where_query = " WHERE {$criteria}";
113
        }
114
        if (!$asobject) {
115
            $sql    = 'SELECT cod_img FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order";
116
            $result = $db->query($sql, $limit, $start);
117
            while (false !== ($myrow = $db->fetchArray($result))) {
118
                $ret[] = $myrow['cog_img'];
119
            }
120
        } else {
121
            $sql    = 'SELECT * FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order";
122
            $result = $db->query($sql, $limit, $start);
123
            while (false !== ($myrow = $db->fetchArray($result))) {
124
                $ret[] = new Pictures($myrow);
125
            }
126
        }
127
128
        return $ret;
129
    }
130
}
131
132
// -------------------------------------------------------------------------
133
// ------------------light_pictures user handler class -------------------
134
// -------------------------------------------------------------------------
135