Completed
Pull Request — master (#19)
by Evan
02:29
created

Builder::register()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 2
b 0
f 1
nc 2
nop 0
dl 0
loc 10
rs 9.4285
1
<?php
2
3
namespace Silk\Taxonomy;
4
5
use Silk\Taxonomy\Taxonomy;
6
use Silk\Type\Builder as TypeBuilder;
7
use Illuminate\Support\Collection;
8
use Silk\Taxonomy\Exception\InvalidTaxonomyNameException;
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
     * @throws \Silk\Taxonomy\Exception\InvalidTaxonomyNameException
65
     *
66
     * @return Taxonomy
67
     */
68
    public function register()
69
    {
70
        if (! $this->id || strlen($this->id) > 32) {
71
            throw new InvalidTaxonomyNameException('Taxonomy names must be between 1 and 32 characters in length.');
72
        }
73
74
        register_taxonomy($this->id, $this->objectTypes, $this->assembleArgs());
75
76
        return Taxonomy::make($this->id);
77
    }
78
}
79