Completed
Push — master ( e3f0be...13bac0 )
by Lars
01:45
created

CollectionStringy::createFromStrings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stringy;
6
7
class CollectionStringy extends \Arrayy\Collection\AbstractCollection
8
{
9 77
    public function getType(): string
10
    {
11 77
        return Stringy::class;
12
    }
13
14
    /**
15
     * @return Stringy[]
16
     */
17
    public function getAll(): array
18
    {
19
        return parent::getAll();
20
    }
21
22
    /**
23
     * @return \Generator|Stringy[]
24
     */
25 76
    public function getGenerator(): \Generator
26
    {
27 76
        return parent::getGenerator();
28
    }
29
30
    /**
31
     * @return string[]
32
     */
33 1
    public function toStrings(): array {
34
        // init
35 1
        $result = [];
36
37 1
        foreach ($this->getArray() as $key => $value) {
38
            /** @var $value Stringy */
39 1
            $result[$key] = $value->toString();
40
        }
41
42 1
        return $result;
43
    }
44
45
    public function addString(string $string): CollectionStringy
46
    {
47
        $this->add(Stringy::create($string));
48
49
        return $this;
50
    }
51
52
    /**
53
     * @param string[] $strings
54
     *
55
     * @return static
56
     */
57 1
    public static function createFromStrings($strings = []): self {
58 1
        foreach ($strings as &$string) {
59 1
            $string = Stringy::create($string);
60
        }
61
62 1
        return new static($strings);
63
    }
64
}
65