VendorsHandler::getVendorProductsCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace XoopsModules\Oledrion;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * oledrion
17
 *
18
 * @copyright   {@link https://xoops.org/ XOOPS Project}
19
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
21
 */
22
23
use XoopsModules\Oledrion;
24
25
/**
26
 * Gestion des vendeurs
27
 */
28
29
/**
30
 * Class VendorsHandler
31
 */
32
class VendorsHandler extends OledrionPersistableObjectHandler
33
{
34
    /**
35
     * VendorsHandler constructor.
36
     * @param \XoopsDatabase|null $db
37
     */
38
    public function __construct(\XoopsDatabase $db = null)
39
    {
40
        //                            Table               Classe          Id          Libellé
41
        parent::__construct($db, 'oledrion_vendors', Vendors::class, 'vendor_id', 'vendor_name');
0 ignored issues
show
Bug introduced by
It seems like $db can also be of type null; however, parameter $db of XoopsModules\Oledrion\Ol...tHandler::__construct() does only seem to accept XoopsDatabase, maybe add an additional type check? ( Ignorable by Annotation )

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

41
        parent::__construct(/** @scrutinizer ignore-type */ $db, 'oledrion_vendors', Vendors::class, 'vendor_id', 'vendor_name');
Loading history...
42
    }
43
44
    /**
45
     * Renvoie la liste de tous les vendeurs du module
46
     *
47
     * @param  Parameters $parameters
48
     * @return array               tableau d'objets de type vendors
49
     * @internal param int $start Position de départ
50
     * @internal param int $limit Nombre total d'enregistrements à renvoyer
51
     * @internal param string $order Champ sur lequel faire le tri
52
     * @internal param string $order Ordre du tri
53
     * @internal param bool $idaskey Indique si le tableau renvoyé doit avoir pour clé l'identifiant unique de l'enregistrement
54
     */
55
    public function getAllVendors(Parameters $parameters)
56
    {
57
        $parameters = $parameters->extend(new Oledrion\Parameters([
58
                                                                      'start'   => 0,
59
                                                                      'limit'   => 0,
60
                                                                      'sort'    => 'vendor_name',
61
                                                                      'order'   => 'ASC',
62
                                                                      'idaskey' => true,
63
                                                                  ]));
64
        $critere    = new \Criteria('vendor_id', 0, '<>');
65
        $critere->setLimit($parameters['limit']);
66
        $critere->setStart($parameters['start']);
67
        $critere->setSort($parameters['sort']);
68
        $critere->setOrder($parameters['order']);
69
        $categories = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $categories is dead and can be removed.
Loading history...
70
        $categories = $this->getObjects($critere, $parameters['idaskey']);
71
72
        return $categories;
73
    }
74
75
    /**
76
     * Retourne le nombre de produits associés à un vendeur
77
     *
78
     * @param int $vendor_id L'ID du vendeur
79
     * @return int Le nombre de produits du vendeur
80
     */
81
    public function getVendorProductsCount($vendor_id)
82
    {
83
        global $productsHandler;
84
85
        return $productsHandler->getVendorProductsCount($vendor_id);
86
    }
87
88
    /**
89
     * Supprime un vendeur
90
     *
91
     * @param  Vendors $vendor
92
     * @return bool          Le résultat de la suppression
93
     */
94
    public function deleteVendor(Vendors $vendor)
95
    {
96
        return $this->delete($vendor, true);
97
    }
98
99
    /**
100
     * Retourne des vendeurs selon leur ID
101
     *
102
     * @param  array $ids Les ID des vendeurs à retrouver
103
     * @return array Objets de type Vendors
104
     */
105
    public function getVendorsFromIds($ids)
106
    {
107
        $ret = [];
108
        if ($ids && is_array($ids)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $ids of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
109
            $criteria = new \Criteria('vendor_id', '(' . implode(',', $ids) . ')', 'IN');
110
            $ret      = $this->getObjects($criteria, true, true, '*', false);
0 ignored issues
show
Unused Code introduced by
The call to XoopsPersistableObjectHandler::getObjects() has too many arguments starting with '*'. ( Ignorable by Annotation )

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

110
            /** @scrutinizer ignore-call */ 
111
            $ret      = $this->getObjects($criteria, true, true, '*', false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
111
        }
112
113
        return $ret;
114
    }
115
}
116