Skip to content

Commit 5ec0006

Browse files
committed
chore: PHPStan fixes
1 parent 054a9b5 commit 5ec0006

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/Concise.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Articulate\Concise\Contracts\EntityMapper;
77
use Articulate\Concise\Contracts\Repository;
8-
use Closure;
98
use Illuminate\Contracts\Foundation\Application;
109
use Illuminate\Database\DatabaseManager;
1110
use InvalidArgumentException;
@@ -226,8 +225,8 @@ public function repository(string $class): Repository
226225
$repository = $this->repositories[$class] ?? null;
227226

228227
if ($repository !== null) {
229-
return $repository;
230228
/** @phpstan-ignore return.type */
229+
return $repository;
231230
}
232231

233232
$repositoryClass = $mapper->repository();

src/ConciseServiceProvider.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ public function register(): void
1818
$this->booted($this->registerRepositories(...));
1919
}
2020

21+
/**
22+
* @param \Articulate\Concise\Concise $concise
23+
*
24+
* @return void
25+
*/
2126
protected function registerRepositories(Concise $concise): void
2227
{
23-
foreach ($concise->getEntityMappers() as $mapper) {
28+
/**
29+
* @var class-string $entity
30+
* @var \Articulate\Concise\Contracts\EntityMapper<*> $mapper
31+
*/
32+
foreach ($concise->getEntityMappers() as $entity => $mapper) {
2433
$repo = $mapper->repository();
2534

2635
if ($repo !== null) {
27-
$this->app->bind($repo, fn () => $concise->repository($mapper->getClass()));
36+
$this->app->bind($repo, fn () => $concise->repository($entity));
2837
}
2938
}
3039
}

src/Support/BaseRepository.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ protected function hydrate(?array $data): ?object
107107
*/
108108
protected function hydrateMany(Collection $collection): Collection
109109
{
110-
return $collection->map(fn (array $data) => $this->hydrate($data));
110+
$newCollection = new Collection();
111+
112+
foreach ($collection as $data) {
113+
$entity = $this->hydrate($data);
114+
115+
if ($entity !== null) {
116+
$newCollection->push($entity);
117+
}
118+
}
119+
120+
return $newCollection;
111121
}
112122
}

src/Support/MapperServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
abstract class MapperServiceProvider extends ServiceProvider
1010
{
11+
/**
12+
* @var array<class-string, class-string<\Articulate\Concise\Contracts\EntityMapper<*>>>
13+
*/
1114
protected array $mappers = [];
1215

1316
public function register(): void

0 commit comments

Comments
 (0)