Skip to content

Commit 2cbad1e

Browse files
committed
feat(soar): Add callback parameter to scores, help, and version
- Modify scores method to accept a callable for processing results. - Update help and version methods to include a callback parameter. - Enhance pest command to improve test output presentation. - Ensure backward compatibility by defaulting callback to null.
1 parent 6b37757 commit 2cbad1e

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"ergebnis/license": "^2.6",
5353
"ergebnis/php-cs-fixer-config": "dev-main",
5454
"ergebnis/rector-rules": "^1.4",
55-
"guanguans/ai-commit": "dev-main",
55+
"guanguans/ai-commit": "^1.15",
5656
"guanguans/monorepo-builder-worker": "^2.0",
5757
"illuminate/support": "^9.52 || ^10.0 || ^11.0 || ^12.0",
5858
"mockery/mockery": "^1.6",
@@ -218,7 +218,8 @@
218218
"normalized-dry-run": "@normalized --dry-run",
219219
"peck": "/opt/homebrew/opt/php@8.3/bin/php ./vendor/bin/peck check --path=src/ --config=peck.json --ansi -v",
220220
"peck-init": "@peck --init",
221-
"pest": "@php ./vendor/bin/pest --coverage",
221+
"pest": "@php ./vendor/bin/pest --colors=always --min=80 --coverage",
222+
"pest-bail": "@pest --bail",
222223
"pest-coverage": "@pest --coverage-html=./.build/phpunit/ --coverage-clover=./.build/phpunit/clover.xml",
223224
"pest-highest": [
224225
"@putenvs",

src/Concerns/ConcreteScores.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ public function markdownScores(array|string $sqls): string
6868
*
6969
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
7070
*/
71-
public function scores(array|string $sqls): string
71+
public function scores(array|string $sqls, ?callable $callback = null): string
7272
{
7373
if (\is_array($sqls)) {
7474
$sqls = implode($this->getDelimiter(';'), $sqls);
7575
}
7676

77-
return $this->clone()->withQuery($sqls)->run();
77+
return $this->clone()->withQuery($sqls)->run($callback);
7878
}
7979
}

src/Contracts/Soar.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ public function run(?callable $callback = null): string;
2222

2323
/**
2424
* @param list<string>|string $sqls
25+
* @param null|callable(string, string): void $callback
2526
*/
26-
public function scores(array|string $sqls): string;
27+
public function scores(array|string $sqls, ?callable $callback = null): string;
2728

28-
public function help(): string;
29+
/**
30+
* @param null|callable(string, string): void $callback
31+
*/
32+
public function help(?callable $callback = null): string;
2933

30-
public function version(): string;
34+
/**
35+
* @param null|callable(string, string): void $callback
36+
*/
37+
public function version(?callable $callback = null): string;
3138
}

src/Soar.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ public function __construct(array $options = [], ?string $soarBinary = null)
4343
/**
4444
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
4545
*/
46-
public function help(): string
46+
public function help(?callable $callback = null): string
4747
{
4848
return $this->clone()->setHelp(true)->run(
49-
static function (string $type, string $line) use (&$errorOutput): void {
49+
static function (string $type, string $line) use (&$errorOutput, $callback): void {
5050
Process::ERR === $type and $errorOutput .= $line;
51+
$callback and $callback($type, $line);
5152
}
5253
) ?: $errorOutput;
5354
}
5455

5556
/**
5657
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
5758
*/
58-
public function version(): string
59+
public function version(?callable $callback = null): string
5960
{
60-
return $this->clone()->setVersion(true)->run();
61+
return $this->clone()->setVersion(true)->run($callback);
6162
}
6263

6364
public function clone(): self

0 commit comments

Comments
 (0)