src/SettingsServiceProvider.php
Avoid unused parameters such as '$app'. Open
Open
$this->app->singleton(Settings::class, function ($app) {
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Call to undeclared method \Poisa\Settings\SettingsServiceProvider::mergeConfigFrom
Open
Open
$this->mergeConfigFrom($configFile, 'settings');
- Exclude checks
Call to undeclared method \Poisa\Settings\SettingsServiceProvider::commands
Open
Open
$this->commands([
- Exclude checks
Call to undeclared function \config_path()
Open
Open
$this->publishes([$configFile => config_path('settings.php')]);
- Exclude checks
Class extends undeclared class \Illuminate\Support\ServiceProvider
Open
Open
class SettingsServiceProvider extends ServiceProvider
- Exclude checks
Call to undeclared method \Poisa\Settings\SettingsServiceProvider::publishes
Open
Open
$this->publishes([$configFile => config_path('settings.php')]);
- Exclude checks
Reference to undeclared property \Poisa\Settings\SettingsServiceProvider->app
Open
Open
$this->app->singleton(Settings::class, function ($app) {
- Exclude checks
Call to undeclared function \config()
Open
Open
if (config('settings.automatic_migrations')) {
- Exclude checks
Call to undeclared method \Poisa\Settings\SettingsServiceProvider::loadMigrationsFrom
Open
Open
$this->loadMigrationsFrom($migrationPath);
- Exclude checks
Reference to undeclared property \Poisa\Settings\SettingsServiceProvider->app
Open
Open
if ($this->app->runningInConsole()) {
- Exclude checks
Remove the unused function parameter "$app". Open
Open
$this->app->singleton(Settings::class, function ($app) {
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect