Skip to content

Commit 308e22d

Browse files
committed
Merge branch 'cleanup'
2 parents 1a196db + e07e050 commit 308e22d

File tree

99 files changed

+1736
-1552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1736
-1552
lines changed

lk-util/Command/Generate/Concept/GenerateCommand.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ abstract class GenerateCommand extends Command
6666
*
6767
* Generators should apply a default description if `null`.
6868
*/
69-
protected ?string $Description;
69+
protected ?string $Description = null;
7070

71-
protected ?bool $ToStdout;
71+
protected bool $ApiTag = false;
7272

73-
protected ?bool $ReplaceIfExists;
73+
protected bool $ToStdout = false;
7474

75-
protected ?bool $Check;
75+
protected bool $Check = false;
7676

77-
protected ?bool $NoMetaTags;
77+
protected bool $ReplaceIfExists = false;
7878

7979
// --
8080

@@ -230,6 +230,11 @@ protected function getOutputOptionList(
230230
}
231231
return [
232232
...$options,
233+
CliOption::build()
234+
->long('api')
235+
->short('a')
236+
->description("Add an `@api` tag to the $outputType")
237+
->bindTo($this->ApiTag),
233238
CliOption::build()
234239
->long('stdout')
235240
->short('s')
@@ -244,26 +249,6 @@ protected function getOutputOptionList(
244249
->short('f')
245250
->description('Overwrite the output file if it already exists')
246251
->bindTo($this->ReplaceIfExists),
247-
CliOption::build()
248-
->long('no-meta')
249-
->short('m')
250-
->description('Suppress metadata tags')
251-
->bindTo($this->NoMetaTags),
252-
];
253-
}
254-
255-
/**
256-
* Get an array of values to use with getEffectiveCommandLine() when
257-
* generating repeatable commands
258-
*
259-
* @return array<string,null>
260-
*/
261-
protected function outputOptionValues(): array
262-
{
263-
return [
264-
'stdout' => null,
265-
'check' => null,
266-
'force' => null,
267252
];
268253
}
269254

@@ -538,6 +523,8 @@ protected function generate(array $innerBlocks = []): string
538523
$phpDoc = Arr::trimAndImplode($blank, [
539524
$this->Description ?? '',
540525
$this->PhpDoc ?? '',
526+
$this->ApiTag ? '@api' : '',
527+
'@generated',
541528
]);
542529

543530
$lines =

lk-util/Command/Generate/GenerateBuilder.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ class GenerateBuilder extends GenerateCommand
4343
'withRefB',
4444
];
4545

46-
private ?string $ClassFqcn;
46+
private string $ClassFqcn = '';
4747

48-
private ?string $BuilderFqcn;
48+
private ?string $BuilderFqcn = null;
49+
50+
private bool $IncludeProperties = false;
51+
52+
private bool $IgnoreProperties = false;
4953

5054
/**
5155
* @var string[]|null
5256
*/
53-
private ?array $Forward;
54-
55-
private ?bool $IncludeProperties;
56-
57-
private ?bool $IgnoreProperties;
57+
private ?array $Forward = null;
5858

5959
/**
60-
* @var string[]|null
60+
* @var string[]
6161
*/
62-
private ?array $Skip;
62+
private array $Skip = [];
6363

6464
// --
6565

@@ -105,7 +105,7 @@ protected function getOptionList(): array
105105
106106
By default, if a property with the same name as a constructor parameter has a
107107
DocBlock, its description is used in the absence of a parameter description,
108-
even if `--properties/-r` is not given. Use this option to disable this
108+
even if `-r/--properties` is not given. Use this option to disable this
109109
behaviour.
110110
EOF)
111111
->bindTo($this->IgnoreProperties),
@@ -120,6 +120,7 @@ protected function getOptionList(): array
120120
EOF)
121121
->optionType(CliOptionType::VALUE_OPTIONAL)
122122
->multipleAllowed()
123+
->nullable()
123124
->bindTo($this->Forward),
124125
CliOption::build()
125126
->long('skip')
@@ -731,17 +732,14 @@ protected function run(string ...$args)
731732
$docBlock[] = ' *';
732733
}
733734
$docBlock[] = $methods;
734-
$docBlock[] = ' *';
735-
$docBlock[] = " * @uses $service";
736-
$docBlock[] = ' *';
737-
$docBlock[] = " * @extends $extends<$service{$this->InputClassType}>";
738-
if (!$this->NoMetaTags) {
739-
$command = $this->getEffectiveCommandLine(true, $this->outputOptionValues());
740-
$program = array_shift($command);
735+
if ($this->ApiTag) {
741736
$docBlock[] = ' *';
742-
$docBlock[] = ' * @generated by ' . $program;
743-
$docBlock[] = ' * @salient-generate-command ' . implode(' ', $command);
737+
$docBlock[] = ' * @api';
744738
}
739+
$docBlock[] = ' *';
740+
$docBlock[] = " * @extends $extends<$service{$this->InputClassType}>";
741+
$docBlock[] = ' *';
742+
$docBlock[] = ' * @generated';
745743
$docBlock[] = ' */';
746744

747745
$imports = $this->generateImports();

lk-util/Command/Generate/GenerateFacade.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ final class GenerateFacade extends GenerateCommand
3232
'getInstance',
3333
];
3434

35-
private ?string $ClassFqcn;
36-
private ?string $FacadeFqcn;
35+
private string $ClassFqcn = '';
36+
37+
private string $FacadeFqcn = '';
3738

3839
/**
39-
* @var string[]|null
40+
* @var string[]
4041
*/
41-
private ?array $SkipMethods;
42+
private array $SkipMethods = [];
4243

4344
public function description(): string
4445
{
@@ -306,16 +307,13 @@ protected function run(string ...$args)
306307
$docBlock[] = $methods;
307308
$docBlock[] = ' *';
308309
}
309-
$docBlock[] = " * @uses $service";
310-
$docBlock[] = ' *';
311-
$docBlock[] = " * @extends $extends<$service>";
312-
if (!$this->NoMetaTags) {
313-
$command = $this->getEffectiveCommandLine(true, $this->outputOptionValues());
314-
$program = array_shift($command);
310+
if ($this->ApiTag) {
311+
$docBlock[] = ' * @api';
315312
$docBlock[] = ' *';
316-
$docBlock[] = ' * @generated by ' . $program;
317-
$docBlock[] = ' * @salient-generate-command ' . implode(' ', $command);
318313
}
314+
$docBlock[] = " * @extends $extends<$service>";
315+
$docBlock[] = ' *';
316+
$docBlock[] = ' * @generated';
319317
$docBlock[] = ' */';
320318

321319
$blocks = [

lk-util/Command/Generate/GenerateSyncEntity.php

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lkrms\LkUtil\Command\Generate;
44

55
use Lkrms\Cli\Catalog\CliOptionType;
6+
use Lkrms\Cli\Catalog\CliOptionValueType;
67
use Lkrms\Cli\Exception\CliInvalidArgumentsException;
78
use Lkrms\Cli\CliOption;
89
use Lkrms\Concern\HasParent;
@@ -30,46 +31,46 @@ class GenerateSyncEntity extends GenerateCommand
3031
*/
3132
public ?array $Entity;
3233

33-
private ?string $ClassFqcn;
34+
private string $ClassFqcn = '';
3435

35-
private ?string $MemberVisibility;
36+
private string $MemberVisibility = '';
3637

3738
/**
38-
* @var string[]|null
39+
* @var string[]
3940
*/
40-
private ?array $OneToOneRelationships;
41+
private array $OneToOneRelationships = [];
4142

4243
/**
43-
* @var string[]|null
44+
* @var string[]
4445
*/
45-
private ?array $OneToManyRelationships;
46+
private array $OneToManyRelationships = [];
4647

47-
private ?string $ParentProperty;
48+
private ?string $ParentProperty = null;
4849

49-
private ?string $ChildrenProperty;
50+
private ?string $ChildrenProperty = null;
5051

51-
private ?string $ReferenceEntityFile;
52+
private ?string $ReferenceEntityFile = null;
5253

5354
/**
5455
* @var class-string<HttpSyncProvider>|null
5556
*/
56-
private ?string $Provider;
57+
private ?string $Provider = null;
5758

58-
private ?string $HttpEndpoint;
59+
private ?string $HttpEndpoint = null;
5960

60-
private ?string $HttpMethod;
61+
private string $HttpMethod = '';
6162

6263
/**
63-
* @var string[]|null
64+
* @var string[]
6465
*/
65-
private ?array $HttpQuery;
66+
private array $HttpQuery = [];
6667

67-
private ?string $HttpDataFile;
68+
private ?string $HttpDataFile = null;
6869

6970
/**
70-
* @var string[]|null
71+
* @var string[]
7172
*/
72-
private ?array $SkipProperties;
73+
private array $SkipProperties = [];
7374

7475
public function description(): string
7576
{
@@ -135,6 +136,7 @@ protected function getOptionList(): array
135136
->valueName('file')
136137
->description('The path to a JSON-serialized reference entity')
137138
->optionType(CliOptionType::VALUE)
139+
->valueType(CliOptionValueType::FILE)
138140
->bindTo($this->ReferenceEntityFile),
139141
CliOption::build()
140142
->long('provider')
@@ -177,6 +179,7 @@ protected function getOptionList(): array
177179
->valueName('file')
178180
->description('The path to JSON-serialized data to submit when requesting a reference entity')
179181
->optionType(CliOptionType::VALUE)
182+
->valueType(CliOptionValueType::FILE)
180183
->bindTo($this->HttpDataFile),
181184
CliOption::build()
182185
->long('skip')
@@ -250,15 +253,6 @@ protected function run(string ...$args)
250253
$data = null;
251254
$dataUri = null;
252255

253-
$values = $this->outputOptionValues() + [
254-
'json' => null,
255-
'provider' => null,
256-
'endpoint' => null,
257-
'method' => null,
258-
'query' => null,
259-
'data' => null,
260-
];
261-
262256
if ($json !== null) {
263257
$entity = $this->getJson($json, $entityUri);
264258
if (!is_array($entity)) {
@@ -316,9 +310,6 @@ protected static function getRemovablePrefixes(): ?array
316310
foreach ($this->SkipProperties as $property) {
317311
$skip[] = $normaliser($property);
318312
}
319-
if ($skip) {
320-
$values['skip'] = $skip;
321-
}
322313

323314
if ($entity) {
324315
foreach (['data', 'Result', 'Items'] as $property) {
@@ -389,16 +380,16 @@ protected static function getRemovablePrefixes(): ?array
389380

390381
$count = 0;
391382
if ($this->ParentProperty !== null) {
392-
$this->validateRelationship("{$this->ParentProperty}={$class}", $normaliser, $parent, $values['parent'], true);
393-
$this->validateRelationship("{$this->ChildrenProperty}={$class}", $normaliser, $children, $values['children'], true);
383+
$this->validateRelationship("{$this->ParentProperty}={$class}", $normaliser, $parent);
384+
$this->validateRelationship("{$this->ChildrenProperty}={$class}", $normaliser, $children);
394385
$count += 2;
395386
}
396387
foreach ($this->OneToOneRelationships as $value) {
397-
$this->validateRelationship($value, $normaliser, $oneToOne, $values['one']);
388+
$this->validateRelationship($value, $normaliser, $oneToOne);
398389
$count++;
399390
}
400391
foreach ($this->OneToManyRelationships as $value) {
401-
$this->validateRelationship($value, $normaliser, $oneToMany, $values['many']);
392+
$this->validateRelationship($value, $normaliser, $oneToMany);
402393
$count++;
403394
}
404395
if (count($oneToOne + $oneToMany + $parent + $children) !== $count) {
@@ -438,23 +429,6 @@ protected static function getRemovablePrefixes(): ?array
438429
$docBlock[] = '';
439430
}
440431

441-
if (!$this->NoMetaTags) {
442-
if ($provider) {
443-
unset($values['provider']);
444-
}
445-
if ($json !== null) {
446-
$values['json'] = $entityUri ?? $this->ReferenceEntityFile;
447-
} elseif ($provider) {
448-
unset($values['endpoint'], $values['query']);
449-
$values['method'] = $method ?? null;
450-
$values['data'] = $dataUri ?? $this->HttpDataFile;
451-
}
452-
$command = $this->getEffectiveCommandLine(true, $values);
453-
$program = array_shift($command);
454-
$docBlock[] = '@generated by ' . $program;
455-
$docBlock[] = '@salient-generate-command ' . implode(' ', $command);
456-
}
457-
458432
if ($docBlock) {
459433
$this->PhpDoc = implode(\PHP_EOL, $docBlock);
460434
}
@@ -514,9 +488,7 @@ protected static function getRemovablePrefixes(): ?array
514488
private function validateRelationship(
515489
string $relationship,
516490
Closure $normaliser,
517-
array &$array,
518-
?string &$value = null,
519-
bool $isParentOrChildren = false
491+
array &$array
520492
): void {
521493
if (!Pcre::match(
522494
'/^(?<property>[[:alpha:]_][[:alnum:]_]*)=(?<class>[[:alpha:]_][[:alnum:]_]*)$/i',
@@ -532,10 +504,5 @@ private function validateRelationship(
532504
$property = $normaliser($matches['property']);
533505
$class = $normaliser($matches['class']);
534506
$array[$property] = $class;
535-
536-
$value =
537-
($value === null ? '' : "$value,")
538-
. $property
539-
. ($isParentOrChildren ? '' : "={$class}");
540507
}
541508
}

0 commit comments

Comments
 (0)