Method template_redirect_action
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function template_redirect_action() {
global $wpdb;
if ( ! is_404() ) {
return;
- Create a ticketCreate a ticket
Function template_redirect_action
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function template_redirect_action() {
global $wpdb;
if ( ! is_404() ) {
return;
- Read upRead up
- Create a ticketCreate a ticket
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 template_redirect_action() contains an exit expression. Open
exit;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid using static access to class '\Mi11er\Utility\Template_Tags' in method 'template_redirect_action'. Open
$request_url = TT::get_the_request_url();
- Read upRead up
- Create a ticketCreate a ticket
- 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 assigning values to variables in if clauses and the like (line '89', column '18'). Open
public function template_redirect_action() {
global $wpdb;
if ( ! is_404() ) {
return;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = (int) $wpdb->get_var( $wpdb->prepare(
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The parameter $post_type is not named in camelCase. Open
function add_meta_boxes_action( $post_type, $post ) {
if ( ! empty( get_post_meta( $post->ID, self::META_FIELD, false ) ) ) {
add_meta_box(
self::META_BOX,
__( 'Old URL Redirect', 'mi11er-utility' ),
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The method add_meta_boxes_action is not named in camelCase. Open
function add_meta_boxes_action( $post_type, $post ) {
if ( ! empty( get_post_meta( $post->ID, self::META_FIELD, false ) ) ) {
add_meta_box(
self::META_BOX,
__( 'Old URL Redirect', 'mi11er-utility' ),
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method template_redirect_action is not named in camelCase. Open
public function template_redirect_action() {
global $wpdb;
if ( ! is_404() ) {
return;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method old_url_redirect_meta_box is not named in camelCase. Open
public function old_url_redirect_meta_box( $post ) {
?>
<ul>
<?php foreach ( get_post_meta( $post->ID, self::META_FIELD, false ) as $value ) : ?>
<li><?php echo esc_html( $value ); ?></li>
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}