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.

TestTranslationExtensions::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WeAreNeopix\LaravelModelTranslation\Commands;
4
5
use Illuminate\Console\Command;
6
7
class TestTranslationExtensions extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'translation:test-extensions 
15
                                                {extensions?*  : The extensions that should be tested} 
16
                                                {--no-database : Defines whether the tests should be performed without access to a database}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Test if the registered TranslationManager extensions work in the way they are supposed to.';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return void
39
     */
40
    public function handle()
41
    {
42
        $this->info('Testing custom Translation drivers.');
43
        $drivers = $this->prepareExtensions();
44
        $this->info('These drivers are being tested: '.implode(', ', $drivers));
45
46
        system($this->makeCommand());
47
    }
48
49
    /**
50
     * Compose the phpunit command to be ran in order to perform the extension tests.
51
     *
52
     * @param string|null $extensionToRun
0 ignored issues
show
Bug introduced by
There is no parameter named $extensionToRun. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     * @return string
54
     */
55
    protected function makeCommand()
56
    {
57
        $phpUnitPath = base_path('vendor/bin/phpunit');
58
        $autoloadPath = base_path('vendor/autoload.php');
59
        $phpunitXmlPath = $this->getPhpunitXmlPath();
60
        $testFilePath = $this->getTestFilePath();
61
62
        $command = "{$phpUnitPath} --bootstrap {$autoloadPath} --configuration {$phpunitXmlPath} {$testFilePath} ";
63
64
        if ($this->option('no-database') === true) {
65
            $command .= '_test_without_database_ ';
66
        }
67
68
        $command .= implode(' ', $this->prepareExtensions());
69
70
        return $command;
71
    }
72
73
    /**
74
     * Returns the path to the phpunit.xml configuration file.
75
     *
76
     * @return string
77
     */
78
    protected function getPhpunitXmlPath()
79
    {
80
        return base_path('packages/misa-neopix/laravel-model-translation/tests/extensions/phpunit.xml');
81
    }
82
83
    /**
84
     * Return the path to the file to be tested.
85
     * We need to include this file manually
86
     * in order to provide driver names that are to
87
     * be tested after it.
88
     *
89
     * @return string
90
     */
91
    protected function getTestFilePath()
92
    {
93
        return base_path('packages/misa-neopix/laravel-model-translation/tests/extensions/UserExtensionsTest.php');
94
    }
95
96
    /**
97
     * We check if the user has provided any extensions here.
98
     * If there are any provided extensions, we will use only
99
     * those.
100
     * Otherwise, we will fetch all the registered
101
     * extensions from the TranslationDriver and
102
     * test them all.
103
     *
104
     * @return array
105
     */
106
    protected function prepareExtensions()
107
    {
108
        $specifiedExtensions = $this->argument('extensions');
109
110
        if (! empty($specifiedExtensions)) {
111
            return $specifiedExtensions;
112
        }
113
114
        return $this->getLaravel()['translation']->getRegisteredExtensionNames();
115
    }
116
}
117