Completed
Push — master ( ae5b26...262c7c )
by Evan
10s
created

PostTypeLabels   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setSingular() 0 8 1
A setPlural() 0 8 1
A toArray() 0 4 2
A merge() 0 8 2
1
<?php
2
3
namespace Silk\Post;
4
5
use Illuminate\Support\Collection;
6
use Silk\Support\LabelsCollection;
7
8
class PostTypeLabels
9
{
10
    /**
11
     * Labels referencing the singular form
12
     * @var array
13
     */
14
    protected $singular = [
15
        'add_new_item'          => 'Add New %s',
16
        'archives'              => '%s Archives',
17
        'edit_item'             => 'Edit %s',
18
        'insert_into_item'      => 'Insert into %s',
19
        'name_admin_bar'        => '%s',
20
        'new_item'              => 'New %s',
21
        'singular_name'         => '%s',
22
        'uploaded_to_this_item' => 'Uploaded to this %s',
23
        'view_item'             => 'View %s',
24
    ];
25
26
    /**
27
     * Labels referencing the plural form
28
     * @var array
29
     */
30
    protected $plural = [
31
        'all_items'             => 'All %s',
32
        'filter_items_list'     => 'Filter %s list',
33
        'items_list_navigation' => '%s list navigation',
34
        'items_list'            => '%s list',
35
        'menu_name'             => '%s',
36
        'name'                  => '%s',
37
        'not_found_in_trash'    => 'No %s found in Trash.',
38
        'not_found'             => 'No %s found.',
39
        'search_items'          => 'Search %s',
40
    ];
41
42
    /**
43
     * The master collection of labels
44
     * @var Collection
45
     */
46
    protected $labels;
47
48
    /**
49
     * Set the singular labels using the given form.
50
     *
51
     * @param $label The singular label form to use
52
     *
53
     * @return $this
54
     */
55
    public function setSingular($label)
56
    {
57
        $this->merge(
58
            LabelsCollection::make($this->singular)->setForm($label)
59
        );
60
61
        return $this;
62
    }
63
64
    /**
65
     * Set the plural labels using the given form.
66
     *
67
     * @param $label The plural label form to use
68
     *
69
     * @return $this
70
     */
71
    public function setPlural($label)
72
    {
73
        $this->merge(
74
            LabelsCollection::make($this->plural)->setForm($label)
75
        );
76
77
        return $this;
78
    }
79
80
    /**
81
     * Get all the labels as an array.
82
     *
83
     * @return array
84
     */
85
    public function toArray()
86
    {
87
        return $this->labels ? $this->labels->toArray() : [];
88
    }
89
90
    /**
91
     * Merge the labels with the master collection.
92
     *
93
     * @param  LabelsCollection $collection
94
     */
95
    protected function merge(LabelsCollection $collection)
96
    {
97
        if (! $this->labels) {
98
            $this->labels = new Collection;
99
        }
100
101
        $this->labels = $this->labels->merge($collection->replaced());
102
    }
103
}
104