Completed
Branch EDTR/master (da238f)
by
unknown
09:58 queued 01:23
created

WordPressPageEditorEdit   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A isMatchingRoute() 13 13 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\specifications\admin;
4
5
use EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecification;
6
use WP_Post;
7
8
/**
9
 * Class WordPressPageEditorEdit
10
 * Returns true when the current request is for the WordPress Page Editor admin page while editing an existing page
11
 *
12
 * @package EventEspresso\core\domain\entities\routing\specifications\admin
13
 * @author  Brent Christensen
14
 * @since   4.9.71.p
15
 */
16 View Code Duplication
class WordPressPageEditorEdit extends RouteMatchSpecification
17
{
18
    /**
19
     * returns true if current request matches specification
20
     *
21
     * @since 4.9.71.p
22
     * @return boolean
23
     */
24
    public function isMatchingRoute()
25
    {
26
        global $post;
27
        return strpos($this->request->requestUri(), 'wp-admin/post.php') !== false
28
            && (
29
                $this->request->getRequestParam('post_type', 'post') === 'page'
30
                || (
31
                    $post instanceof WP_Post
0 ignored issues
show
Bug introduced by
The class WP_Post does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
32
                    && $post->post_type === 'page'
33
                )
34
            )
35
            && $this->request->getRequestParam('action') === 'edit';
36
    }
37
}
38