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

Oledrion_location::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 1
Ratio 14.29 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 1
loc 7
rs 9.4285
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_location
24
 */
25 View Code Duplication
class Oledrion_location extends Oledrion_Object
0 ignored issues
show
Duplication introduced by
This class 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...
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('location_id', XOBJ_DTYPE_INT, null, false);
37
        $this->initVar('location_pid', XOBJ_DTYPE_INT, null, false);
38
        $this->initVar('location_title', XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('location_online', XOBJ_DTYPE_INT, null, false);
40
        $this->initVar('location_type', XOBJ_DTYPE_TXTBOX, null, false);
41
    }
42
43
    /**
44
     * Retourne les éléments du produits formatés pour affichage
45
     *
46
     * @param  string $format
47
     * @return array
48
     */
49
    public function toArray($format = 's')
50
    {
51
        $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...
52
        $ret = parent::toArray($format);
53
54
        return $ret;
55
    }
56
}
57
58
/**
59
 * Class OledrionOledrion_locationHandler
60
 */
61
class OledrionOledrion_locationHandler 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...
62
{
63
    /**
64
     * OledrionOledrion_locationHandler constructor.
65
     * @param XoopsDatabase|null $db
66
     */
67
    public function __construct(XoopsDatabase $db)
68
    { //                                        Table                   Classe              Id
69
        parent::__construct($db, 'oledrion_location', 'oledrion_location', 'location_id');
70
    }
71
72
    /**
73
     * @param  Oledrion_parameters $parameters
74
     * @return array
75
     */
76 View Code Duplication
    public function getAllLocation(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...
77
    {
78
        $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...
79
                                                                      'start' => 0,
80
                                                                      'limit' => 0,
81
                                                                      'sort'  => 'location_id',
82
                                                                      'order' => 'ASC'
83
                                                                  )));
84
        $critere    = new Criteria('location_id', 0, '<>');
85
        $critere->setLimit($parameters['limit']);
86
        $critere->setStart($parameters['start']);
87
        $critere->setSort($parameters['sort']);
88
        $critere->setOrder($parameters['order']);
89
        $location = array();
0 ignored issues
show
Unused Code introduced by
$location 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...
90
        $location = $this->getObjects($critere);
91
92
        return $location;
93
    }
94
95
    /**
96
     * @param  Oledrion_parameters $parameters
97
     * @return array
98
     */
99 View Code Duplication
    public function getAllPid(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...
100
    {
101
        $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...
102
                                                                      'start' => 0,
103
                                                                      'limit' => 0,
104
                                                                      'sort'  => 'location_id',
105
                                                                      'order' => 'ASC'
106
                                                                  )));
107
        $critere    = new CriteriaCompo();
108
        $critere->add(new Criteria('location_type', 'parent'));
109
        $critere->setLimit($parameters['limit']);
110
        $critere->setStart($parameters['start']);
111
        $critere->setSort($parameters['sort']);
112
        $critere->setOrder($parameters['order']);
113
        $pid = array();
0 ignored issues
show
Unused Code introduced by
$pid 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...
114
        $pid = $this->getObjects($critere);
115
116
        return $pid;
117
    }
118
119
    /**
120
     * @param $id
121
     * @return array
122
     */
123 View Code Duplication
    public function getLocation($id)
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...
124
    {
125
        $critere = new CriteriaCompo();
126
        $critere->add(new Criteria('location_online', 1));
127
        $critere->add(new Criteria('location_type', 'location'));
128
        $critere->add(new Criteria('location_pid', $id));
129
        $location = array();
0 ignored issues
show
Unused Code introduced by
$location 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...
130
        $location = $this->getObjects($critere);
131
132
        return $location;
133
    }
134
135
    /**
136
     * @param $id
137
     * @return int
138
     */
139 View Code Duplication
    public function haveChild($id)
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...
140
    {
141
        $critere = new CriteriaCompo();
142
        $critere->add(new Criteria('location_online', 1));
143
        $critere->add(new Criteria('location_type', 'location'));
144
        $critere->add(new Criteria('location_pid', $id));
145
        $location = $this->getCount($critere);
146
147
        return $location;
148
    }
149
}
150