Skip to content

Commit 25c378a

Browse files
committed
Sync: add initial implementation of deferred sync entity resolution
Also: - Continue review of `SyncEntity` and related interfaces/classes/traits - Move `IResolvable::normaliser()` to new interface `ReturnsNormaliser` that extends `IResolvable` and adjust implementations accordingly - Clean up remaining @phpstan-param and @phpstan-return tags - Update documentation
1 parent 8dbb163 commit 25c378a

25 files changed

+229
-131
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ parameters:
5555
count: 1
5656
path: src/Concept/Facade.php
5757

58-
-
59-
message: "#^Method Lkrms\\\\Contract\\\\IExtensible\\:\\:getMetaProperty\\(\\) has no return type specified\\.$#"
60-
count: 1
61-
path: src/Contract/IExtensible.php
62-
63-
-
64-
message: "#^Method Lkrms\\\\Contract\\\\IExtensible\\:\\:setMetaProperty\\(\\) has parameter \\$value with no type specified\\.$#"
65-
count: 1
66-
path: src/Contract/IExtensible.php
67-
6858
-
6959
message: "#^Method Lkrms\\\\Contract\\\\IPipe\\:\\:handle\\(\\) has parameter \\$pipeline with generic interface Lkrms\\\\Contract\\\\IPipeline but does not specify its types\\: TInput, TOutput, TArgument$#"
7060
count: 1

src/Concern/HasNormaliser.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
namespace Lkrms\Concern;
44

5-
use Lkrms\Contract\IResolvable;
5+
use Lkrms\Contract\ReturnsNormaliser;
66
use Lkrms\Utility\Convert;
77
use Closure;
88

99
/**
10-
* Implements IResolvable
10+
* Implements ReturnsNormaliser
1111
*
12-
* @see IResolvable
12+
* @see ReturnsNormaliser
1313
*/
14-
trait TResolvable
14+
trait HasNormaliser
1515
{
1616
/**
17-
* @var array<string,Closure(string, bool=, string...): string>
17+
* @var array<string,Closure(string $name, bool $greedy=, string...$hints): string>
1818
*/
1919
private static $_Normaliser = [];
2020

2121
public static function normaliser(): Closure
2222
{
23-
return fn(string $name): string => Convert::toSnakeCase($name);
23+
return
24+
fn(string $name): string =>
25+
Convert::toSnakeCase($name);
2426
}
2527

2628
final public static function normalise(string $name, bool $greedy = true, string ...$hints): string

src/Concern/TConstructible.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,17 @@ final public static function construct(array $data, ?IContainer $container = nul
5151
*
5252
* See {@see TConstructible::construct()} for more information.
5353
*
54-
* @param iterable<mixed[]> $dataList
55-
* @param int $conformity One of the {@see ArrayKeyConformity} values. Use
56-
* `COMPLETE` or `PARTIAL` wherever possible to improve performance.
57-
* @phpstan-param ArrayKeyConformity::* $conformity
54+
* @param iterable<mixed[]> $list
55+
* @param ArrayKeyConformity::* $conformity Use `COMPLETE` or `PARTIAL`
56+
* wherever possible to improve performance.
5857
* @param IContainer|null $container Used to create each instance if set.
5958
* @param (IHierarchy&static)|null $parent If the class implements
6059
* {@see IHierarchy}, pass `$parent` to each instance via
6160
* {@see IHierarchy::setParent()}.
6261
* @return Generator<static>
6362
*/
6463
final public static function constructList(
65-
iterable $dataList,
64+
iterable $list,
6665
int $conformity = ArrayKeyConformity::NONE,
6766
?IContainer $container = null,
6867
$parent = null
@@ -72,7 +71,7 @@ final public static function constructList(
7271
}
7372

7473
$closure = null;
75-
foreach ($dataList as $key => $data) {
74+
foreach ($list as $key => $data) {
7675
if (!$closure) {
7776
/** @var Introspector<static,IntrospectionClass<static>> */
7877
$builder = Introspector::getService($container, static::class);

src/Concern/TIntrospector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait TIntrospector
2424
/**
2525
* @var array<string,TIntrospectionClass>
2626
*/
27-
private static $IntrospectionClasses = [];
27+
private static $_IntrospectionClasses = [];
2828

2929
/**
3030
* @param class-string<TClass> $class
@@ -73,8 +73,8 @@ private function __construct(string $class)
7373
{
7474
$_class = strtolower($class);
7575
$this->_Class =
76-
(self::$IntrospectionClasses[$_class] ?? null)
77-
?: (self::$IntrospectionClasses[$_class] =
76+
(self::$_IntrospectionClasses[$_class] ?? null)
77+
?: (self::$_IntrospectionClasses[$_class] =
7878
$this->getIntrospectionClass($class));
7979
}
8080
}

src/Concern/TProvidable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,32 +156,32 @@ final public static function provide(
156156
*
157157
* See {@see TProvidable::provide()} for more information.
158158
*
159-
* @param iterable<array-key,mixed[]> $dataList
159+
* @param iterable<array-key,mixed[]> $list
160160
* @param TProvider $provider
161161
* @param ArrayKeyConformity::* $conformity
162162
* @param TProviderContext|null $context
163163
* @return FluentIteratorInterface<array-key,static>
164164
*/
165165
final public static function provideList(
166-
iterable $dataList,
166+
iterable $list,
167167
IProvider $provider,
168168
int $conformity = ArrayKeyConformity::NONE,
169169
?IProviderContext $context = null
170170
): FluentIteratorInterface {
171171
return IterableIterator::from(
172-
self::_provideList($dataList, $provider, $conformity, $context)
172+
self::_provideList($list, $provider, $conformity, $context)
173173
);
174174
}
175175

176176
/**
177-
* @param iterable<array-key,mixed[]> $dataList
177+
* @param iterable<array-key,mixed[]> $list
178178
* @param TProvider $provider
179179
* @param ArrayKeyConformity::* $conformity
180180
* @param TProviderContext|null $context
181181
* @return Generator<array-key,static>
182182
*/
183183
private static function _provideList(
184-
iterable $dataList,
184+
iterable $list,
185185
IProvider $provider,
186186
int $conformity,
187187
?IProviderContext $context
@@ -202,7 +202,7 @@ private static function _provideList(
202202

203203
$introspector = Introspector::getService($container, static::class);
204204

205-
foreach ($dataList as $key => $data) {
205+
foreach ($list as $key => $data) {
206206
if (!isset($closure)) {
207207
$closure =
208208
in_array($conformity, [ArrayKeyConformity::PARTIAL, ArrayKeyConformity::COMPLETE], true)

src/Contract/IConstructible.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Lkrms\Support\Catalog\ArrayKeyConformity;
66

77
/**
8-
* Instantiates itself from associative arrays
8+
* Creates instances of itself from data in associative arrays
99
*
1010
*/
1111
interface IConstructible
@@ -14,14 +14,18 @@ interface IConstructible
1414
* @param mixed[] $data
1515
* @return static
1616
*/
17-
public static function construct(array $data, ?IContainer $container = null);
17+
public static function construct(
18+
array $data,
19+
?IContainer $container = null
20+
);
1821

1922
/**
20-
* @param iterable<mixed[]> $dataList
23+
* @param iterable<mixed[]> $list
24+
* @param ArrayKeyConformity::* $conformity
2125
* @return iterable<static>
2226
*/
2327
public static function constructList(
24-
iterable $dataList,
28+
iterable $list,
2529
int $conformity = ArrayKeyConformity::NONE,
2630
?IContainer $container = null
2731
): iterable;

src/Contract/IExtensible.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,63 @@
33
namespace Lkrms\Contract;
44

55
/**
6-
* Stores arbitrary property values
6+
* Reads and writes arbitrary undeclared properties
77
*
88
*/
99
interface IExtensible
1010
{
11+
/**
12+
* Set the value of an undeclared property
13+
*
14+
* @param mixed $value
15+
*/
1116
public function setMetaProperty(string $name, $value): void;
1217

18+
/**
19+
* Get the value of an undeclared property
20+
*
21+
* @return mixed
22+
*/
1323
public function getMetaProperty(string $name);
1424

25+
/**
26+
* True if an undeclared property is set
27+
*
28+
*/
1529
public function isMetaPropertySet(string $name): bool;
1630

31+
/**
32+
* Unset an undeclared property
33+
*
34+
*/
1735
public function unsetMetaProperty(string $name): void;
1836

1937
/**
20-
* Return an array that maps names to values for all stored properties
38+
* Get an array that maps the object's undeclared property names to their
39+
* current values
2140
*
2241
* @return array<string,mixed>
2342
*/
2443
public function getMetaProperties(): array;
2544

2645
/**
27-
* Clear stored properties
46+
* Unset the object's undeclared properties
2847
*
2948
* @return $this
3049
*/
3150
public function clearMetaProperties();
51+
52+
/**
53+
* @param mixed $value
54+
*/
55+
public function __set(string $name, $value): void;
56+
57+
/**
58+
* @return mixed
59+
*/
60+
public function __get(string $name);
61+
62+
public function __isset(string $name): bool;
63+
64+
public function __unset(string $name): void;
3265
}

src/Contract/IProvidable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ public static function provide(
109109
/**
110110
* Create instances of the class from arrays on behalf of a provider
111111
*
112-
* @param iterable<array-key,mixed[]> $dataList
112+
* @param iterable<array-key,mixed[]> $list
113113
* @param TProvider $provider
114-
* @phpstan-param ArrayKeyConformity::* $conformity
114+
* @param ArrayKeyConformity::* $conformity
115115
* @param TProviderContext|null $context
116116
* @return FluentIteratorInterface<array-key,static>
117117
*/
118118
public static function provideList(
119-
iterable $dataList,
119+
iterable $list,
120120
IProvider $provider,
121121
int $conformity = ArrayKeyConformity::NONE,
122122
?IProviderContext $context = null

src/Contract/IProviderContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getParent(): ?IHierarchy;
8686
/**
8787
* Get the current payload's array key conformity
8888
*
89-
* @phpstan-return ArrayKeyConformity::*
89+
* @return ArrayKeyConformity::*
9090
*/
9191
public function getConformity(): int;
9292
}

src/Contract/IResolvable.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@
22

33
namespace Lkrms\Contract;
44

5-
use Closure;
6-
75
/**
8-
* Normalises property names
6+
* Normalises the names of its properties
97
*
108
*/
119
interface IResolvable
1210
{
13-
/**
14-
* Return a closure that normalises a property name
15-
*
16-
* Arguments after `$name` may be ignored. If `$greedy` is honoured, it
17-
* should be `true` by default.
18-
*
19-
* @return Closure(string $name, bool $greedy=, string...$hints): string
20-
*/
21-
public static function normaliser(): Closure;
22-
2311
/**
2412
* Normalise a property name
2513
*

0 commit comments

Comments
 (0)