8000 sa · msgphp/msgphp@4b55c2b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b55c2b

Browse files
committed
sa
1 parent 80115bb commit 4b55c2b

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

docs/ddd/identifiers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ A decorating identifier to built custom/concrete identifiers upon.
6464
```php
6565
<?php
6666

67-
use MsgPhp\Domain\AbstractDomainId;use MsgPhp\Domain\DomainId;
67+
use MsgPhp\Domain\AbstractDomainId;
6868

6969
// SETUP
7070

src/Domain/DomainCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function get($key);
4545
/**
4646
* @param callable(T):bool $filter
4747
*
48-
* @return self<TKey, T>
48+
* @return static<TKey, T>
4949
*/
5050
public function filter(callable $filter): self;
5151

5252
/**
53-
* @return self<TKey, T>
53+
* @return static<TKey, T>
5454
*/
5555
public function slice(int $offset, int $limit = 0): self;
5656

@@ -59,7 +59,7 @@ public function slice(int $offset, int $limit = 0): self;
5959
*
6060
* @param callable(T):T2 $mapper
6161
*
62-
* @return self<TKey, T2>
62+
* @return static<TKey, T2>
6363
*/
6464
public function map(callable $mapper): self;
6565
}

src/Domain/Factory/GenericDomainObjectFactory.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function setNestedFactory(?DomainObjectFactory $factory): void
3232
$this->factory = $factory;
3333
}
3434

35+
/**
36+
* @template T
37+
*
38+
* @param class-string<T> $class
39+
*
40+
* @return T
41+
*/
3542
public function create(string $class, array $context = []): object
3643
{
3744
$class = $this->getClass($class, $context);
@@ -48,6 +55,13 @@ public function create(string $class, array $context = []): object
4855
return new $class(...$this->resolveArguments($class, '__construct', $context));
4956
}
5057

58+
/**
59+
* @template T
60+
*
61+
* @param class-string<T> $class
62+
*
63+
* @return T
64+
*/
5165
public function reference(string $class, array $context = []): object
5266
{
5367
if (!class_exists(Instantiator::class)) {

src/Domain/GenericDomainCollection.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ public function contains($element): bool
8787
public function containsKey($key): bool
8888
{
8989
if ($this->elements instanceof \Traversable) {
90-
/** @psalm-suppress InvalidCast */
91-
$key = \is_int($key) ? (string) $key : $key;
9290
foreach ($this->elements as $knownKey => $element) {
93-
/** @psalm-suppress InvalidCast */
94-
if ($key === (\is_int($knownKey) ? (string) $knownKey : $knownKey)) {
91+
if ((string) $key === (string) $knownKey) {
9592
return true;
9693
}
9794
}
@@ -145,11 +142,8 @@ public function last()
145142
public function get($key)
146143
{
147144
if ($this->elements instanceof \Traversable) {
148-
/** @psalm-suppress InvalidCast */
149-
$key = \is_int($key) ? (string) $key : $key;
150145
foreach ($this->elements as $knownKey => $element) {
151-
/** @psalm-suppress InvalidCast */
152-
if ($key === (\is_int($knownKey) ? (string) $knownKey : $knownKey)) {
146+
if ((string) $key === (string) $knownKey) {
153147
return $element;
154148
}
155149
}
@@ -164,6 +158,11 @@ public function get($key)
164158
throw UnknownCollectionElement::createForKey($key);
165159
}
166160

161+
/**
162+
* @param callable(T):bool $filter
163+
*
164+
* @return self<TKey, T>
165+
*/
167166
public function filter(callable $filter): DomainCollection
168167
{
169168
if ($this->elements instanceof \Traversable) {
@@ -203,6 +202,10 @@ public function slice(int $offset, int $limit = 0): DomainCollection
203202

204203
/**
205204
* @template T2
205+
*
206+
* @param callable(T):T2 $mapper
207+
*
208+
* @return self<TKey, T2>
206209
*/
207210
public function map(callable $mapper): DomainCollection
208211
{

src/Domain/Infrastructure/Doctrine/DomainObjectFactory.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ public function __construct(BaseDomainObjectFactory $factory, EntityManagerInter
2222
$this->em = $em;
2323
}
2424

25+
/**
26+
* @template T
27+
*
28+
* @param class-string<T> $class
29+
*
30+
* @return T
31+
*/
2532
public function create(string $class, array $context = []): object
2633
{
2734
/** @var T */
2835
return $this->factory->create($this->resolveDiscriminatorClass($class, $context), $context);
2936
}
3037

38+
/**
39+
* @template T
40+
*
41+
* @param class-string<T> $class
42+
*
43+
* @return T
44+
*/
3145
public function reference(string $class, array $context = []): object
3246
{
3347
$class = $this->factory->getClass($class, $context);

0 commit comments

Comments
 (0)
0