Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

Utility::getDateBetweenDates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
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 19.

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
/**
4
 * classGenerator
5
 * walls_watermarks.
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * L'utilisation de ce formulaire d'adminitration suppose
17
 * que la classe correspondante de la table a été générées avec classGenerator
18
 **/
19
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extcal\XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
20
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
    public static function getEvent($eventId)
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
    public static function loadImg(&$REQUEST, &$event_picture1, &$event_picture2)
61
    {
62
        ///////////////////////////////////////////////////////////////////////////////
63
        $uploaddir_event = XOOPS_ROOT_PATH . '/uploads/extcal/';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extcal\XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
        $uploadurl_event = XOOPS_URL . '/uploads/extcal/';
0 ignored issues
show
Unused Code introduced by
The assignment to $uploadurl_event is dead and can be removed.
Loading history...
Bug introduced by
The constant XoopsModules\Extcal\XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
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, [
0 ignored issues
show
Bug introduced by
The type XoopsMediaUploader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
                        /** @scrutinizer ignore-call */ 
84
                        redirect_header('javascript:history.go(-1)', 3, $errors);
Loading history...
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
122
     */
123
    public static function getListCategories($cat, $addNone = true, $name = 'cat')
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);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    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. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

149
    public static function getCheckeCategories(/** @scrutinizer ignore-unused */ $name = 'cat', $cat)

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

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
185
     */
186
    public static function getListOrderBy($name = 'orderby', $caption = '', $defaut, $addNone = false)
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
217
     */
218
    public static function getListAndOr($name = 'andor', $caption = '', $defaut)
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
239
     */
240
    public static function getList($name, $caption, $defaut, $options, $sep = ';')
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
        foreach ($options as $h => $hValue) {
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. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

265
    public static function getDateBetweenDates($ts, $startMonth, $endMonth, /** @scrutinizer ignore-unused */ $mode = 'w')

This check looks for 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
Comprehensibility Best Practice introduced by
The variable $periodStart does not exist. Did you maybe mean $period?
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
The assignment to $period is dead and can be removed.
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
    public static function echoArray($t, $msg = '')
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 extEcho($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 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::echoTsu($ts, $tsName, $msg = '');
361
    }
362
363
    /*****************************************************************/
364
    /**
365
     * @param        $ts
366
     * @param        $tsName
367
     * @param string $msg
368
     */
369
    public static function echoTsu($ts, $tsName, $msg = '')
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
385
     */
386
    public static function convertDate($date, $sep = '-')
387
    {
388
        $lstSep = '/ .';
389
390
        for ($h = 0, $count = strlen($lstSep); $h < $count; ++$h) {
0 ignored issues
show
Unused Code introduced by
++$h is not 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
    public static function addDate($givendate, $day = 0, $mth = 0, $yr = 0)
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));
0 ignored issues
show
Bug introduced by
date('s', $cd) of type string is incompatible with the type integer expected by parameter $second of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

412
        $newdate = date('Y-m-d h:i:s', mktime(date('h', $cd), date('i', $cd), /** @scrutinizer ignore-type */ date('s', $cd), date('m', $cd) + $mth, date('d', $cd) + $day, date('Y', $cd) + $yr));
Loading history...
Bug introduced by
date('h', $cd) of type string is incompatible with the type integer expected by parameter $hour of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

412
        $newdate = date('Y-m-d h:i:s', mktime(/** @scrutinizer ignore-type */ date('h', $cd), date('i', $cd), date('s', $cd), date('m', $cd) + $mth, date('d', $cd) + $day, date('Y', $cd) + $yr));
Loading history...
Bug introduced by
date('i', $cd) of type string is incompatible with the type integer expected by parameter $minute of mktime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

412
        $newdate = date('Y-m-d h:i:s', mktime(date('h', $cd), /** @scrutinizer ignore-type */ date('i', $cd), date('s', $cd), date('m', $cd) + $mth, date('d', $cd) + $day, date('Y', $cd) + $yr));
Loading history...
413
414
        return strtotime($newdate);
415
    }
416
417
    /**
418
     * @param $date
419
     * @param $number
420
     * @param $interval
421
     *
422
     * @return int
423
     */
424
    public static function addDate2($date, $number, $interval = 'd')
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