Skip to content

Commit 57e830b

Browse files
committed
Code refactor
1 parent a0d575b commit 57e830b

9 files changed

Lines changed: 91 additions & 37 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"scripts": {
4747
"lint": "pint",
4848
"refactor": "rector",
49-
"test:type-coverage": "pest --type-coverage --min=99",
49+
"test:type-coverage": "pest --type-coverage --exactly=99",
5050
"test:typos": "peck",
5151
"test:lint": "pint --test",
5252
"test:unit": "pest --coverage --exactly=100",

package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@
22

33
declare(strict_types=1);
44

5-
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
65
use Rector\Config\RectorConfig;
7-
use Rector\Set\ValueObject\LevelSetList;
8-
use Rector\Set\ValueObject\SetList;
96

10-
return static function (RectorConfig $rectorConfig): void {
11-
$rectorConfig->paths([
7+
return RectorConfig::configure()
8+
->withPaths([
129
__DIR__.'/src',
13-
]);
14-
15-
$rectorConfig->rules([
16-
InlineConstructorDefaultToPropertyRector::class,
17-
]);
18-
19-
$rectorConfig->sets([
20-
LevelSetList::UP_TO_PHP_82,
21-
SetList::CODE_QUALITY,
22-
SetList::DEAD_CODE,
23-
SetList::EARLY_RETURN,
24-
SetList::TYPE_DECLARATION,
25-
SetList::PRIVATIZATION,
26-
]);
27-
};
10+
__DIR__.'/tests',
11+
])
12+
->withPreparedSets(
13+
deadCode: true,
14+
codeQuality: true,
15+
typeDeclarations: true,
16+
privatization: true,
17+
earlyReturn: true,
18+
strictBooleans: true,
19+
)
20+
->withPhpSets();

src/PendingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function assertTitle(string $expectedTitle): self
5252
* @param iterable $response The response (array or Generator)
5353
* @return mixed The extracted value
5454
*/
55-
private function extractResultValue(iterable $response)
55+
private function extractResultValue(iterable $response): mixed
5656
{
5757
// Get all values from keys matching *.result.value
5858
$values = [];

src/Playground.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
*/
1313
final class Playground
1414
{
15-
private const DEFAULT_SCHEME = 'http';
15+
private const string DEFAULT_SCHEME = 'http';
1616

17-
private const DEFAULT_HOST = 'localhost';
17+
private const string DEFAULT_HOST = 'localhost';
1818

19-
private const DEFAULT_PORT = 9357;
19+
private const int DEFAULT_PORT = 9357;
2020

2121
/**
2222
* Playground instance.
@@ -26,15 +26,15 @@ final class Playground
2626
/**
2727
* Artisan serve process.
2828
*/
29-
private Process $process;
29+
private readonly Process $process;
3030

3131
/**
3232
* Constructs new instance and starts Artisan serve process.
3333
*/
3434
private function __construct(
35-
private string $scheme,
36-
private string $host,
37-
private int $port
35+
private readonly string $scheme,
36+
private readonly string $host,
37+
private readonly int $port
3838
) {
3939
$this->shutdownIdleProcesses();
4040

@@ -56,7 +56,7 @@ public function __destruct()
5656
*/
5757
public static function start(): self
5858
{
59-
if (self::$instance === null) {
59+
if (! self::$instance instanceof self) {
6060
self::$instance = new self(
6161
Arr::get($_ENV, 'PEST_BROWSER_PLUGIN_PLAYGROUND_SCHEME', self::DEFAULT_SCHEME), // @phpstan-ignore-line
6262
Arr::get($_ENV, 'PEST_BROWSER_PLUGIN_PLAYGROUND_HOST', self::DEFAULT_HOST), // @phpstan-ignore-line

src/Playwright/Server.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function isRunning(): bool
8686
$process->run();
8787
$output = $process->getOutput();
8888

89-
$pids = array_filter(explode("\n", mb_trim($output)), fn ($pid): bool => (int) $pid > 0);
89+
$pids = array_filter(explode("\n", mb_trim($output)), fn (string $pid): bool => (int) $pid > 0);
9090

9191
return count($pids) > 0;
9292
}
@@ -97,7 +97,6 @@ public function isRunning(): bool
9797
public function stop(): void
9898
{
9999
if ($this->isRunning()) {
100-
// Stop this way because initial process changes PID for some reason
101100
$command = Process::fromShellCommandline("kill -9 $(lsof -t -i :{$this->port})");
102101
$command->disableOutput();
103102
$command->run();

src/Support/Screenshot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
final class Screenshot
1313
{
14-
private const DEFAULT_DIR = '/tmp/pest-browser-screenshots';
14+
private const string DEFAULT_DIR = '/tmp/pest-browser-screenshots';
1515

1616
/**
1717
* Return the path to the screenshots directory.

tests/Pest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ function cleanupScreenshots(): void
1818
}
1919
}
2020

21-
file_exists($basePath) && rmdir($basePath);
21+
if (file_exists($basePath)) {
22+
rmdir($basePath);
23+
}
2224
}
2325

2426
function playgroundUrl(string $path = '/'): string

tests/Unit/Support/StrTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
use Pest\Browser\Support\Str;
66

7-
test('one character non-regex string', function () {
7+
test('one character non-regex string', function (): void {
88
$string = 'a';
99

1010
$result = Str::isRegex($string);
1111

1212
expect($result)->toBeFalse();
1313
});
1414

15-
it('detects regex expressions', function () {
15+
it('detects regex expressions', function (): void {
1616
$regex = '/^.*$/';
1717

1818
$result = Str::isRegex($regex);
1919

2020
expect($result)->toBeTrue();
2121
});
2222

23-
it('detects non-regex expressions', function () {
23+
it('detects non-regex expressions', function (): void {
2424
$string = 'string';
2525

2626
$result = Str::isRegex($string);

0 commit comments

Comments
 (0)