Passed
Push — master ( 05cb95...eed2c7 )
by Michael
02:06
created

Pictures::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 18
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace XoopsModules\Adslight;
4
5
/*
6
-------------------------------------------------------------------------
7
                     ADSLIGHT 2 : Module for Xoops
8
9
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
10
        Started with the Classifieds module and made MANY changes
11
        Website : http://www.luc-bizet.fr
12
        Contact : [email protected]
13
-------------------------------------------------------------------------
14
             Original credits below Version History
15
##########################################################################
16
#                    Classified Module for Xoops                         #
17
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
18
#      Started with the MyAds module and made MANY changes               #
19
##########################################################################
20
 Original Author: Pascal Le Boustouller
21
 Author Website : [email protected]
22
 Licence Type   : GPL
23
-------------------------------------------------------------------------
24
*/
25
26
/**
27
 * Protection against inclusion outside the site
28
 */
29
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
30
31
/**
32
 * Includes of form objects and uploader
33
 */
34
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
35
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
36
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
37
require_once XOOPS_ROOT_PATH . '/kernel/object.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
45
{
46
    /** @var \XoopsMySQLDatabase $db */
47
    public $db;
48
    // constructor
49
50
    /**
51
     * @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...
52
     * @param null|array $lid
53
     */
54
    public function __construct($id = null, $lid = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public function __construct(/** @scrutinizer ignore-unused */ $id = null, $lid = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        $this->db = \XoopsDatabaseFactory::getDatabaseConnection();
57
        $this->initVar('cod_img', XOBJ_DTYPE_INT, null, false, 10);
58
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false);
59
        $this->initVar('date_added', XOBJ_DTYPE_TXTBOX, null, false);
60
        $this->initVar('date_modified', XOBJ_DTYPE_TXTBOX, null, false);
61
        $this->initVar('lid', XOBJ_DTYPE_INT, null, false, 10);
62
        $this->initVar('uid_owner', XOBJ_DTYPE_TXTBOX, null, false);
63
        $this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false);
64
        if (!empty($lid)) {
65
            if (is_array($lid)) {
0 ignored issues
show
introduced by
The condition is_array($lid) is always true.
Loading history...
66
                $this->assignVars($lid);
67
            } else {
68
                $this->load((int)$lid);
69
            }
70
        } else {
71
            $this->setNew();
72
        }
73
    }
74
75
    /**
76
     * @param $id
77
     */
78
    public function load($id)
79
    {
80
        global $moduleDirName;
81
        $sql   = 'SELECT * FROM ' . $this->db->prefix('adslight_pictures') . ' WHERE cod_img=' . $id . ' ';
82
        $myrow = $this->db->fetchArray($this->db->query($sql));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->db->query($sql) targeting XoopsMySQLDatabase::query() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
83
        $this->assignVars($myrow);
84
        if (!$myrow) {
85
            $this->setNew();
86
        }
87
    }
88
89
    /**
90
     * @param array  $criteria
91
     * @param bool   $asobject
92
     * @param string $sort
93
     * @param string $cat_order
94
     * @param int    $limit
95
     * @param int    $start
96
     * @return array
97
     * @internal   param string $order
98
     * @deprecated this should be handled through {@see PicturesHandler}
99
     */
100
    public function getAllPictures($criteria = [], $asobject = false, $sort = 'cod_img', $cat_order = 'ASC', $limit = 0, $start = 0)
101
    {
102
        global $moduleDirName;
103
        /** @var \XoopsMySQLDatabase $db */
104
        $db          = \XoopsDatabaseFactory::getDatabaseConnection();
105
        $ret         = [];
106
        $where_query = '';
107
        if (is_array($criteria) && count($criteria) > 0) {
108
            $where_query = ' WHERE';
109
            foreach ($criteria as $c) {
110
                $where_query .= " {$c} AND";
111
            }
112
            $where_query = mb_substr($where_query, 0, -4);
113
        } elseif (!is_array($criteria) && $criteria) {
114
            $where_query = " WHERE {$criteria}";
115
        }
116
        if (!$asobject) {
117
            $sql    = 'SELECT cod_img FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order";
118
            $result = $db->query($sql, $limit, $start);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $db->query($sql, $limit, $start) targeting XoopsMySQLDatabase::query() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
119
            while (false !== ($myrow = $db->fetchArray($result))) {
120
                $ret[] = $myrow['cog_img'];
121
            }
122
        } else {
123
            $sql    = 'SELECT * FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order";
124
            $result = $db->query($sql, $limit, $start);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $db->query($sql, $limit, $start) targeting XoopsMySQLDatabase::query() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
125
            while (false !== ($myrow = $db->fetchArray($result))) {
126
                $ret[] = new self($myrow);
127
            }
128
        }
129
130
        return $ret;
131
    }
132
}
133
134
// -------------------------------------------------------------------------
135
// ------------------light_pictures user handler class -------------------
136
// -------------------------------------------------------------------------
137