RelatedHandler::updatePercent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
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
/**
24
 * Gestion des produits relatifs
25
 */
26
27
use XoopsModules\Oledrion;
28
29
/**
30
 * Class RelatedHandler
31
 */
32
class RelatedHandler extends OledrionPersistableObjectHandler
33
{
34
    /**
35
     * RelatedHandler constructor.
36
     * @param \XoopsDatabase|null $db
37
     */
38
    public function __construct(\XoopsDatabase $db = null)
39
    {
40
        //                            Table               Classe                   Id
41
        parent::__construct($db, 'oledrion_related', Related::class, 'related_id');
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_related', Related::class, 'related_id');
Loading history...
42
    }
43
44
    /**
45
     * Supprime les produits relatifs rattachés à un produit
46
     *
47
     * @param int $related_product_id L'identifiant du produit pour lequel il faut faire la suppression
48
     */
49
    public function deleteProductRelatedProducts($related_product_id)
50
    {
51
        $criteria = new \Criteria('related_product_id', $related_product_id, '=');
52
        $this->deleteAll($criteria);
53
    }
54
55
    /**
56
     * Retourne la liste des produits relatifs d'une liste de produits
57
     *
58
     * @param  array $ids Les ID des produits dont on recherche les produits relatifs
59
     * @return array Objets de type Related
60
     */
61
    public function getRelatedProductsFromProductsIds($ids)
62
    {
63
        $ret = [];
64
        if (is_array($ids)) {
0 ignored issues
show
introduced by
The condition is_array($ids) is always true.
Loading history...
65
            $criteria = new \Criteria('related_product_id', '(' . implode(',', $ids) . ')', 'IN');
66
            $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

66
            /** @scrutinizer ignore-call */ 
67
            $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...
67
        }
68
69
        return $ret;
70
    }
71
72
    /**
73
     * Update product percent
74
     *
75
     * @param $id
76
     * @param $related
77
     * @param $percent
78
     * @return bool
79
     * @internal param $
80
     */
81
    public function updatePercent($id, $related, $percent)
82
    {
83
        if ($percent > 100) {
84
            return false;
85
        }
86
87
        $sql = 'UPDATE ' . $this->table . ' SET `related_product_percent` = ' . (int)$percent . ' WHERE (related_product_id = ' . (int)$id . ') AND (related_product_related = ' . (int)$related . ')';
88
89
        return $this->db->queryF($sql);
90
    }
91
}
92