Skip to content

Commit ca2c1f7

Browse files
author
ityaozm@gmail.com
committed
refactor(Generator): Refactor Generator class
- Remove unused closure param - Add missing parameter type declaration - Suppress undefined interface method - Remove sanitizeJson method
1 parent 2e744c3 commit ca2c1f7

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

app/Generators/BitoCliGenerator.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
final class BitoCliGenerator extends Generator
1818
{
19-
/**
20-
* @psalm-suppress UnusedClosureParam
21-
*/
2219
public function generate(string $prompt): string
2320
{
2421
return $this

app/Generators/Generator.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function mustRunProcess(
7373
/**
7474
* @param array|string|\Symfony\Component\Process\Process $cmd
7575
* @noinspection MissingParameterTypeDeclarationInspection
76+
* @psalm-suppress UndefinedInterfaceMethod
7677
*/
7778
public function runProcess(
7879
$cmd,
@@ -102,15 +103,4 @@ public function getHelper(string $name): HelperInterface
102103
{
103104
return $this->helperSet->get($name);
104105
}
105-
106-
public function sanitizeJson(string $json): string
107-
{
108-
return (string) str($json)
109-
->match('/\{.*\}/s')
110-
// ->replaceMatches('/[[:cntrl:]]/mu', '')
111-
->replace(
112-
["\\'", PHP_EOL],
113-
["'", '']
114-
);
115-
}
116106
}

app/Generators/GithubCopilotCliGenerator.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
final class GithubCopilotCliGenerator extends Generator
1818
{
19-
/**
20-
* @psalm-suppress UnusedClosureParam
21-
*/
2219
public function generate(string $prompt): string
2320
{
2421
return resolve(

tests/Unit/Generators/GeneratorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* This source file is subject to the MIT license that is bundled.
1919
*/
2020

21+
use App\Commands\CommitCommand;
2122
use App\GeneratorManager;
2223

2324
beforeEach(function (): void {
@@ -40,5 +41,9 @@
4041
OUTPUT;
4142

4243
expect($output)->not->toBeJson()
43-
->and($this->generator->sanitizeJson($output))->toBeJson();
44+
->and(
45+
(function (string $message): string {
46+
return $this->tryFixMessage($message);
47+
})->call(app(CommitCommand::class), $output)
48+
)->toBeJson();
4449
})->group(__DIR__, __FILE__);

0 commit comments

Comments
 (0)