must_use_loader.php
Method list_subdir_mu_plugins
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function list_subdir_mu_plugins() {
foreach ( $this->plugins as $plugin_file ) {
$plugin_data = $this->filter_plugin_data( $plugin_file );
Function get_mu_plugins
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
public function get_mu_plugins() {
// Invalid cache
$plugins = [];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid unused local variables such as '$not_used'. Open
Open
foreach ( $mu_plugins as $plugin_file => $not_used ) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The method subdir_mu_plugins_files uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
// Get cached plugins.
$plugins = $this->get_transient();
// Refresh if the transient is wrong.
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Filenames should be all lowercase with hyphens as word separators. Expected must-use-loader.php, but found must_use_loader.php. Open
Open
<?php
- Exclude checks
Opening PHP tag must be on a line by itself Open
Open
<?php printf(
- Exclude checks
A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders. Open
Open
esc_attr__( 'Version %1$s | By %2$s %3$s' ),
- Exclude checks
Class file names should be based on the class name with "class-" prepended. Expected class-must-use-loader.php, but found must_use_loader.php. Open
Open
<?php
- Exclude checks
When a multi-item array uses associative keys, each value should start on a new line. Open
Open
'a' => [ 'href' => TRUE, 'title' => TRUE ],
- Exclude checks
Class name must begin with a capital letter Open
Open
class must_use_loader {
- Exclude checks
Class name is not valid; consider Must_Use_Loader instead Open
Open
class must_use_loader {
- Exclude checks
Closing PHP tag must be on a line by itself Open
Open
); ?>
- Exclude checks
Use Yoda Condition checks, you must. Open
Open
if ( '.' !== dirname( $plugin_file ) && dirname( $plugin_file )[0] !== '_' ) {
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'sanitize_title'. Open
Open
<tr id="<?php echo sanitize_title( $plugin_file ); ?>" class="active">
- Exclude checks
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'. Open
Open
mustuse = value + <?php echo $this->mustuse_total; ?>;
- Exclude checks
No space found before comment text; expected "// $this->set_network_plugin_option( $plugin_file );" but found "//$this->set_network_plugin_option( $plugin_file );" Open
Open
//$this->set_network_plugin_option( $plugin_file );
- Exclude checks
Closing PHP tag must be on a line by itself Open
Open
]; ?>
- Exclude checks