Skip to content

Commit 59a703f

Browse files
committed
refactor(WithRunable): Update callable types to Closure for better type safety
- Change callable type hints to Closure for $pipe and $tap properties. - Update method signatures for withPipe and withTap to accept Closure. - Ensure type checks use instanceof for Closure instead of is_callable. Signed-off-by: guanguans <[email protected]>
1 parent 38433b9 commit 59a703f

21 files changed

+45
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ $soar->withSudoPassword('your sudo password'); // With a sudo password to run th
514514

515515
### Or configure sudoers
516516

517-
> On higher versions of macOS, it is possible that the fingerprint authentication window will pop up. You can configure sudoers to run `soar` commands without a password.
517+
> On higher versions of macOS, it is possible that the fingerprint authentication window will pop up. You can configure sudoers to run `soar` command without password.
518518
519519
1. Edit Configuration file of sudoers:
520520

@@ -534,8 +534,8 @@ guanguans ALL=(ALL) NOPASSWD: /Users/guanguans/Documents/develop/soar-php/bin/so
534534
```shell
535535
composer benchmark
536536
composer checks:required
537-
composer soar:example-run
538-
composer soar:example-serve
537+
composer soar:usage-example-run
538+
composer soar:usage-example-serve
539539
composer test
540540
```
541541

composer-bump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class ComposerBump
213213
},
214214
];
215215

216-
sort($dependencyVersions);
216+
sort($dependencyVersions, \SORT_NUMERIC);
217217

218218
$package['dependency_version'] = implode(' || ', $dependencyVersions);
219219
$carry[$package['name']] = $package;

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
"@php-cs-fixer:fix-dry-run-stop-on-violation",
215215
"@soar:check-binary",
216216
"@soar:dump-config",
217+
"@soar:usage-example-run",
217218
"@pest:bail",
218219
"@rector:process-dry-run",
219220
"@phpstan:analyse"
@@ -394,7 +395,7 @@
394395
"rule-doc-generator:rector-validate": "@rule-doc-generator validate src/Support/Rectors/",
395396
"sk": "@php vendor/bin/swiss-knife --ansi -vv",
396397
"sk:alice-yaml-fixtures-to-php": "@sk alice-yaml-fixtures-to-php --help",
397-
"sk:check-commented-code": "@sk check-commented-code examples/ src/ --line-limit=5 --skip-file=src/Soar.php",
398+
"sk:check-commented-code": "@sk check-commented-code examples/ src/ --line-limit=6 --skip-file=src/Soar.php",
398399
"sk:check-conflicts": "@sk check-conflicts examples/ src/",
399400
"sk:dump-editorconfig": "@sk dump-editorconfig",
400401
"sk:finalize-classes": "@sk finalize-classes examples/ src/",
@@ -428,13 +429,13 @@
428429
],
429430
"soar:dump-php-config-prototype": "Guanguans\\SoarPHP\\Support\\ComposerScripts::dumpSoarPHPConfig",
430431
"soar:dump-yaml-config": "Guanguans\\SoarPHP\\Support\\ComposerScripts::dumpSoarYamlConfig",
431-
"soar:example-run": [
432+
"soar:usage-example-run": [
432433
"echo 'examples/example.php:\n'",
433-
"@php examples/example.php"
434+
"@php examples/usage-example.php"
434435
],
435-
"soar:example-serve": [
436+
"soar:usage-example-serve": [
436437
"@composer-config:disable-process-timeout",
437-
"@php -S localhost:8123 examples/example.php"
438+
"@php -S localhost:8123 examples/usage-example.php"
438439
],
439440
"testbench": "@php vendor/bin/testbench --ansi",
440441
"testbench:build": "@testbench workbench:build",

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
'PhpUndefinedClassInspection',
117117
'PhpUnhandledExceptionInspection',
118118
'PhpVoidFunctionResultUsedInspection',
119+
'SqlResolve',
119120
'StaticClosureCanBeUsedInspection',
120121
])
121122
->withConfiguredRule(NewExceptionToNewAnonymousExtendsExceptionImplementsRector::class, [

src/Concerns/WithRunable.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
*/
2121
trait WithRunable
2222
{
23-
/** @var null|callable(Process): Process */
24-
protected $pipe;
23+
/** @var null|\Closure(Process): Process */
24+
protected ?\Closure $pipe = null;
2525

26-
/** @var null|callable(Process): void */
27-
protected $tap;
26+
/** @var null|\Closure(Process): void */
27+
protected ?\Closure $tap = null;
2828

29-
public function withPipe(?callable $pipe): self
29+
public function withPipe(?\Closure $pipe): self
3030
{
3131
$this->pipe = $pipe;
3232

3333
return $this;
3434
}
3535

36-
public function withTap(?callable $tap): self
36+
public function withTap(?\Closure $tap): self
3737
{
3838
$this->tap = $tap;
3939

@@ -59,10 +59,10 @@ protected function toProcess(): Process
5959
? new Process(command: ['sudo', '-S', ...$command], input: $this->getSudoPassword())
6060
: new Process($command);
6161

62-
if (\is_callable($this->tap)) {
63-
($this->tap)($process);
62+
if ($this->tap instanceof \Closure) {
63+
$this->tap->call($process, $process);
6464
}
6565

66-
return \is_callable($this->pipe) ? ($this->pipe)($process) : $process;
66+
return $this->pipe instanceof \Closure ? ($this->pipe)->call($process, $process) : $process;
6767
}
6868
}

tests/ArchTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/** @noinspection PhpUndefinedClassInspection */
77
/** @noinspection PhpUnhandledExceptionInspection */
88
/** @noinspection PhpVoidFunctionResultUsedInspection */
9+
/** @noinspection SqlResolve */
910
/** @noinspection StaticClosureCanBeUsedInspection */
1011
declare(strict_types=1);
1112

tests/Concerns/ConcreteMagicTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/** @noinspection PhpUndefinedClassInspection */
77
/** @noinspection PhpUnhandledExceptionInspection */
88
/** @noinspection PhpVoidFunctionResultUsedInspection */
9+
/** @noinspection SqlResolve */
910
/** @noinspection StaticClosureCanBeUsedInspection */
1011
/** @noinspection DebugFunctionUsageInspection */
1112
declare(strict_types=1);

tests/Concerns/ConcreteScoresTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
/** @noinspection PhpUndefinedClassInspection */
77
/** @noinspection PhpUnhandledExceptionInspection */
88
/** @noinspection PhpVoidFunctionResultUsedInspection */
9+
/** @noinspection SqlResolve */
910
/** @noinspection StaticClosureCanBeUsedInspection */
1011
/** @noinspection DebugFunctionUsageInspection */
1112
/** @noinspection ForgottenDebugOutputInspection */
12-
/** @noinspection SqlResolve */
1313
declare(strict_types=1);
1414

1515
/**

tests/Concerns/HasOptionsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/** @noinspection PhpUndefinedClassInspection */
77
/** @noinspection PhpUnhandledExceptionInspection */
88
/** @noinspection PhpVoidFunctionResultUsedInspection */
9+
/** @noinspection SqlResolve */
910
/** @noinspection StaticClosureCanBeUsedInspection */
1011
/** @noinspection NestedAssignmentsUsageInspection */
1112
declare(strict_types=1);

0 commit comments

Comments
 (0)