Completed
Push — master ( d71805...ee9560 )
by Gorka
14s
created

PostType::taxonomyType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
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;
13
14
/**
15
 * Abstract class of base post type that implements the interface.
16
 * This class avoids the redundant task of create the same PostType constructor.
17
 * Also, it comes with basic implementation of "permalink" method.
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 * @author Gorka Laucirica <[email protected]>
21
 */
22
class PostType implements PostTypeInterface
0 ignored issues
show
Deprecated Code introduced by
The interface LIN3S\WPFoundation\PostTypes\PostTypeInterface has been deprecated with message: since version 1.7, will be made private in 2.0. Use PostType class.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
{
24
    private $name;
25
    private $options;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param string $name
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
31
     * @param array $options
32
     */
33
    public function __construct($name = null, $options = [])
34
    {
35
        $this->name = $name;
36
        $this->options = $options;
37
38
        add_action('init', [$this, 'postType']);
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...
39
        add_action('init', [$this, 'taxonomyType']);
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...
40
        add_action('init', [$this, 'fields'], 20);
0 ignored issues
show
Unused Code introduced by
The call to add_action() has too many arguments starting with 20.

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 add_action() seems unnecessary as the function has no side-effects.
Loading history...
41
        add_action('init', [$this, 'rewriteRules'], 20);
0 ignored issues
show
Unused Code introduced by
The call to add_action() has too many arguments starting with 20.

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 add_action() seems unnecessary as the function has no side-effects.
Loading history...
42
43
        add_filter('post_type_link', [$this, 'permalink'], 1, 2);
0 ignored issues
show
Unused Code introduced by
The call to add_filter() has too many arguments starting with 1.

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 add_filter() seems unnecessary as the function has no side-effects.
Loading history...
44
        add_filter('term_link', [$this, 'taxonomyPermalink'], 1, 2);
0 ignored issues
show
Unused Code introduced by
The call to add_filter() has too many arguments starting with 1.

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 add_filter() seems unnecessary as the function has no side-effects.
Loading history...
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function fields()
51
    {
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function permalink($permalink, $id = 0)
58
    {
59
        return $permalink;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function rewriteRules()
66
    {
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public static function serialize($postTypes)
73
    {
74
        if (is_array($postTypes)) {
75
            foreach ($postTypes as $key => $postType) {
76
                $postTypes[$key] = static::singleSerialize($postType);
0 ignored issues
show
Deprecated Code introduced by
The method LIN3S\WPFoundation\PostT...Type::singleSerialize() has been deprecated with message: since version 1.7, will be removed in 2.0. Create a custom serializer class.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
77
            }
78
79
            return $postTypes;
80
        }
81
        $postType = $postTypes;
82
83
        return static::singleSerialize($postType);
0 ignored issues
show
Deprecated Code introduced by
The method LIN3S\WPFoundation\PostT...Type::singleSerialize() has been deprecated with message: since version 1.7, will be removed in 2.0. Create a custom serializer class.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function taxonomyPermalink($url, $term)
90
    {
91
        return $url;
92
    }
93
94
    /**
95
     * Static method that simplifies the process of getting all data
96
     * from given post. This method is called by the main serialize method.
97
     *
98
     * @param object $postType The post type
99
     *
100
     * @deprecated since version 1.7, will be removed in 2.0. Create a custom serializer class.
101
     *
102
     * @return object Serialized given post type
103
     */
104
    protected static function singleSerialize($postType)
105
    {
106
        return $postType;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function postType()
113
    {
114
        if ($this->name !== null && $this->options !== null) {
115
            register_post_type($this->name, $this->options);
116
        }
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function taxonomyType()
123
    {
124
    }
125
}
126