Labels   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setPlural() 0 5 1
A toArray() 0 15 1
A setSingular() 0 5 1
1
<?php
2
3
namespace Silk\Type;
4
5
use Silk\Support\Collection;
6
7
class Labels extends Collection
8
{
9
    /**
10
     * Label form for a single entity
11
     * @var string
12
     */
13
    protected $singularForm;
14
15
    /**
16
     * Label form for a multiple entities
17
     * @var string
18
     */
19
    protected $pluralForm;
20
21
    /**
22
     * Set the singular labels using the given form.
23
     *
24
     * @param string $label The singular label form to use
25
     *
26
     * @return $this
27
     */
28
    public function setSingular($label)
29
    {
30
        $this->singularForm = $label;
31
32
        return $this;
33
    }
34
35
    /**
36
     * Set the plural labels using the given form.
37
     *
38
     * @param string $label The plural label form to use
39
     *
40
     * @return $this
41
     */
42
    public function setPlural($label)
43
    {
44
        $this->pluralForm = $label;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Get all the labels as an array.
51
     *
52
     * @return array
53
     */
54
    public function toArray()
55
    {
56
        return $this->map(function ($label) {
57
            return str_replace(
58
                [
59
                    '{one}',
60
                    '{many}'
61
                ],
62
                [
63
                    $this->singularForm,
64
                    $this->pluralForm
65
                ],
66
                $label
67
            );
68
        })->all();
69
    }
70
}
71