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

Builder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forTypes() 0 6 2
A register() 0 10 2
1
<?php
2
3
namespace Silk\Taxonomy;
4
5
use Silk\Taxonomy\Taxonomy;
6
use Silk\Type\Builder as TypeBuilder;
7
use Silk\Exception\WP_ErrorException;
8
use Illuminate\Support\Collection;
9
10
class Builder extends TypeBuilder
11
{
12
    /**
13
     * Object types this taxonomy will be registered for
14
     * @var array
15
     */
16
    protected $objectTypes = [];
17
18
    /**
19
     * Default taxonomy labels
20
     * @var array
21
     */
22
    protected $labelDefaults = [
23
        'add_new_item'               => 'Add New {one}',
24
        'add_or_remove_items'        => NULL,
25
        'all_items'                  => 'All {many}',
26
        'archives'                   => 'All {many}',
27
        'choose_from_most_used'      => NULL,
28
        'edit_item'                  => 'Edit {one}',
29
        'items_list_navigation'      => '{many} list navigation',
30
        'items_list'                 => '{many} list',
31
        'menu_name'                  => '{many}',
32
        'name_admin_bar'             => '{one}',
33
        'name'                       => '{many}',
34
        'new_item_name'              => 'New {one} Name',
35
        'no_terms'                   => 'No {many}',
36
        'not_found'                  => 'No {many} found.',
37
        'parent_item_colon'          => 'Parent {one}:',
38
        'parent_item'                => 'Parent {one}',
39
        'popular_items'              => NULL,
40
        'search_items'               => 'Search {many}',
41
        'separate_items_with_commas' => NULL,
42
        'singular_name'              => '{one}',
43
        'update_item'                => 'Update {one}',
44
        'view_item'                  => 'View {one}',
45
    ];
46
47
    /**
48
     * Specify which object types the taxonomy is for.
49
     *
50
     * @param  ...string|array $types  A list of object types or an array.
0 ignored issues
show
Documentation introduced by
The doc-type ...string|array could not be parsed: Unknown type name "...string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
51
     *
52
     * @return $this
53
     */
54
    public function forTypes($types)
55
    {
56
        $this->objectTypes = is_array($types) ? $types : func_get_args();
57
58
        return $this;
59
    }
60
61
    /**
62
     * Register and return the new taxonomy.
63
     *
64
     * @return Taxonomy
65
     */
66
    public function register()
67
    {
68
        $error = register_taxonomy($this->id, $this->objectTypes, $this->assembleArgs());
69
70
        if (is_wp_error($error)) {
71
            throw new WP_ErrorException($error);
72
        }
73
74
        return Taxonomy::make($this->id);
75
    }
76
}
77