Completed
Branch develop (73bc23)
by Evan
02:37
created

Builder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A supports() 0 8 2
A open() 0 4 1
A closed() 0 4 1
A withUI() 0 4 1
A noUI() 0 4 1
A register() 0 6 1
1
<?php
2
3
namespace Silk\PostType;
4
5
use Silk\Type\Builder as BaseBuilder;
6
use Illuminate\Support\Collection;
7
use Silk\PostType\Exception\InvalidPostTypeNameException;
8
9
class Builder extends BaseBuilder
10
{
11
    /**
12
     * [$labelDefaults description]
13
     * @var array
14
     */
15
    protected $labelDefaults = [
16
        'add_new_item'          => 'Add New {one}',
17
        'all_items'             => 'All {many}',
18
        'archives'              => '{one} Archives',
19
        'edit_item'             => 'Edit {one}',
20
        'filter_items_list'     => 'Filter {many} list',
21
        'insert_into_item'      => 'Insert into {one}',
22
        'items_list_navigation' => '{many} list navigation',
23
        'items_list'            => '{many} list',
24
        'menu_name'             => '{many}',
25
        'name_admin_bar'        => '{one}',
26
        'name'                  => '{many}',
27
        'new_item'              => 'New {one}',
28
        'not_found_in_trash'    => 'No {many} found in Trash.',
29
        'not_found'             => 'No {many} found.',
30
        'search_items'          => 'Search {many}',
31
        'singular_name'         => '{one}',
32
        'uploaded_to_this_item' => 'Uploaded to this {one}',
33
        'view_item'             => 'View {one}',
34
    ];
35
36
    /**
37
     * PostTypeBuilder constructor.
38
     *
39
     * @param string $slug  post type slug
40
     * @param array $args   initial registration arguments
41
     */
42
    public function __construct($slug, array $args = [])
43
    {
44
        if (strlen($slug) < 1 || strlen($slug) > 20) {
45
            throw new InvalidPostTypeNameException('Post type names must be between 1 and 20 characters in length.');
46
        }
47
48
        parent::__construct($slug, $args);
49
    }
50
51
    /**
52
     * Specify which features the post type supports.
53
     *
54
     * @param  mixed $features  array of features
55
     *         string ...$features  features as parameters
56
     *
57
     * @return $this
58
     */
59
    public function supports($features)
60
    {
61
        if (! is_array($features)) {
62
            $features = func_get_args();
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $features. This often makes code more readable.
Loading history...
63
        }
64
65
        return $this->set('supports', $features);
66
    }
67
68
    /**
69
     * Set the post type as publicly available.
70
     *
71
     * @return $this
72
     */
73
    public function open()
74
    {
75
        return $this->set('public', true);
76
    }
77
78
    /**
79
     * Set the post type as non-publicly available.
80
     *
81
     * @return $this
82
     */
83
    public function closed()
84
    {
85
        return $this->set('public', false);
86
    }
87
88
    /**
89
     * Enable admin interface.
90
     *
91
     * @return $this
92
     */
93
    public function withUI()
94
    {
95
        return $this->set('show_ui', true);
96
    }
97
98
    /**
99
     * Disable admin interface.
100
     *
101
     * @return $this
102
     */
103
    public function noUI()
104
    {
105
        return $this->set('show_ui', false);
106
    }
107
108
    /**
109
     * Register the post type.
110
     *
111
     * @return PostType
112
     */
113
    public function register()
114
    {
115
        $object = register_post_type($this->id, $this->assembleArgs());
116
117
        return new PostType($object);
118
    }
119
}
120