Completed
Branch master (55a138)
by Michael
03:21
created

Utility   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 471
Duplicated Lines 51.38 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 242
loc 471
rs 6.8
c 0
b 0
f 0
wmc 55
lcom 1
cbo 5

17 Methods

Rating   Name   Duplication   Size   Complexity  
A extcal_getEvent() 13 13 2
C extcal_loadImg() 54 54 15
A getListCategories() 18 18 3
B getCheckeCategories() 27 27 3
A getListOrderBy() 23 23 2
A getListAndOr() 11 11 1
A getList() 15 15 3
B getDateBetweenDates() 0 38 1
A echoDateArray() 0 6 2
A ext_echoArray() 9 9 2
A ext_echo() 0 7 2
A ext_echoTSN() 0 6 1
A ext_echoTSU() 8 8 2
A ext_convert_date() 13 13 3
A ext_DateAdd() 8 8 1
C ext_DateAdd2() 43 43 11
A getLighterColor() 0 8 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.

1
<?php namespace XoopsModules\Extcal;
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 27 and the first side effect is on line 18.

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
 * classGenerator
4
 * walls_watermarks.
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
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 *
14
 *
15
 * L'utilisation de ce formulaire d'adminitration suppose
16
 * que la classe correspondante de la table a été générées avec classGenerator
17
 **/
18
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
19
20
use Xmf\Request;
21
use XoopsModules\Extcal;
22
use XoopsModules\Extcal\Common;
23
24
/**
25
 * Class Utility
26
 */
27
class Utility
28
{
29
    use common\VersionChecks; //checkVerXoops, checkVerPhp Traits
30
31
    use common\ServerStats; // getServerStats Trait
32
33
    use common\FilesManagement; // Files Management Trait
34
35
    //--------------- Custom module methods -----------------------------
36
    /**
37
     * @param $eventId
38
     *
39
     * @return array
40
     */
41 View Code Duplication
    public static function extcal_getEvent($eventId)
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...
42
    {
43
        $eventHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_EVENT);
44
        $event        = $eventHandler->getEvent($eventId);
45
        $t            = $event->getVars();
46
        $data         = [];
47
        //        while (list($key, $val) = each($t)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
        foreach ($t as $key => $val) {
49
            $data[$key] = $val['value'];
50
        }
51
52
        return $data;
53
    }
54
55
    /**
56
     * @param $REQUEST
57
     * @param $event_picture1
58
     * @param $event_picture2
59
     */
60 View Code Duplication
    public static function extcal_loadImg(&$REQUEST, &$event_picture1, &$event_picture2)
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...
61
    {
62
        ///////////////////////////////////////////////////////////////////////////////
63
        $uploaddir_event = XOOPS_ROOT_PATH . '/uploads/extcal/';
64
        $uploadurl_event = XOOPS_URL . '/uploads/extcal/';
0 ignored issues
show
Unused Code introduced by
$uploadurl_event 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...
65
        //$picture = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        for ($j = 1; $j < 3; ++$j) {
67
            $delimg = @$REQUEST['delimg_' . $j . ''];
68
            $delimg = isset($delimg) ? (int)$delimg : 0;
69
            if (0 == $delimg && !empty($REQUEST['xoops_upload_file'][$j])) {
70
                $upload = new \XoopsMediaUploader($uploaddir_event, [
71
                    'image/gif',
72
                    'image/jpeg',
73
                    'image/pjpeg',
74
                    'image/x-png',
75
                    'image/png',
76
                    'image/jpg',
77
                ], 3145728, null, null);
78
                if ($upload->fetchMedia($REQUEST['xoops_upload_file'][$j])) {
79
                    $upload->setPrefix('event_');
80
                    $upload->fetchMedia($REQUEST['xoops_upload_file'][$j]);
81
                    if (!$upload->upload()) {
82
                        $errors = $upload->getErrors();
83
                        redirect_header('javascript:history.go(-1)', 3, $errors);
84
                    } else {
85
                        if (1 == $j) {
86
                            $event_picture1 = $upload->getSavedFileName();
87
                        } elseif (2 == $j) {
88
                            $event_picture2 = $upload->getSavedFileName();
89
                        }
90
                    }
91
                } elseif (!empty($REQUEST['file' . $j])) {
92
                    if (1 == $j) {
93
                        $event_picture1 = $REQUEST['file' . $j];
94
                    } elseif (2 == $j) {
95
                        $event_picture2 = $REQUEST['file' . $j];
96
                    }
97
                }
98
            } else {
99
                $url_event = XOOPS_ROOT_PATH . '/uploads/extcal/' . $REQUEST['file' . $j];
100
                if (1 == $j) {
101
                    $event_picture1 = '';
102
                } elseif (2 == $j) {
103
                    $event_picture2 = '';
104
                }
105
                if (is_file($url_event)) {
106
                    chmod($url_event, 0777);
107
                    unlink($url_event);
108
                }
109
            }
110
        }
111
        //exit;
112
        ///////////////////////////////////////////////////////////////////////////////
113
    }
114
115
    /*******************************************************************
116
     *
117
     ******************************************************************
118
     * @param        $cat
119
     * @param bool   $addNone
120
     * @param string $name
121
     * @return XoopsFormSelect
0 ignored issues
show
Documentation introduced by
Should the return type not be \XoopsFormSelect?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
122
     */
123 View Code Duplication
    public static function getListCategories($cat, $addNone = true, $name = 'cat')
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
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
126
        // Category selectbox
127
        $catHandler   = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
128
129
        $catsList  = $catHandler->getAllCat($xoopsUser);
130
        $catSelect = new \XoopsFormSelect('', $name, $cat);
131
        if ($addNone) {
132
            $catSelect->addOption(0, ' ');
133
        }
134
135
        foreach ($catsList as $catList) {
136
            $catSelect->addOption($catList->getVar('cat_id'), $catList->getVar('cat_name'));
137
        }
138
139
        return $catSelect;
140
    }
141
142
    /*******************************************************************
143
     *
144
     ******************************************************************
145
     * @param string $name
146
     * @param        $cat
147
     * @return array
148
     */
149 View Code Duplication
    public static function getCheckeCategories($name = 'cat', $cat)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
150
    {
151
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
152
        // Category selectbox
153
        //<option style="background-color:#00FFFF;">VARCHAR</option>
154
155
         $catHandler   = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
156
        $catsList   = $catHandler->getAllCat($xoopsUser);
157
158
        $t = [];
159
        foreach ($catsList as $catList) {
160
            $cat_id    = $catList->getVar('cat_id');
161
            $name      = $catList->getVar('cat_name');
162
            $cat_color = $catList->getVar('cat_color');
163
            $checked   = in_array($cat_id, $cat) ? 'checked' : '';
164
            $cat       = ''
165
                         . "<div style='float:left; margin-left:5px;'>"
166
                         . "<input type='checkbox' name='{$name}[{$cat_id}]' value='1' {$checked}>"
167
                         . "<div style='absolute:left;height:12px; width:6px; background-color:#{$cat_color}; border:1px solid black; float:left; margin-right:5px;' ></div>"
168
                         . " {$name}"
169
                         . '</div>';
170
171
            $t[] = $cat;
172
        }
173
174
        return $t;
175
    }
176
177
    /*******************************************************************
178
     *
179
     ******************************************************************
180
     * @param string $name
181
     * @param string $caption
182
     * @param        $defaut
183
     * @param bool   $addNone
184
     * @return XoopsFormSelect
0 ignored issues
show
Documentation introduced by
Should the return type not be \XoopsFormSelect?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
185
     */
186 View Code Duplication
    public static function getListOrderBy($name = 'orderby', $caption = '', $defaut, $addNone = false)
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...
187
    {
188
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
189
190
        $select = new \XoopsFormSelect($caption, $name, $defaut);
191
        if ($addNone) {
192
            $select->addOption('', '');
193
        }
194
195
        $select->addOption('year ASC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
196
        $select->addOption('year DESC', _MD_EXTCAL_YEAR . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
197
198
        $select->addOption('month ASC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
199
        $select->addOption('month DESC', _MD_EXTCAL_MONTH . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
200
201
        $select->addOption('event_title ASC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
202
        $select->addOption('event_title DESC', _MD_EXTCAL_ALPHA . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
203
204
        $select->addOption('cat_name ASC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_ASC);
205
        $select->addOption('cat_name DESC', _MD_EXTCAL_CATEGORY . ' ' . _MD_EXTCAL_ORDER_BY_DESC);
206
207
        return $select;
208
    }
209
210
    /*******************************************************************
211
     *
212
     ******************************************************************
213
     * @param string $name
214
     * @param string $caption
215
     * @param        $defaut
216
     * @return XoopsFormSelect
0 ignored issues
show
Documentation introduced by
Should the return type not be \XoopsFormSelect?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
217
     */
218 View Code Duplication
    public static function getListAndOr($name = 'andor', $caption = '', $defaut)
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...
219
    {
220
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
221
222
        $select = new \XoopsFormSelect($caption, $name, $defaut);
223
224
        $select->addOption('AND', _MD_EXTCAL_AND);
225
        $select->addOption('OR', _MD_EXTCAL_OR);
226
227
        return $select;
228
    }
229
230
    /*******************************************************************
231
     *
232
     ******************************************************************
233
     * @param        $name
234
     * @param        $caption
235
     * @param        $defaut
236
     * @param        $options
237
     * @param string $sep
238
     * @return XoopsFormSelect
0 ignored issues
show
Documentation introduced by
Should the return type not be \XoopsFormSelect?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
239
     */
240 View Code Duplication
    public static function getList($name, $caption, $defaut, $options, $sep = ';')
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...
241
    {
242
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
243
244
        $select = new \XoopsFormSelect($caption, $name, $defaut);
245
        if (!is_array($options)) {
246
            $options = explode($sep, $options);
247
        }
248
249
        for ($h = 0, $count = count($options); $h < $count; ++$h) {
250
            $select->addOption($h, $options[$h]);
251
        }
252
253
        return $select;
254
    }
255
256
    /*******************************************************************
257
     *
258
     ******************************************************************
259
     * @param        $ts
260
     * @param        $startMonth
261
     * @param        $endMonth
262
     * @param string $mode
263
     * @return DateTime
264
     */
265
    public static function getDateBetweenDates($ts, $startMonth, $endMonth, $mode = 'w')
0 ignored issues
show
Unused Code introduced by
The parameter $mode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
266
    {
267
        $d = new DateTime($periodStart);
0 ignored issues
show
Bug introduced by
The variable $periodStart does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
268
        $d->setTimestamp($ts);
269
270
        //echo "<br>affichage des periodes : <br>";
271
        $begin = new DateTime();
272
        $begin->setTimestamp($startMonth);
273
        //echo $begin->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
274
275
        $end = new DateTime();
276
        $end->setTimestamp($endMonth);
277
        //echo $end->format("d/m/Y à H\hi:s").'<br>'; // 03/10/2007 à 19h39:53
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
278
        //echo "<hr>";
279
        $interval = DateInterval::createFromDateString('next sunday');
280
        $period   = new DatePeriod($begin, $interval, $end);
0 ignored issues
show
Unused Code introduced by
$period 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...
281
        //echoDateArray($period);
282
283
        //echo "<hr>{$interval}";
284
        return $d;
285
286
        //echo mktime($heure, $minute, $seconde, $mois, $jour, $an);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
287
288
        //
289
        //   $jour = date('d', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
        //   $mois = date('m', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
291
        //   $an = date('Y', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
292
        //   $heure = date('H', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
293
        //   $minute = date('i', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
294
        //   $seconde = date('s', $ts);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
295
        //   $d->setDate($heure,$minute,$seconde,$mois,$jour,$an);
0 ignored issues
show
Unused Code Comprehensibility introduced by
89% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
296
297
        // <?php
298
        // $interval = DateInterval::createFromDateString('next sunday');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
299
        // $period = new DatePeriod($begin, $interval, $end);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
300
        // foreach ($period as $dt) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
301
        //   echo $dt->format( "l Y-m-d H:i:s\n" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
302
    }
303
304
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
305
    Sunday 2009-11-01 00:00:00
306
    Sunday 2009-11-08 00:00:00
307
    Sunday 2009-11-15 00:00:00
308
    Sunday 2009-11-22 00:00:00
309
    Sunday 2009-11-29 00:00:00
310
    Sunday 2009-12-06 00:00:00
311
    ...
312
    */
313
    /**
314
     * @param $period
315
     */
316
    public static function echoDateArray($period)
317
    {
318
        foreach ($period as $dt) {
319
            echo $dt->format("l Y-m-d H:i:s\n") . '<br>';
320
        }
321
    }
322
323
    /*****************************************************************/
324
    /**
325
     * @param        $t
326
     * @param string $msg
327
     */
328 View Code Duplication
    public static function ext_echoArray($t, $msg = '')
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...
329
    {
330
        if ('' != $msg) {
331
            echo "<hr>{$msg}<hr>";
332
        }
333
334
        $txt = print_r($t, true);
335
        echo '<pre>Number of items: ' . count($t) . "<br>{$txt}</pre>";
336
    }
337
338
    /*****************************************************************/
339
    /**
340
     * @param        $line
341
     * @param string $msg
342
     */
343
    public static function ext_echo($line, $msg = '')
344
    {
345
        if ('' != $msg) {
346
            echo "<hr>{$msg}<hr>";
347
        }
348
        echo $line . '<br>';
349
    }
350
351
    /*****************************************************************/
352
    /**
353
     * @param        $tsName
354
     * @param string $msg
355
     */
356
    public static function ext_echoTSN($tsName, $msg = '')
357
    {
358
        global $$tsName;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
359
        $ts = $$tsName;
360
        static::ext_echoTSU($ts, $tsName, $msg = '');
361
    }
362
363
    /*****************************************************************/
364
    /**
365
     * @param        $ts
366
     * @param        $tsName
367
     * @param string $msg
368
     */
369 View Code Duplication
    public static function ext_echoTSU($ts, $tsName, $msg = '')
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...
370
    {
371
        if ('' != $msg) {
372
            echo "<hr>{$msg}<hr>";
373
        }
374
375
        echo 'date --->' . $tsName . ' = ' . $ts . ' - ' . date('d-m-Y H:m:s', $ts) . '<br>';
376
    }
377
378
    /*****************************************************************/
379
    /*****************************************************************/
380
    /**
381
     * @param        $date
382
     * @param string $sep
383
     *
384
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
385
     */
386 View Code Duplication
    public static function ext_convert_date($date, $sep = '-')
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...
387
    {
388
        $lstSep = '/ .';
389
390
        for ($h = 0, $count = strlen($lstSep); $h < $count; ++$h) {
0 ignored issues
show
Unused Code introduced by
++$h; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
391
            $sep2replace = substr($lstSep, $h, 1);
392
            if (strpos($date, $sep2replace)) {
393
                $date = str_replace($sep2replace, $sep, $date);
394
            }
395
396
            return strtotime($date);
397
        }
398
    }
399
400
    /**
401
     * @param     $givendate
402
     * @param int $day
403
     * @param int $mth
404
     * @param int $yr
405
     *
406
     * @return int
407
     */
408 View Code Duplication
    public static function ext_DateAdd($givendate, $day = 0, $mth = 0, $yr = 0)
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...
409
    {
410
        //$cd = strtotime($givendate);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
411
        $cd      = $givendate;
412
        $newdate = date('Y-m-d h:i:s', mktime(date('h', $cd), date('i', $cd), date('s', $cd), date('m', $cd) + $mth, date('d', $cd) + $day, date('Y', $cd) + $yr));
413
414
        return strtotime($newdate);
415
    }
416
417
    /**
418
     * @param $date
419
     * @param $number
420
     * @param $interval
421
     *
422
     * @return int
423
     */
424 View Code Duplication
    public static function ext_DateAdd2($date, $number, $interval = 'd')
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...
425
    {
426
        $date_time_array = getdate($date);
427
        $hours           = $date_time_array['hours'];
428
        $minutes         = $date_time_array['minutes'];
429
        $seconds         = $date_time_array['seconds'];
430
        $month           = $date_time_array['mon'];
431
        $day             = $date_time_array['mday'];
432
        $year            = $date_time_array['year'];
433
434
        switch ($interval) {
435
436
            case 'yyyy':
437
                $year += $number;
438
                break;
439
            case 'q':
440
                $year += ($number * 3);
441
                break;
442
            case 'm':
443
                $month += $number;
444
                break;
445
            case 'y':
446
            case 'd':
447
            case 'w':
448
                $day += $number;
449
                break;
450
            case 'ww':
451
                $day += ($number * 7);
452
                break;
453
            case 'h':
454
                $hours += $number;
455
                break;
456
            case 'n':
457
                $minutes += $number;
458
                break;
459
            case 's':
460
                $seconds += $number;
461
                break;
462
        }
463
        $timestamp = mktime($hours, $minutes, $seconds, $month, $day, $year);
464
465
        return $timestamp;
466
    }
467
468
    // function date_diff($date1, $date2) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
469
    //     $current = $date1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
470
    //     $datetime2 = date_create($date2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
471
    //     $count = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
472
    //     while (date_create($current) < $datetime2) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
473
    //         $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
474
    //         ++$count;
475
    //     }
476
    //     return $count;
477
    // }
478
479
    /**************************************************************************/
480
    /**
481
     * @param $color
482
     * @param $plancher
483
     * @param $plafond
484
     *
485
     * @return string
486
     */
487
    public static function getLighterColor($color, $plancher, $plafond)
488
    {
489
        require_once __DIR__ . '/ColorTools.php';
490
491
        //$ct = new ColorTools();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
492
        //return $ct->eclaircir($color,$plancher,$plafond);
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
493
        return ColorTools::eclaircir($color, $plancher, $plafond);
494
    }
495
    /**************************************************************************/
496
497
}
498