File cli-models-command.php
has 364 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* CLI models command class
*
* @package Leaves_And_Love\Plugin_Lib
Function list_
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$query_args = array_merge( array( 'number' => -1 ), $assoc_args );
$query_args = self::process_csv_arguments_to_arrays( $query_args );
- 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
The class CLI_Models_Command has an overall complexity of 65 which is very high. The configured complexity threshold is 50. Open
abstract class CLI_Models_Command extends \WP_CLI\CommandWithDBObject {
/**
* The manager instance.
*
* @since 1.0.0
- Exclude checks
CLI_Models_Command
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class CLI_Models_Command extends \WP_CLI\CommandWithDBObject {
/**
* The manager instance.
*
* @since 1.0.0
Method list_
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$query_args = array_merge( array( 'number' => -1 ), $assoc_args );
$query_args = self::process_csv_arguments_to_arrays( $query_args );
Function create
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function create( $args, $assoc_args ) {
$singular_name = $this->prepare_type_for_output( $this->obj_type );
if ( method_exists( $this->manager, 'get_content_property' ) ) {
$content_property = $this->manager->get_content_property();
- 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
Method get_create_args
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_create_args( $name ) {
$singular_name = $this->prepare_type_for_output( $this->obj_type );
$synopsis = array();
Method get_list_args
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_list_args( $name ) {
$singular_name = $this->prepare_type_for_output( $this->obj_type );
$plural_name = $this->prepare_type_for_output( $this->obj_type_plural );
$synopsis = array(
Method get_get_args
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_get_args( $name ) {
$singular_name = $this->prepare_type_for_output( $this->obj_type );
$synopsis = array(
array(
Function update
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function update( $args, $assoc_args ) {
if ( method_exists( $this->manager, 'get_content_property' ) ) {
$content_property = $this->manager->get_content_property();
foreach ( $args as $key => $arg ) {
- 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
Method get_update_args
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_update_args( $name ) {
$singular_name = $this->prepare_type_for_output( $this->obj_type );
$plural_name = $this->prepare_type_for_output( $this->obj_type_plural );
$synopsis = array(
Function read_from_file_or_stdin
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function read_from_file_or_stdin( $arg ) {
if ( '-' !== $arg ) {
$readfile = $arg;
if ( ! file_exists( $readfile ) || ! is_file( $readfile ) ) {
\WP_CLI::error( "Unable to read content from '$readfile'." );
- 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
Function __construct
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function __construct( $manager ) {
$this->manager = $manager;
$this->fetcher = new CLI_Model_Fetcher( $this->manager );
- 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
The method list_() has an NPath complexity of 5184. The configured NPath complexity threshold is 200. Open
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$query_args = array_merge( array( 'number' => -1 ), $assoc_args );
$query_args = self::process_csv_arguments_to_arrays( $query_args );
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method list_() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function list_( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$query_args = array_merge( array( 'number' => -1 ), $assoc_args );
$query_args = self::process_csv_arguments_to_arrays( $query_args );
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$result = new WP_Error( 'cli_item_not_exists', sprintf( 'The %s %d does not exist.', $singular_name, $params[ $this->obj_id_key ] ) );
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using static access to class '\WP_CLI' in method 'edit'. Open
\WP_CLI::warning( sprintf( 'No change made to %s content.', $singular_name ), 'Aborted' );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name", new CLI_Command_Aggregate(), $this->get_general_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name edit", array( $this, 'edit' ), $this->get_edit_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name list", array( $this, 'list_' ), $this->get_list_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name create", array( $this, 'create' ), $this->get_create_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name update", array( $this, 'update' ), $this->get_update_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name get", array( $this, 'get' ), $this->get_get_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'read_from_file_or_stdin'. Open
\WP_CLI::error( "Unable to read content from '$readfile'." );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name delete", array( $this, 'delete' ), $this->get_delete_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\WP_CLI' in method 'add'. Open
\WP_CLI::add_command( "$name meta", new CLI_Model_Meta_Command( $this->manager ), $this->get_meta_args( $name ) );
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid unused parameters such as '$name'. Open
protected function get_delete_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_create_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_general_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_get_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_update_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_list_args( $name ) {
- 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
Avoid unused parameters such as '$args'. Open
public function list_( $args, $assoc_args ) {
- 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
Avoid unused parameters such as '$assoc_args'. Open
protected function delete_callback( $id, $assoc_args ) {
- 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
Avoid unused local variables such as '$params'. Open
$result = new WP_Error( 'cli_item_not_exists', sprintf( 'The %s %d does not exist.', $singular_name, $params[ $this->obj_id_key ] ) );
- 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
Avoid unused parameters such as '$assoc_args'. Open
public function edit( $args, $assoc_args ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_edit_args( $name ) {
- 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
Avoid unused parameters such as '$name'. Open
protected function get_meta_args( $name ) {
- 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
TODO found Open
/* TODO: \WP_CLI::add_command( "$name generate", array( $this, 'generate' ), $this->get_generate_args( $name ) ); */
- Exclude checks