Completed
Push — master ( 7c4b33...dbfb4d )
by Lars
01:43
created

CollectionStringy   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 73.68%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 14
cts 19
cp 0.7368
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 4 1
A getAll() 0 4 1
A getGenerator() 0 4 1
A toStrings() 0 12 2
A addString() 0 6 1
A createFromStrings() 0 8 2
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
    {
35
        // init
36 1
        $result = [];
37
38 1
        foreach ($this->getArray() as $key => $value) {
39 1
            \assert($value instanceof Stringy);
40 1
            $result[$key] = $value->toString();
41
        }
42
43 1
        return $result;
44
    }
45
46
    public function addString(string $string): self
47
    {
48
        $this->add(Stringy::create($string));
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param string[] $strings
55
     *
56
     * @return static
57
     */
58 1
    public static function createFromStrings($strings = []): self
59
    {
60 1
        foreach ($strings as &$string) {
61 1
            $string = Stringy::create($string);
62
        }
63
64 1
        return new static($strings);
65
    }
66
}
67