Skip to content

Commit bf55064

Browse files
committed
Merge branch 'develop'
2 parents 960cc80 + f029413 commit bf55064

Some content is hidden

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

47 files changed

+988
-660
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Run PHP CS Fixer
5353
run: tools/php-cs-fixer check --diff --verbose
5454

55-
- name: Run PrettyPHP
55+
- name: Run pretty-php
5656
run: tools/pretty-php --diff
5757

5858
phpstan:

.phive/phars.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="lkrms/pretty-php" version="^0.4.48" installed="0.4.48" location="./tools/pretty-php" copy="false"/>
4-
<phar name="php-cs-fixer" version="^3.46.0" installed="3.47.1" location="./tools/php-cs-fixer" copy="false"/>
3+
<phar name="lkrms/pretty-php" version="^0.4.48" installed="0.4.50" location="./tools/pretty-php" copy="false"/>
4+
<phar name="php-cs-fixer" version="^3.46.0" installed="3.48.0" location="./tools/php-cs-fixer" copy="false"/>
55
<phar name="salient-labs/php-changelog" version="^1.0.0" installed="1.0.1" location="./tools/changelog" copy="false"/>
66
</phive>

docs/Benchmarks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Benchmarks
2+
3+
Unscientific tests that have informed various decisions.
4+
5+
## Polling loops
6+
7+
e.g. when waiting for a `proc_open()` process to terminate:
8+
9+
| Statement | CPU time | % of elapsed time |
10+
| ---------------- | --------- | ----------------- |
11+
| none | 9984.34ms | 99.84% |
12+
| `usleep(1)` | 1234.08ms | 12.34% |
13+
| `usleep(10)` | 232.06ms | 2.32% |
14+
| `usleep(100)` | 94.29ms | 0.94% |
15+
| `usleep(1000)` | 25.15ms | 0.25% |
16+
| `usleep(10000)` | 6.00ms | 0.06% |
17+
| `usleep(100000)` | 2.34ms | 0.02% |

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

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
use Lkrms\Support\ProviderContext;
2020
use Lkrms\Support\TokenExtractor;
2121
use Lkrms\Utility\Arr;
22-
use Lkrms\Utility\Convert;
2322
use Lkrms\Utility\File;
2423
use Lkrms\Utility\Get;
2524
use Lkrms\Utility\Package;
25+
use Lkrms\Utility\Pcre;
2626
use Lkrms\Utility\Reflect;
2727
use Lkrms\Utility\Str;
2828
use Lkrms\Utility\Test;
@@ -383,25 +383,56 @@ protected function resolveTemplates(string $type, array $templates, ?PhpDocTempl
383383
*/
384384
protected function getPhpDocTypeAlias($type, array $templates, string $namespace, ?string $filename = null, array &$inputClassTemplates = []): string
385385
{
386-
return PhpDocTag::normaliseType(preg_replace_callback(
386+
/** @var string */
387+
$subject = $type instanceof PhpDocTag
388+
? Str::coalesce($type->Type, '')
389+
: $type;
390+
391+
return PhpDocTag::normaliseType(Pcre::replaceCallback(
387392
'/(?<!\$)([a-z_]+(-[a-z0-9_]+)+|(?=\\\\?\b)' . Regex::PHP_TYPE . ')\b/i',
388-
function ($match) use ($type, $namespace, $templates, $filename, &$inputClassTemplates) {
389-
$t = $this->resolveTemplates($match[0], $templates, $template, $inputClassTemplates);
393+
function ($match) use (
394+
$type,
395+
$templates,
396+
$namespace,
397+
$filename,
398+
&$inputClassTemplates,
399+
$subject
400+
) {
401+
$t = $this->resolveTemplates($match[0][0], $templates, $template, $inputClassTemplates);
390402
$type = $template ?: $type;
391-
if ($type instanceof PhpDocTag && $type->Class) {
403+
if ($type instanceof PhpDocTag && $type->Class !== null) {
392404
$class = new ReflectionClass($type->Class);
393405
$namespace = $class->getNamespaceName();
394406
$filename = $class->getFileName();
395407
}
396408
// Recurse if template expansion occurred
397-
if ($t !== $match[0]) {
409+
if ($t !== $match[0][0]) {
398410
return $this->getPhpDocTypeAlias($t, $templates, $namespace, $filename);
399411
}
400412
// Leave reserved words and PHPDoc types (e.g. `class-string`)
401413
// alone
402414
if (Test::isPhpReservedWord($t) || strpos($t, '-') !== false) {
403415
return $t;
404416
}
417+
// Leave `min` and `max` (lowercase) alone if they appear
418+
// between angle brackets after `int` (not case sensitive)
419+
if ($t === 'min' || $t === 'max') {
420+
// - before: `'array < int < 1, max > >'`
421+
// - after: `['array', '<', 'int', '<', '1']`
422+
$before = substr($subject, 0, $match[0][1]);
423+
$before = Pcre::split('/(?=(?<![-a-z0-9$\\\\_])int\s*<)|(?=<)|(?<=<)|,/i', $before);
424+
$before = Arr::trim($before);
425+
while ($before) {
426+
$last = array_pop($before);
427+
if ($last === 'min' || $last === 'max' || Test::isIntValue($last)) {
428+
continue;
429+
}
430+
if ($last === '<' && $before && Str::lower(array_pop($before)) === 'int') {
431+
return $t;
432+
}
433+
break;
434+
}
435+
}
405436
// Don't waste time trying to find a FQCN in $InputFileUseMaps
406437
if (($t[0] ?? null) === '\\') {
407438
return $this->getTypeAlias($t);
@@ -412,9 +443,10 @@ function ($match) use ($type, $namespace, $templates, $filename, &$inputClassTem
412443
$filename
413444
);
414445
},
415-
$type instanceof PhpDocTag
416-
? ($type->Type ?: '')
417-
: $type
446+
$subject,
447+
-1,
448+
$count,
449+
\PREG_OFFSET_CAPTURE,
418450
));
419451
}
420452

@@ -812,7 +844,7 @@ protected function handleOutput($lines): void
812844
*/
813845
protected function code($value): string
814846
{
815-
return Convert::valueToCode($value, ',' . \PHP_EOL, ' => ', null, self::TAB);
847+
return Get::code($value, ',' . \PHP_EOL, ' => ', null, self::TAB);
816848
}
817849

818850
/**

lk-util/Command/Generate/GenerateBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ protected function run(string ...$args)
325325

326326
$default = '';
327327
$defaultText = null;
328-
switch (preg_replace('/^(\?|null\|)|\|null$/', '', $type)) {
328+
switch (Pcre::replace('/^(\?|null\|)|\|null$/', '', $type)) {
329329
case '\static':
330330
case 'static':
331331
case '$this':
@@ -427,7 +427,7 @@ protected function run(string ...$args)
427427

428428
$default = '';
429429
$defaultText = null;
430-
switch (preg_replace('/^(\?|null\|)|\|null$/', '', $type)) {
430+
switch (Pcre::replace('/^(\?|null\|)|\|null$/', '', $type)) {
431431
case '\static':
432432
case 'static':
433433
case '$this':
@@ -499,7 +499,7 @@ protected function run(string ...$args)
499499
$templateTag->Variance = null;
500500
$lines[] = (string) $templateTag;
501501
$returnType[$template] = $T;
502-
$param = preg_replace("/(?<!\$|\\\\)\b$template\b/", $T, $param);
502+
$param = Pcre::replace("/(?<!\$|\\\\)\b$template\b/", $T, (string) $param);
503503
}
504504
$lines[] = $param;
505505
$lines[] = '@return $this<' . implode(',', $returnType) . '>';

scripts/generate.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use Lkrms\Store\CacheStore;
3030
use Lkrms\Support\ErrorHandler;
3131
use Lkrms\Support\EventDispatcher;
32-
use Lkrms\Support\Timekeeper;
32+
use Lkrms\Support\MetricCollector;
3333
use Lkrms\Sync\Support\DbSyncDefinition;
3434
use Lkrms\Sync\Support\DbSyncDefinitionBuilder;
3535
use Lkrms\Sync\Support\HttpSyncDefinition;
@@ -51,6 +51,7 @@
5151
use Lkrms\Utility\File;
5252
use Lkrms\Utility\Json;
5353
use Lkrms\Utility\Package;
54+
use Lkrms\Utility\Pcre;
5455

5556
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
5657

@@ -62,7 +63,7 @@
6263
ErrorHandler::class => [Err::class, '--skip', 'handleShutdown,handleError,handleException'],
6364
EventDispatcher::class => Event::class,
6465
SyncStore::class => Sync::class,
65-
Timekeeper::class => Profile::class,
66+
MetricCollector::class => [Profile::class, '--api'],
6667
];
6768

6869
$builders = [
@@ -179,7 +180,7 @@ function generated($commandOrFile): void
179180
}
180181

181182
$file = dirname(__DIR__) . '/.gitattributes';
182-
$attributes = preg_grep(
183+
$attributes = Pcre::grep(
183184
'/(^#| linguist-generated$)/',
184185
Arr::trim(file($file)),
185186
\PREG_GREP_INVERT

src/Cli/CliApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,6 @@ private function generateHelp(string $name, $node, int $target, string ...$args)
462462
$usage = $this->getHelp($name, $node, $style);
463463
$usage = $formatter->formatTags($usage);
464464
$usage = Str::eolToNative($usage);
465-
printf('%s%s', str_replace('\ ', ' ', $usage), \PHP_EOL);
465+
printf('%s%s', str_replace('\ ', "\u{00A0}", $usage), \PHP_EOL);
466466
}
467467
}

src/Cli/CliOption.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Lkrms\Utility\Convert;
2323
use Lkrms\Utility\Env;
2424
use Lkrms\Utility\Format;
25+
use Lkrms\Utility\Get;
2526
use Lkrms\Utility\Pcre;
2627
use Lkrms\Utility\Str;
2728
use Lkrms\Utility\Test;
@@ -1083,7 +1084,7 @@ private function throwValueTypeException($value): void
10831084
'invalid %s value (%s expected): %s',
10841085
$this->DisplayName,
10851086
$this->getValueTypeName(),
1086-
Convert::valueToCode($value),
1087+
Get::code($value),
10871088
));
10881089
}
10891090

src/Console/ConsoleFormatter.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ public function formatTags(
326326
}
327327

328328
$string = '';
329-
/** @var array<int|string,string|null> $match */
330329
foreach ($matches as $match) {
331330
$indent = (string) $match['indent'];
332331

@@ -359,7 +358,6 @@ function (array $match) use (
359358
$baseOffset,
360359
&$adjust
361360
): string {
362-
/** @var array<int|string,array{string,int}> $match */
363361
$text = $this->applyTags(
364362
$match,
365363
true,
@@ -472,7 +470,6 @@ function (array $match) use (
472470
): string {
473471
// If the escape character is being wrapped, do nothing other
474472
// than temporarily replace "\ " with "\x"
475-
/** @var array<int|string,array{string,int}> $match */
476473
if ($wrapAfterApply && !$unescape) {
477474
if ($match[1][0] !== ' ') {
478475
return $match[0][0];

src/Console/ConsoleWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function unload(): void
113113
* Register a log file to receive console output
114114
*
115115
* Output is appended to a file created with mode `0600` in
116-
* `sys_get_temp_dir()`:
116+
* {@see sys_get_temp_dir()}:
117117
*
118118
* ```php
119119
* <?php

0 commit comments

Comments
 (0)