Issues (88)

src/Rules/Timezone.php (2 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
use BlitzPHP\Utilities\String\Text;
15
use DateTimeZone;
16
17
class Timezone extends AbstractRule
18
{
19
    protected $fillableParams = ['settings'];
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function check($value): bool
25
    {
26
        [$timezoneGroup, $countryCode] = explode(',', $this->parameter('settings', 'ALL')) + [1 => null];
27
28
        return in_array($value, timezone_identifiers_list(
0 ignored issues
show
Are you sure the usage of timezone_identifiers_lis...r($countryCode) : null) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
timezone_identifiers_lis...r($countryCode) : null) of type void is incompatible with the type array expected by parameter $haystack of in_array(). ( Ignorable by Annotation )

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

28
        return in_array($value, /** @scrutinizer ignore-type */ timezone_identifiers_list(
Loading history...
29
            constant(DateTimeZone::class . '::' . Text::upper($timezoneGroup)),
30
            null !== $countryCode ? Text::upper($countryCode) : null,
31
        ), true);
32
    }
33
}
34