CustomPostTypeFields::connector()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-present 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
 * @deprecated since version 1.7, will be removed in 2.0. Use Fields constructor
22
 */
23
abstract class CustomPostTypeFields extends Fields
24
{
25
    /**
26
     * Constructor.
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
32
        add_action('admin_init', [$this, 'addScreenAttributes']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
33
        add_action('admin_init', [$this, 'removeScreenAttributes']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function connector()
40
    {
41
        return [
42
            [
43
                [
44
                    'param'    => 'post_type',
45
                    'operator' => '==',
46
                    'value'    => $this->name,
47
                ],
48
            ],
49
        ];
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function removeScreenAttributes()
56
    {
57
        remove_post_type_support($this->name, 'comments');
0 ignored issues
show
Unused Code introduced by
The call to remove_post_type_support() has too many arguments starting with $this->name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the function remove_post_type_support() seems unnecessary as the function has no side-effects.
Loading history...
58
        remove_post_type_support($this->name, 'custom-fields');
0 ignored issues
show
Unused Code introduced by
The call to remove_post_type_support() has too many arguments starting with $this->name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the function remove_post_type_support() seems unnecessary as the function has no side-effects.
Loading history...
59
    }
60
}
61