Skip to content

Commit 7cc581f

Browse files
Merge pull request #31 from matthiasnoback/fransik-improved-types
Fransik improved types
2 parents 6c4a2eb + a99eae2 commit 7cc581f

File tree

16 files changed

+165
-70
lines changed

16 files changed

+165
-70
lines changed

build_and_push.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
4+
# Use this script to build new versions of the Docker images that can be pulled by anyone who wants to run the tests.
5+
6+
set -e
7+
8+
docker-compose build
9+
docker-compose push

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"php": ">=7.2",
1212
"doctrine/dbal": "^2.5",
1313
"webmozart/assert": "^1.4",
14-
"ext-pdo": "*"
14+
"ext-pdo": "*",
15+
"composer/package-versions-deprecated": "1.11.99.1"
1516
},
1617
"require-dev": {
1718
"doctrine/migrations": "^1.5",

composer.lock

Lines changed: 76 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/php72/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RUN docker-php-ext-install pdo pdo_mysql \
3131

3232
# Install Xdebug (for code coverage)
3333
RUN apk add --no-cache --virtual .build-dependencies $PHPIZE_DEPS \
34-
&& pecl install xdebug \
34+
&& pecl install xdebug-2.9.8 \
3535
&& docker-php-ext-enable xdebug \
3636
&& apk --no-cache del .build-dependencies \
3737
&& php -m | grep xdebug

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ HOST_GID=$(id -g)
77

88
mkdir -p build/logs/
99
docker-compose up -d mysql
10+
sleep 5
1011

1112
docker-compose run --user="${HOST_UID}:${HOST_GID}" php72 \
1213
composer install --prefer-dist

src/TalisOrm/Aggregate.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* @see AggregateBehavior
9+
* @phpstan-template T
910
*/
1011
interface Aggregate extends Entity
1112
{
@@ -21,6 +22,10 @@ interface Aggregate extends Entity
2122
* return [
2223
* Line::class => $this->lines()
2324
* ];
25+
*
26+
* @return array<string, mixed[]>
27+
*
28+
* @phpstan-return array<class-string<ChildEntity>, mixed[]>
2429
*/
2530
public function childEntitiesByType(): array;
2631

@@ -30,6 +35,10 @@ public function childEntitiesByType(): array;
3035
* return [
3136
* Line::class
3237
* ]
38+
*
39+
* @return array<int, string>
40+
*
41+
* @phpstan-return array<int, class-string<ChildEntity>>
3342
*/
3443
public static function childEntityTypes(): array;
3544

@@ -50,9 +59,12 @@ public static function childEntityTypes(): array;
5059
* return $order;
5160
* }
5261
*
53-
* @param array $aggregateState
54-
* @param array $childEntitiesByType
62+
* @param array<string, mixed> $aggregateState
63+
* @param array<string, mixed[]> $childEntitiesByType
5564
* @return static
65+
*
66+
* @phpstan-param array<class-string<ChildEntity>, mixed[]> $childEntitiesByType
67+
* @phpstan-return T
5668
*/
5769
public static function fromState(array $aggregateState, array $childEntitiesByType);
5870

src/TalisOrm/AggregateBehavior.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
namespace TalisOrm;
55

66
use TalisOrm\DomainEvents\EventRecordingCapabilities;
7-
use Webmozart\Assert\Assert;
87

98
trait AggregateBehavior
109
{
1110
use EventRecordingCapabilities;
1211

1312
/**
14-
* @var array
13+
* @var ChildEntity[]
1514
*/
1615
private $deletedChildEntities = [];
1716

@@ -34,7 +33,7 @@ public function deletedChildEntities(): array
3433
return $deletedChildEntities;
3534
}
3635

37-
private function deleteChildEntity(ChildEntity $childEntity)
36+
private function deleteChildEntity(ChildEntity $childEntity): void
3837
{
3938
$this->deletedChildEntities[] = $childEntity;
4039
}
@@ -49,10 +48,7 @@ public function markAsPersisted(): void
4948
$this->isNew = false;
5049
}
5150

52-
/**
53-
* @return int
54-
*/
55-
public function aggregateVersion()
51+
public function aggregateVersion(): int
5652
{
5753
return $this->aggregateVersion;
5854
}

src/TalisOrm/AggregateRepository.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use TalisOrm\DomainEvents\EventDispatcher;
1212
use Webmozart\Assert\Assert;
1313

14+
/**
15+
* @phpstan-template T of Aggregate
16+
*/
1417
final class AggregateRepository
1518
{
1619
/**
@@ -31,11 +34,12 @@ public function __construct(Connection $connection, EventDispatcher $eventDispat
3134

3235
/**
3336
* @throws ConcurrentUpdateOccurred (only when you use optimistic concurrency locking)
37+
*
38+
* @phpstan-param T $aggregate
3439
*/
3540
public function save(Aggregate $aggregate): void
3641
{
3742
$this->connection->transactional(function () use ($aggregate) {
38-
/** @var Entity[] $persistedEntities */
3943
$persistedEntities = [];
4044

4145
$this->insertOrUpdate($aggregate);
@@ -63,6 +67,13 @@ public function save(Aggregate $aggregate): void
6367
$this->eventDispatcher->dispatch($aggregate->releaseEvents());
6468
}
6569

70+
/**
71+
* @param array<string, mixed> $extraState
72+
* @return mixed|Aggregate
73+
*
74+
* @phpstan-param class-string<T> $aggregateClass
75+
* @phpstan-return T
76+
*/
6677
public function getById(string $aggregateClass, AggregateId $aggregateId, array $extraState = []): Aggregate
6778
{
6879
if (!is_a($aggregateClass, Aggregate::class, true)) {
@@ -92,6 +103,11 @@ public function getById(string $aggregateClass, AggregateId $aggregateId, array
92103
return $aggregate;
93104
}
94105

106+
/**
107+
* @return array<string, mixed>
108+
*
109+
* @phpstan-param class-string<T> $aggregateClass
110+
*/
95111
private function getAggregateState(string $aggregateClass, AggregateId $aggregateId): array
96112
{
97113
$aggregateStates = $this->fetchAll(
@@ -115,7 +131,11 @@ private function getAggregateState(string $aggregateClass, AggregateId $aggregat
115131
}
116132

117133
/**
118-
* @return array[]
134+
* @param array<string, mixed> $aggregateState
135+
* @return array<string, mixed[]>
136+
*
137+
* @phpstan-param class-string<T> $aggregateClass
138+
* @phpstan-return array<class-string<ChildEntity>, mixed[]>
119139
*/
120140
private function getChildEntitiesByType(
121141
string $aggregateClass,
@@ -145,6 +165,9 @@ function (array $childEntityState) use ($childEntityType, $aggregateState) {
145165
return $childEntitiesByType;
146166
}
147167

168+
/**
169+
* @phpstan-param T $aggregate
170+
*/
148171
public function delete(Aggregate $aggregate): void
149172
{
150173
$this->connection->transactional(function () use ($aggregate) {
@@ -155,7 +178,6 @@ public function delete(Aggregate $aggregate): void
155178

156179
foreach ($aggregate->childEntitiesByType() as $type => $childEntities) {
157180
foreach ($childEntities as $childEntity) {
158-
/** @var ChildEntity $childEntity */
159181
$this->connection->delete(
160182
$this->connection->quoteIdentifier($childEntity::tableName()),
161183
$childEntity->identifier()
@@ -194,7 +216,8 @@ private function insertOrUpdate(Entity $entity): void
194216
}
195217

196218
/**
197-
* @return array[]
219+
* @param array<string, mixed> $identifier
220+
* @return array<int, array<string, mixed>>
198221
*/
199222
private function fetchAll(string $tableName, array $identifier): array
200223
{
@@ -206,7 +229,8 @@ private function fetchAll(string $tableName, array $identifier): array
206229
/**
207230
* This method might have been on Connection itself...
208231
*
209-
* @return ResultStatement
232+
* @param array<string, mixed> $where
233+
* @return ResultStatement<mixed>
210234
*/
211235
private function select(string $selectExpression, string $tableExpression, array $where): ResultStatement
212236
{

src/TalisOrm/ChildEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ interface ChildEntity extends Entity
1818
*
1919
* return $line;
2020
*
21-
* @param array $state
22-
* @param array $aggregateState
21+
* @param array<string, mixed> $state
22+
* @param array<string, mixed> $aggregateState
2323
* @return static
2424
*/
2525
public static function fromState(array $state, array $aggregateState);

src/TalisOrm/ConcurrentUpdateOccurred.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public static function ofEntity(Entity $entity): ConcurrentUpdateOccurred
1515
));
1616
}
1717

18+
/**
19+
* @param array<string, mixed> $identifier
20+
*/
1821
private static function renderIdentifier(array $identifier): string
1922
{
2023
$parts = [];

0 commit comments

Comments
 (0)