Labels::setPlural()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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