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

Labels   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSingular() 0 6 1
A setPlural() 0 6 1
A toArray() 0 14 1
1
<?php
2
3
namespace Silk\Type;
4
5
use Illuminate\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 $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 $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
                        '{one}',
59
                        '{many}'
60
                    ], [
61
                        $this->singularForm,
62
                        $this->pluralForm
63
                    ],
64
                    $label
65
                );
66
            })->all();
67
    }
68
}
69