Completed
Push — master ( dc809d...ea43b1 )
by Lars
03:20
created

CollectionStringy   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
dl 0
loc 98
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

7 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 8 2
A addStringy() 0 8 2
A createFromStrings() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stringy;
6
7
/**
8
 * @template TKey of array-key
9
 * @template T
10
 * @extends \Arrayy\Collection\Collection<TKey,T|Stringy>
11
 */
12
class CollectionStringy extends \Arrayy\Collection\Collection
13
{
14 83
    public function getType(): string
15
    {
16 83
        return Stringy::class;
17
    }
18
19
    /**
20
     * @return Stringy[]
21
     *
22
     * @psalm-return array<array-key,Stringy>
23
     *
24
     * @noinspection SenselessProxyMethodInspection - other phpdocs ;)
25
     */
26
    public function getAll(): array
27
    {
28
        return parent::getAll();
29
    }
30
31
    /**
32
     * @return \Generator|Stringy[]
33
     *
34
     * @psalm-return \Generator<mixed,Stringy>|\Generator<TKey,Stringy>
35
     * @psalm-mutation-free
36
     *
37
     * @noinspection PhpInconsistentReturnPointsInspection
38
     * @noinspection SenselessProxyMethodInspection - other phpdocs ;)
39
     */
40 82
    public function getGenerator(): \Generator
41
    {
42 82
        return parent::getGenerator();
43
    }
44
45
    /**
46
     * @return string[]
47
     */
48 2
    public function toStrings(): array
49
    {
50
        // init
51 2
        $result = [];
52
53 2
        foreach ($this->getArray() as $key => $value) {
54 2
            \assert($value instanceof Stringy);
55 2
            $result[$key] = $value->toString();
56
        }
57
58 2
        return $result;
59
    }
60
61
    /**
62
     * @param string ...$string
63
     *
64
     * @return $this
65
     *
66
     * @noinspection PhpDocSignatureInspection
67
     */
68 1
    public function addString(string ...$string): self
69
    {
70 1
        foreach ($string as $stringTmp) {
71 1
            $this->add(Stringy::create($stringTmp));
72
        }
73
74 1
        return $this;
75
    }
76
77
    /**
78
     * @param Stringy ...$stringy
79
     *
80
     * @return $this
81
     */
82 1
    public function addStringy(Stringy ...$stringy): self
83
    {
84 1
        foreach ($stringy as $stringyTmp) {
85 1
            $this->add($stringyTmp);
86
        }
87
88 1
        return $this;
89
    }
90
91
    /**
92
     * @param string[] $strings
93
     *
94
     * @return static
95
     */
96 2
    public static function createFromStrings($strings = []): self
97
    {
98
        /** @noinspection AlterInForeachInspection */
99 2
        foreach ($strings as &$string) {
100 2
            $string = Stringy::create($string);
101
        }
102
103
        /** @noinspection PhpSillyAssignmentInspection */
104
        /** @var Stringy[] $strings */
105 2
        $strings = $strings;
0 ignored issues
show
Bug introduced by
Why assign $strings to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
106
107 2
        return new static($strings);
108
    }
109
}
110