Skip to content

Commit a00d70e

Browse files
committed
Continue utility class cleanup
- Optionally preserve keys in `Arr::unique()` - Add `Arr::toScalars()`, deprecating `Convert::toScalarArray()` - Add `Arr::keyOffset()`, deprecating `Convert::arrayKeyToOffset()` - Remove unused/redundant methods: - `Convert::stringsToUnique()` - `Convert::stringsToUniqueList()` - `Convert::walkRecursive()` - `Convert::columnsToUnique()` - `Arr::forEach()` Also: - Add import statements for built-in classes used in code and DocBlocks
1 parent 1ee58ea commit a00d70e

24 files changed

+367
-360
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
2424
'no_unneeded_import_alias' => true,
2525
'no_unused_imports' => true,
26+
'phpdoc_no_useless_inheritdoc' => true,
2627
'single_import_per_statement' => true,
2728
'yoda_style' => ['equal' => false, 'identical' => false],
2829
])

src/Console/Target/StreamTarget.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Lkrms\Utility\Date;
88
use Lkrms\Utility\File;
99
use DateTime;
10+
use DateTimeZone;
1011
use LogicException;
1112

1213
/**
@@ -30,7 +31,7 @@ final class StreamTarget extends ConsoleTarget
3031
private $Timestamp = '[d M y H:i:s.vO] ';
3132

3233
/**
33-
* @var \DateTimeZone|null
34+
* @var DateTimeZone|null
3435
*/
3536
private $Timezone;
3637

@@ -66,7 +67,7 @@ final class StreamTarget extends ConsoleTarget
6667
* @param bool|null $addTimestamp If `null`, timestamps are added if
6768
* `$stream` is not STDOUT or STDERR.
6869
* @param string|null $timestamp Default: `[d M y H:i:s.vO] `
69-
* @param \DateTimeZone|string|null $timezone Default: as per
70+
* @param DateTimeZone|string|null $timezone Default: as per
7071
* `date_default_timezone_set` or INI setting `date.timezone`
7172
*/
7273
public function __construct(
@@ -140,7 +141,7 @@ public function reopen(string $path = null)
140141
* @param bool|null $addTimestamp If `null`, timestamps will be added unless
141142
* `$path` is STDOUT, STDERR, or a TTY
142143
* @param string|null $timestamp Default: `[d M y H:i:s.vO] `
143-
* @param \DateTimeZone|string|null $timezone Default: as per
144+
* @param DateTimeZone|string|null $timezone Default: as per
144145
* `date_default_timezone_set` or INI setting `date.timezone`
145146
*/
146147
public static function fromPath(

src/Contract/IFacade.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lkrms\Contract;
44

55
use Lkrms\Concept\Facade;
6+
use LogicException;
67

78
/**
89
* Provides a static interface to an instance of an underlying class
@@ -29,8 +30,7 @@ public static function isLoaded(): bool;
2930
* facade is passed to {@see ReceivesFacade::setFacade()}.
3031
*
3132
* @return TClass
32-
* @throws \RuntimeException if an underlying instance has already been
33-
* loaded.
33+
* @throws LogicException if an underlying instance has already been loaded.
3434
*/
3535
public static function load();
3636

@@ -44,11 +44,8 @@ public static function unload(): void;
4444
/**
4545
* Get the underlying instance
4646
*
47-
* If an underlying instance has not been loaded, the facade may either:
48-
*
49-
* 1. call {@see IFacade::load()} and pass the instance it returns to the
50-
* caller (preferred), or
51-
* 2. throw a `RuntimeException`.
47+
* If an underlying instance has not been loaded, the facade should return
48+
* an instance from {@see IFacade::load()}.
5249
*
5350
* @return TClass
5451
*/

src/Contract/IProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lkrms\Contract;
44

55
use Lkrms\Exception\MethodNotImplementedException;
6+
use Stringable;
67

78
/**
89
* Services objects on behalf of a backend
@@ -58,7 +59,7 @@ public function getContext(?IContainer $container = null): IProviderContext;
5859
* - values that aren't unique to the connected data source
5960
* - case-insensitive values (unless normalised first)
6061
*
61-
* @return array<int|float|string|bool|\Stringable|null>
62+
* @return array<int|float|string|bool|Stringable|null>
6263
*/
6364
public function getBackendIdentifier(): array;
6465

src/Curler/Curler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use Lkrms\Utility\Convert;
3535
use Lkrms\Utility\Env;
3636
use Lkrms\Utility\Package;
37+
use CurlHandle;
3738
use DateTimeInterface;
3839
use Generator;
3940
use LogicException;
@@ -385,7 +386,7 @@ final class Curler implements IReadable, IWritable, Buildable
385386
protected $ObjectAsArray = true;
386387

387388
/**
388-
* @var \CurlHandle|resource|null
389+
* @var CurlHandle|resource|null
389390
*/
390391
private $Handle;
391392

@@ -417,7 +418,7 @@ final class Curler implements IReadable, IWritable, Buildable
417418
private static $DefaultUserAgent;
418419

419420
/**
420-
* @var \CurlHandle|resource|null
421+
* @var CurlHandle|resource|null
421422
*/
422423
private static $SharedHandle;
423424

src/Iterator/Concern/FluentIteratorTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
trait FluentIteratorTrait
1616
{
1717
/**
18-
* @return array<TKey,TValue>|list<TValue>
19-
* @phpstan-return ($preserveKeys is true ? array<TKey,TValue> : list<TValue>)
18+
* @return ($preserveKeys is true ? array<TKey,TValue> : list<TValue>)
2019
*/
2120
public function toArray(bool $preserveKeys = true): array
2221
{

src/Iterator/Contract/FluentIteratorInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ interface FluentIteratorInterface extends Arrayable, Traversable
1919
/**
2020
* Copy the elements of the iterator to an array
2121
*
22-
* @return array<TKey,TValue>|list<TValue>
23-
* @phpstan-return ($preserveKeys is true ? array<TKey,TValue> : list<TValue>)
22+
* @return ($preserveKeys is true ? array<TKey,TValue> : list<TValue>)
2423
*/
2524
public function toArray(bool $preserveKeys = true): array;
2625

src/Support/IntrospectionClass.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Lkrms\Support\Catalog\NormaliserFlag;
1515
use Lkrms\Support\Catalog\RelationshipType;
1616
use Lkrms\Utility\Reflect;
17+
use Closure;
1718
use DateTimeInterface;
1819
use ReflectionClass;
1920
use ReflectionMethod;
@@ -268,75 +269,75 @@ class IntrospectionClass
268269
/**
269270
* Normalises property names
270271
*
271-
* @var (\Closure(string $name, bool $greedy=, string...$hints): string)|null
272+
* @var (Closure(string $name, bool $greedy=, string...$hints): string)|null
272273
*/
273274
public $Normaliser;
274275

275276
/**
276277
* Normalises property names with $greedy = false
277278
*
278-
* @var (\Closure(string): string)|null
279+
* @var (Closure(string): string)|null
279280
*/
280281
public $GentleNormaliser;
281282

282283
/**
283284
* Normalises property names with $hints = $this->NormalisedProperties
284285
*
285-
* @var (\Closure(string): string)|null
286+
* @var (Closure(string): string)|null
286287
*/
287288
public $CarefulNormaliser;
288289

289290
/**
290291
* Signature => closure
291292
*
292-
* @var array<string,\Closure>
293+
* @var array<string,Closure>
293294
*/
294295
public $CreateFromSignatureClosures = [];
295296

296297
/**
297298
* Signature => (int) $strict => closure
298299
*
299-
* @var array<string,array<int,\Closure>>
300+
* @var array<string,array<int,Closure>>
300301
*/
301302
public $CreateProviderlessFromSignatureClosures = [];
302303

303304
/**
304305
* Signature => (int) $strict => closure
305306
*
306-
* @var array<string,array<int,\Closure>>
307+
* @var array<string,array<int,Closure>>
307308
*/
308309
public $CreateProvidableFromSignatureClosures = [];
309310

310311
/**
311312
* (int) $strict => closure
312313
*
313-
* @var array<int,\Closure>
314+
* @var array<int,Closure>
314315
*/
315316
public $CreateProviderlessFromClosures = [];
316317

317318
/**
318319
* (int) $strict => closure
319320
*
320-
* @var array<int,\Closure>
321+
* @var array<int,Closure>
321322
*/
322323
public $CreateProvidableFromClosures = [];
323324

324325
/**
325326
* Normalised property name => action => closure
326327
*
327-
* @var array<string,array<string,\Closure>>
328+
* @var array<string,array<string,Closure>>
328329
*/
329330
public $PropertyActionClosures = [];
330331

331332
/**
332-
* @var \Closure|null
333+
* @var Closure|null
333334
*/
334335
public $GetNameClosure;
335336

336337
/**
337338
* Rules signature => closure
338339
*
339-
* @var array<string,\Closure>
340+
* @var array<string,Closure>
340341
*/
341342
public $SerializeClosures = [];
342343

@@ -367,7 +368,7 @@ public function __construct(string $class)
367368
if ($class->implementsInterface(ReturnsNormaliser::class)) {
368369
$this->Normaliser = $class->getMethod('normaliser')->invoke(null);
369370
} else {
370-
$this->Normaliser = \Closure::fromCallable([$className, 'normalise']);
371+
$this->Normaliser = Closure::fromCallable([$className, 'normalise']);
371372
}
372373
$this->GentleNormaliser = fn(string $name): string => ($this->Normaliser)($name, false);
373374
$this->CarefulNormaliser = fn(string $name): string => ($this->Normaliser)($name, true, ...$this->NormalisedKeys);

src/Sync/Support/SyncEntityFuzzyResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Lkrms\Sync\Contract\ISyncEntityResolver;
1212
use Lkrms\Utility\Compute;
1313
use Lkrms\Utility\Convert;
14+
use Closure;
1415
use LogicException;
1516

1617
/**
@@ -36,7 +37,7 @@ final class SyncEntityFuzzyResolver implements ISyncEntityResolver
3637
private $EntityProvider;
3738

3839
/**
39-
* @var string|\Closure(TEntity): (string|null)
40+
* @var string|Closure(TEntity): (string|null)
4041
*/
4142
private $NameProperty;
4243

src/Sync/Support/SyncErrorCollection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Lkrms\Console\ConsoleFormatter as Formatter;
88
use Lkrms\Sync\Catalog\SyncErrorType as ErrorType;
99
use Lkrms\Utility\Arr;
10-
use Lkrms\Utility\Convert;
1110
use JsonSerializable;
1211

1312
/**
@@ -64,7 +63,7 @@ public function toString(bool $withMarkup = false): string
6463
$lines = [];
6564
$separator = "\n ";
6665
foreach ($summary as $error) {
67-
$values = Convert::toScalarArray($error['meta']['values']);
66+
$values = Arr::toScalars($error['meta']['values']);
6867

6968
if ($withMarkup) {
7069
foreach ($values as &$value) {

0 commit comments

Comments
 (0)