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; |
|
|
|
|
106
|
|
|
|
107
|
2 |
|
return new static($strings); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This checks looks for cases where a variable has been assigned to itself.
This assignement can be removed without consequences.