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.

RouteTranslationsListCommand::getArguments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Mcamara\LaravelLocalization\Commands;
4
5
use Mcamara\LaravelLocalization\LaravelLocalization;
6
use Mcamara\LaravelLocalization\Traits\TranslatedRouteCommandContext;
7
use Illuminate\Contracts\Console\Kernel;
8
use Illuminate\Foundation\Console\RouteListCommand;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class RouteTranslationsListCommand extends RouteListCommand
12
{
13
    use TranslatedRouteCommandContext;
14
15
    /**
16
     * @var string
17
     */
18
    protected $name = 'route:trans:list';
19
20
    /**
21
     * @var string
22
     */
23
    protected $description = 'List all registered routes for specific locales';
24
25
26
    /**
27
     * Execute the console command.
28
     */
29
    public function handle()
30
    {
31
        if (count($this->routes) == 0) {
32
            $this->error("Your application doesn't have any routes.");
33
            return;
34
        }
35
36
        $locale = $this->argument('locale');
37
38
        if ( ! $this->isSupportedLocale($locale)) {
0 ignored issues
show
Bug introduced by
It seems like $locale defined by $this->argument('locale') on line 36 can also be of type array or null; however, Mcamara\LaravelLocalizat...xt::isSupportedLocale() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39
            $this->error("Unsupported locale: '{$locale}'.");
40
            return;
41
        }
42
43
        $this->routes = $this->getFreshApplicationRoutes($locale);
0 ignored issues
show
Bug introduced by
It seems like $locale defined by $this->argument('locale') on line 36 can also be of type array or null; however, Mcamara\LaravelLocalizat...reshApplicationRoutes() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
45
        $this->displayRoutes($this->getRoutes());
46
    }
47
48
    /**
49
     * Boot a fresh copy of the application and get the routes.
50
     *
51
     * @param string $locale
52
     * @return \Illuminate\Routing\RouteCollection
53
     */
54
    protected function getFreshApplicationRoutes($locale)
55
    {
56
        $app = require $this->getBootstrapPath() . '/app.php';
57
58
        $key = LaravelLocalization::ENV_ROUTE_KEY;
59
60
        putenv("{$key}={$locale}");
61
62
        $app->make(Kernel::class)->bootstrap();
63
64
        putenv("{$key}=");
65
66
        return $app['router']->getRoutes();
67
    }
68
69
    /**
70
     * Get the console command arguments.
71
     *
72
     * @return array
73
     */
74
    protected function getArguments()
75
    {
76
        return [
77
            ['locale', InputArgument::REQUIRED, 'The locale to list routes for.'],
78
        ];
79
    }
80
}
81