Skip to content

Commit a805cbf

Browse files
committed
Merge branch 'cleanup'
2 parents f75ce59 + fea182f commit a805cbf

File tree

26 files changed

+455
-295
lines changed

26 files changed

+455
-295
lines changed

.vscode/php.code-snippets

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Class file": {
3+
"scope": "php",
4+
"prefix": "<?php",
5+
"body": [
6+
"<?php declare(strict_types=1);",
7+
"",
8+
"namespace ${TM_DIRECTORY/^.*\\\\/src\\\\/(?:(Toolkit)|(Util))|^.*\\\\/(tests\\\\/(?:unit|fixtures|3rdparty)\\\\/(?:(Toolkit)|(Util)))|\\\\/([a-zA-Z0-9]+)/${1:+Salient}${4:+Salient}${2:+Lkrms}${5:+Lkrms}${3:+\\\\Tests}${6:+\\\\}$6/g};",
9+
"",
10+
"class ${TM_FILENAME_BASE/[^a-zA-Z0-9]+//g} {",
11+
" $0",
12+
"}",
13+
""
14+
]
15+
}
16+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"phpstan/extension-installer": "^1",
3131
"phpstan/phpstan": "^1",
3232
"phpstan/phpstan-deprecation-rules": "^1",
33+
"phpstan/phpstan-phpunit": "^1",
3334
"phpunit/phpunit": "^9",
3435
"sebastian/diff": "^4 || ^5"
3536
},

lk-util/Command/Generate/GenerateSyncEntity.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Lkrms\Support\Catalog\RelationshipType;
1414
use Lkrms\Sync\Concept\HttpSyncProvider;
1515
use Lkrms\Sync\Concept\SyncEntity;
16+
use Lkrms\Sync\Support\DeferredEntity;
17+
use Lkrms\Sync\Support\DeferredRelationship;
1618
use Lkrms\Utility\Arr;
1719
use Lkrms\Utility\Convert;
1820
use Lkrms\Utility\Inflect;
@@ -399,16 +401,38 @@ protected static function getRemovablePrefixes(): ?array
399401
}
400402

401403
foreach ($parent as $key => $value) {
402-
$properties[$key] = 'static|null';
404+
$deferredEntity ??= $this->getFqcnAlias(DeferredEntity::class);
405+
$properties[$key] = sprintf('static|%s<static>|null', $deferredEntity);
403406
}
404407
foreach ($children as $key => $value) {
405-
$properties[$key] = 'static[]|null';
408+
$deferredEntity ??= $this->getFqcnAlias(DeferredEntity::class);
409+
$deferredRelationship ??= $this->getFqcnAlias(DeferredRelationship::class);
410+
$properties[$key] = sprintf(
411+
'array<static|%s<static>>|%s<static>|null',
412+
$deferredEntity,
413+
$deferredRelationship,
414+
);
406415
}
407416
foreach ($oneToOne as $key => $value) {
408-
$properties[$key] = "{$value}|null";
417+
$deferredEntity ??= $this->getFqcnAlias(DeferredEntity::class);
418+
$properties[$key] = sprintf(
419+
'%s|%s<%s>|null',
420+
$value,
421+
$deferredEntity,
422+
$value,
423+
);
409424
}
410425
foreach ($oneToMany as $key => $value) {
411-
$properties[$key] = "{$value}[]|null";
426+
$deferredEntity ??= $this->getFqcnAlias(DeferredEntity::class);
427+
$deferredRelationship ??= $this->getFqcnAlias(DeferredRelationship::class);
428+
$properties[$key] = sprintf(
429+
'array<%s|%s<%s>>|%s<%s>|null',
430+
$value,
431+
$deferredEntity,
432+
$value,
433+
$deferredRelationship,
434+
$value,
435+
);
412436
}
413437

414438
$oneToOne += array_diff_key($tentativeOneToOne, $oneToMany, $parent, $children);

src/Util/Cli/CliApplication.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ class CliApplication extends Application implements CliApplicationInterface
4848
public function __construct(
4949
?string $basePath = null,
5050
?string $appName = null,
51-
int $envFlags = EnvFlag::ALL
51+
int $envFlags = EnvFlag::ALL,
52+
?string $configDir = 'config'
5253
) {
53-
parent::__construct($basePath, $appName, $envFlags);
54+
parent::__construct($basePath, $appName, $envFlags, $configDir);
5455

5556
Assert::runningOnCli();
57+
5658
Assert::argvIsDeclared();
5759

5860
// Keep running, even if:
@@ -424,6 +426,8 @@ public function run()
424426

425427
/**
426428
* @inheritDoc
429+
*
430+
* @codeCoverageIgnore
427431
*/
428432
public function exit()
429433
{
@@ -432,6 +436,8 @@ public function exit()
432436

433437
/**
434438
* @inheritDoc
439+
*
440+
* @codeCoverageIgnore
435441
*/
436442
public function runAndExit()
437443
{

src/Util/Cli/Contract/CliApplicationInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function getProgramName(): string;
2121
* Get the command invoked by run()
2222
*
2323
* This method should only return a command that is currently running.
24+
*
25+
* @phpstan-impure
2426
*/
2527
public function getRunningCommand(): ?CliCommandInterface;
2628

@@ -29,13 +31,17 @@ public function getRunningCommand(): ?CliCommandInterface;
2931
*
3032
* This method should only return a command that ran to completion or failed
3133
* with an exception.
34+
*
35+
* @phpstan-impure
3236
*/
3337
public function getLastCommand(): ?CliCommandInterface;
3438

3539
/**
3640
* Get the return value most recently recorded by run()
3741
*
3842
* This method should return `0` if a return value has not been recorded.
43+
*
44+
* @phpstan-impure
3945
*/
4046
public function getLastExitStatus(): int;
4147

src/Util/Store/CacheStore.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function set(string $key, $value, $expires = null): self
116116
*
117117
* - its age in seconds is less than or equal to `$maxAge`, or
118118
* - `$maxAge` is `0`
119+
*
120+
* @phpstan-impure
119121
*/
120122
public function has(string $key, ?int $maxAge = null): bool
121123
{
@@ -148,6 +150,8 @@ public function has(string $key, ?int $maxAge = null): bool
148150
* - `$maxAge` is `0`
149151
*
150152
* @return mixed|null `null` if the item has expired or doesn't exist.
153+
*
154+
* @phpstan-impure
151155
*/
152156
public function get(string $key, ?int $maxAge = null)
153157
{
@@ -182,6 +186,8 @@ public function get(string $key, ?int $maxAge = null)
182186
* @return T|null `null` if the item has expired or doesn't exist.
183187
* @throws AssertionFailedException if the item stored under `$key` is not
184188
* an instance of `$class`.
189+
*
190+
* @phpstan-impure
185191
*/
186192
public function getInstanceOf(string $key, string $class, ?int $maxAge = null): ?object
187193
{
@@ -200,6 +206,8 @@ public function getInstanceOf(string $key, string $class, ?int $maxAge = null):
200206
* @return mixed[]|null `null` if the item has expired or doesn't exist.
201207
* @throws AssertionFailedException if the item stored under `$key` is not
202208
* an array.
209+
*
210+
* @phpstan-impure
203211
*/
204212
public function getArray(string $key, ?int $maxAge = null): ?array
205213
{
@@ -218,6 +226,8 @@ public function getArray(string $key, ?int $maxAge = null): ?array
218226
* @return int|null `null` if the item has expired or doesn't exist.
219227
* @throws AssertionFailedException if the item stored under `$key` is not
220228
* an integer.
229+
*
230+
* @phpstan-impure
221231
*/
222232
public function getInt(string $key, ?int $maxAge = null): ?int
223233
{
@@ -236,6 +246,8 @@ public function getInt(string $key, ?int $maxAge = null): ?int
236246
* @return string|null `null` if the item has expired or doesn't exist.
237247
* @throws AssertionFailedException if the item stored under `$key` is not a
238248
* string.
249+
*
250+
* @phpstan-impure
239251
*/
240252
public function getString(string $key, ?int $maxAge = null): ?string
241253
{
@@ -319,6 +331,8 @@ public function flush(): self
319331
* Unix timestamp representing its expiration time, or an integer
320332
* representing its lifetime in seconds.
321333
* @return T
334+
*
335+
* @phpstan-impure
322336
*/
323337
public function maybeGet(string $key, callable $callback, $expires = null)
324338
{
@@ -341,6 +355,8 @@ public function maybeGet(string $key, callable $callback, $expires = null)
341355
*
342356
* - their age in seconds is less than or equal to `$maxAge`, or
343357
* - `$maxAge` is `0`
358+
*
359+
* @phpstan-impure
344360
*/
345361
public function getItemCount(?int $maxAge = null): int
346362
{
@@ -373,6 +389,8 @@ public function getItemCount(?int $maxAge = null): int
373389
* - `$maxAge` is `0`
374390
*
375391
* @return string[]
392+
*
393+
* @phpstan-impure
376394
*/
377395
public function getAllKeys(?int $maxAge = null): array
378396
{

src/Util/Utility/Arr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@ public static function toIndex(array $array, $value = true): array
828828
*
829829
* @template TValue of ArrayAccess|array|object
830830
*
831-
* @param array<TValue> $array
831+
* @param TValue[] $array
832832
* @param array-key $key
833-
* @return array<TValue>
833+
* @return TValue[]
834834
*/
835835
public static function toMap(array $array, $key): array
836836
{
File renamed without changes.

tests/fixtures/Util/Cli/Command/TestOptions.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class TestOptions extends CliCommand
1616
{
1717
private const ACTION_APPLY_VALUES = 'apply-values';
1818
private const ACTION_APPLY_SCHEMA_VALUES = 'apply-schema-values';
19+
private const ACTION_GET_RUNNING_COMMAND = 'get-running-command';
20+
21+
/**
22+
* @var mixed
23+
*/
24+
public $Result;
25+
26+
// --
1927

2028
private ?string $Action = null;
2129

@@ -90,6 +98,7 @@ protected function getOptionList(): array
9098
->allowedValues([
9199
self::ACTION_APPLY_VALUES,
92100
self::ACTION_APPLY_SCHEMA_VALUES,
101+
self::ACTION_GET_RUNNING_COMMAND,
93102
])
94103
->hide()
95104
->bindTo($this->Action),
@@ -104,7 +113,6 @@ protected function getOptionList(): array
104113
->allowedValues(array_keys($this->getCallbacks()))
105114
->multipleAllowed()
106115
->unique()
107-
->defaultValue(['args', 'schemaOptions', 'hasArg'])
108116
->hide()
109117
->bindTo($this->Print),
110118
CliOption::build()
@@ -181,14 +189,22 @@ protected function run(string ...$args)
181189
$data = Json::parseObjectAsArray($this->Data);
182190
$this->applyOptionValues($data, true, true, true, true, true);
183191
break;
192+
193+
case self::ACTION_GET_RUNNING_COMMAND:
194+
$this->Result = $this->App->getRunningCommand();
195+
break;
184196
}
185197

186198
$callbacks = $this->getCallbacks();
187199
foreach ($this->Print as $print) {
188200
$output[$print] = $callbacks[$print]();
189201
}
190202

191-
echo Json::prettyPrint($output ?? []) . \PHP_EOL;
203+
if (!isset($output)) {
204+
return;
205+
}
206+
207+
echo Json::prettyPrint($output) . \PHP_EOL;
192208
}
193209

194210
/**

tests/fixtures/Util/Sync/Entity/Album.php

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

0 commit comments

Comments
 (0)