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

class/oledrion_vat.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
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
/**
21
 * Gestion des TVA
22
 */
23
require __DIR__ . '/classheader.php';
24
25
/**
26
 * Class Oledrion_vat
27
 */
28
class Oledrion_vat extends Oledrion_Object
29
{
30
    /**
31
     * constructor
32
     *
33
     * normally, this is called from child classes only
34
     *
35
     * @access public
36
     */
37
    public function __construct()
38
    {
39
        $this->initVar('vat_id', XOBJ_DTYPE_INT, null, false);
40
        $this->initVar('vat_rate', XOBJ_DTYPE_TXTBOX, null, false);
41
        $this->initVar('vat_country', XOBJ_DTYPE_TXTBOX, null, false);
42
    }
43
44
    /**
45
     * @param  string $format
46
     * @return array
47
     */
48 View Code Duplication
    public function toArray($format = 's')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $ret                      = array();
0 ignored issues
show
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51
        $ret                      = parent::toArray($format);
52
        $oledrion_Currency        = Oledrion_Currency::getInstance();
53
        $ret['vat_rate_formated'] = $oledrion_Currency->amountInCurrency((float)$this->getVar('vat_rate', 'e'));
54
55
        return $ret;
56
    }
57
}
58
59
/**
60
 * Class OledrionOledrion_vatHandler
61
 */
62
class OledrionOledrion_vatHandler extends Oledrion_XoopsPersistableObjectHandler
63
{
64
    /**
65
     * OledrionOledrion_vatHandler constructor.
66
     * @param XoopsDatabase|null $db
67
     */
68
    public function __construct(XoopsDatabase $db)
69
    { //                        Table           Classe          Id
70
        parent::__construct($db, 'oledrion_vat', 'oledrion_vat', 'vat_id');
71
    }
72
73
    /**
74
     * Renvoie la liste de toutes les TVA du module
75
     *
76
     * @param  Oledrion_parameters $parameters
77
     * @return array               tableau d'objets de type TVA
78
     * @internal param int $start Position de départ
79
     * @internal param int $limit Nombre total d'enregistrements à renvoyer
80
     * @internal param string $order Champ sur lequel faire le tri
81
     * @internal param string $order Ordre du tri
82
     * @internal param bool $idaskey Indique si le tableau renvoyé doit avoir pour clé l'identifiant unique de l'enregistrement
83
     */
84
    public function getAllVats(Oledrion_parameters $parameters)
85
    {
86
        $parameters = $parameters->extend(new Oledrion_parameters(array(
0 ignored issues
show
new \Oledrion_parameters...C', 'idaskey' => true)) is of type object<Oledrion_parameters>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
                                                                      'start'   => 0,
88
                                                                      'limit'   => 0,
89
                                                                      'sort'    => 'vat_id',
90
                                                                      'order'   => 'ASC',
91
                                                                      'idaskey' => true
92
                                                                  )));
93
        $critere    = new Criteria('vat_id', 0, '<>');
94
        $critere->setLimit($parameters['limit']);
95
        $critere->setStart($parameters['start']);
96
        $critere->setSort($parameters['sort']);
97
        $critere->setOrder($parameters['order']);
98
        $vats = array();
99
        $vats = $this->getObjects($critere, $parameters['idaskey']);
100
101
        return $vats;
102
    }
103
104
    /**
105
     * Renvoie la liste de toutes les TVA du module
106
     *
107
     * @param $country
108
     * @return array tableau d'objets de type TVA
109
     * @internal param int $start Position de départ
110
     * @internal param int $limit Nombre total d'enregistrements à renvoyer
111
     * @internal param string $order Champ sur lequel faire le tri
112
     * @internal param string $order Ordre du tri
113
     * @internal param bool $idaskey Indique si le tableau renvoyé doit avoir pour clé l'identifiant unique de l'enregistrement
114
     */
115
    public function getCountryVats($country)
116
    {
117
        $parameters = new Oledrion_parameters(array(
118
                                                  'start'   => 0,
119
                                                  'limit'   => 0,
120
                                                  'sort'    => 'vat_id',
121
                                                  'order'   => 'ASC',
122
                                                  'idaskey' => true
123
                                              ));
124
        $critere    = new CriteriaCompo();
125
        if (!empty($country)) {
126
            $critere->add(new Criteria('vat_country', $country, 'LIKE'));
127
        }
128
        $critere->setLimit($parameters['limit']);
129
        $critere->setStart($parameters['start']);
130
        $critere->setSort($parameters['sort']);
131
        $critere->setOrder($parameters['order']);
132
        $vats = array();
133
        $vats = $this->getObjects($critere, $parameters['idaskey']);
134
135
        return $vats;
136
    }
137
138
    /**
139
     * Suppression d'une TVA
140
     *
141
     * @param  oledrion_vat $vat
142
     * @return boolean      Le résultat de la suppressin
143
     */
144
    public function deleteVat(Oledrion_vat $vat)
145
    {
146
        return $this->delete($vat, true);
147
    }
148
149
    /**
150
     * Retourne le nombre de produits associés à une TVA
151
     *
152
     * @param  integer $vat_id L'ID de la TVA
153
     * @return integer Le nombre de produits
154
     */
155
    public function getVatProductsCount($vat_id)
156
    {
157
        global $h_oledrion_products;
158
159
        return $h_oledrion_products->getVatProductsCount($vat_id);
160
    }
161
}
162