Completed
Push — master ( 261499...3196a9 )
by Beñat
07:26
created

CustomPostTypeFields   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 1
dl 12
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connector() 0 12 1
A removeScreenAttributes() 0 5 1

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
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPFoundation\PostTypes\Fields;
13
14
/**
15
 * Abstract custom post type fields class that extends the fields basic
16
 * behaviour, implementing the "connector" and "removeScreenAttributes"
17
 * methods with the common use case.
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
abstract class CustomPostTypeFields extends Fields
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function connector()
27
    {
28
        return [
29
            [
30
                [
31
                    'param'    => 'post_type',
32
                    'operator' => '==',
33
                    'value'    => $this->name,
34
                ],
35
            ],
36
        ];
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function removeScreenAttributes()
43
    {
44
        remove_post_type_support('page', 'comments');
45
        remove_post_type_support('page', 'custom-fields');
46
    }
47
}
48