GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

helpers.php ➔ mmex_guid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('mmex_guid')) {
4
    /**
5
     * Signs a url and make it available for the given amount of hours.
6
     *
7
     * @return string
8
     */
9
    function mmex_guid()
10
    {
11
        $uuid = Uuid::generate();
12
        $guid = strtoupper($uuid);
13
14
        return sprintf('{%s}', $guid);
15
    }
16
}
17
18
if (!function_exists('locale_dateformat')) {
19
    /**
20
     * Signs a url and make it available for the given amount of hours.
21
     *
22
     * @return string
23
     */
24
    function locale_dateformat()
25
    {
26
        if (starts_with(App::getLocale(), 'de')) {
27
            $format = 'd.m.Y';
28
        } elseif (App::getLocale() == 'en_US') {
29
            $format = 'm/d/Y';
30
        } elseif (App::getLocale() == 'en_GB') {
31
            $format = 'd/m/Y';
32
        }
33
34
        return $format;
0 ignored issues
show
Bug introduced by
The variable $format does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
35
    }
36
}
37