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

OledrionOledrion_packingHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 25 and the first side effect is on line 20.

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
 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      Hossein Azizabadi ([email protected])
18
 */
19
20
require __DIR__ . '/classheader.php';
21
22
/**
23
 * Class Oledrion_packing
24
 */
25
class Oledrion_packing extends Oledrion_Object
0 ignored issues
show
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...
26
{
27
    /**
28
     * constructor
29
     *
30
     * normally, this is called from child classes only
31
     *
32
     * @access public
33
     */
34
    public function __construct()
35
    {
36
        $this->initVar('packing_id', XOBJ_DTYPE_INT, null, false);
37
        $this->initVar('packing_title', XOBJ_DTYPE_TXTBOX, null, false);
38
        $this->initVar('packing_width', XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('packing_length', XOBJ_DTYPE_TXTBOX, null, false);
40
        $this->initVar('packing_weight', XOBJ_DTYPE_TXTBOX, null, false);
41
        $this->initVar('packing_image', XOBJ_DTYPE_TXTBOX, null, false);
42
        $this->initVar('packing_description', XOBJ_DTYPE_TXTAREA, null, false);
43
        $this->initVar('packing_price', XOBJ_DTYPE_INT, null, false);
44
        $this->initVar('packing_online', XOBJ_DTYPE_INT, null, false);
45
    }
46
47
    /**
48
     * Retourne l'URL de l'image de la catégorie courante
49
     * @return string L'URL
50
     */
51 View Code Duplication
    public function getPictureUrl()
0 ignored issues
show
Duplication introduced by
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...
52
    {
53
        if (xoops_trim($this->getVar('product_image_url')) != '') {
54
            return OLEDRION_PICTURES_URL . '/' . $this->getVar('packing_image');
55
        } else {
56
            return '';
57
        }
58
    }
59
60
    /**
61
     * Indique si l'image de la catégorie existe
62
     *
63
     * @return boolean Vrai si l'image existe sinon faux
64
     */
65 View Code Duplication
    public function pictureExists()
0 ignored issues
show
Duplication introduced by
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...
66
    {
67
        $return = false;
68
        if (xoops_trim($this->getVar('packing_image')) != ''
69
            && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image'))
70
        ) {
71
            $return = true;
72
        }
73
74
        return $return;
75
    }
76
77
    /**
78
     * Supprime l'image associée à une catégorie
79
     * @return void
80
     */
81 View Code Duplication
    public function deletePicture()
0 ignored issues
show
Duplication introduced by
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...
82
    {
83
        if ($this->pictureExists()) {
84
            @unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image'));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
85
        }
86
        $this->setVar('packing_image', '');
87
    }
88
89
    /**
90
     * Retourne les éléments du produits formatés pour affichage
91
     *
92
     * @param  string $format
93
     * @return array
94
     */
95 View Code Duplication
    public function toArray($format = 's')
0 ignored issues
show
Duplication introduced by
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...
96
    {
97
        $oledrion_Currency               = Oledrion_Currency::getInstance();
98
        $ret                             = array();
0 ignored issues
show
Unused Code introduced by
$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...
99
        $ret                             = parent::toArray($format);
100
        $ret['packing_price_fordisplay'] = $oledrion_Currency->amountForDisplay($this->getVar('packing_price'));
101
        $ret['packing_image_url']        = $this->getPictureUrl();
102
103
        return $ret;
104
    }
105
}
106
107
/**
108
 * Class OledrionOledrion_packingHandler
109
 */
110
class OledrionOledrion_packingHandler extends Oledrion_XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

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...
111
{
112
    /**
113
     * OledrionOledrion_packingHandler constructor.
114
     * @param XoopsDatabase|null $db
115
     */
116
    public function __construct(XoopsDatabase $db)
117
    { //                                       Table                    Classe              Id
118
        parent::__construct($db, 'oledrion_packing', 'oledrion_packing', 'packing_id');
119
    }
120
121
    /**
122
     * @param  Oledrion_parameters $parameters
123
     * @return array
124
     */
125 View Code Duplication
    public function getAllPacking(Oledrion_parameters $parameters)
0 ignored issues
show
Duplication introduced by
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...
126
    {
127
        $parameters = $parameters->extend(new Oledrion_parameters(array(
0 ignored issues
show
Documentation introduced by
new \Oledrion_parameters...id', 'order' => 'ASC')) 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...
128
                                                                      'start' => 0,
129
                                                                      'limit' => 0,
130
                                                                      'sort'  => 'packing_id',
131
                                                                      'order' => 'ASC'
132
                                                                  )));
133
        $critere    = new Criteria('packing_id', 0, '<>');
134
        $critere->setLimit($parameters['limit']);
135
        $critere->setStart($parameters['start']);
136
        $critere->setSort($parameters['sort']);
137
        $critere->setOrder($parameters['order']);
138
        $packings = array();
0 ignored issues
show
Unused Code introduced by
$packings 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...
139
        $packings = $this->getObjects($critere);
140
141
        return $packings;
142
    }
143
144
    /**
145
     * @return array
146
     */
147
    public function getPacking()
148
    {
149
        $ret     = array();
150
        $critere = new CriteriaCompo();
151
        $critere->add(new Criteria('packing_online', '1'));
152
        $packings = $this->getObjects($critere);
153
        foreach ($packings as $root) {
154
            $tab   = array();
0 ignored issues
show
Unused Code introduced by
$tab 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...
155
            $tab   = $root->toArray();
156
            $ret[] = $tab;
157
        }
158
159
        return $ret;
160
    }
161
}
162