Skip to content

Commit 4edf955

Browse files
committed
Add Larastan and level 6 static analysis
1 parent 9e546af commit 4edf955

Some content is hidden

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

58 files changed

+447
-202
lines changed

.github/workflows/tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,31 @@ jobs:
5555
LINES: 32
5656
COLUMNS: 180
5757
run: vendor/bin/phpunit
58+
59+
analyse:
60+
runs-on: ubuntu-latest
61+
62+
name: Static Analysis
63+
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v6.0.2
67+
68+
- name: Cache dependencies
69+
uses: actions/cache@v5.0.3
70+
with:
71+
path: ~/.composer/cache/files
72+
key: analysis-php-8.4-composer-${{ hashFiles('composer.json') }}
73+
74+
- name: Setup PHP
75+
uses: shivammathur/setup-php@2.37.0
76+
with:
77+
php-version: "8.4"
78+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
79+
coverage: none
80+
81+
- name: Install dependencies
82+
run: composer update --prefer-dist --prefer-stable --no-interaction
83+
84+
- name: Run static analysis
85+
run: composer analyse

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"phpunit/phpunit": "^10.5|^11|^12.5",
3232
"orchestra/testbench": "^8.29|^9.5|^10|^11.0",
3333
"laravel/serializable-closure": "^1.3|^2.0",
34-
"mockery/mockery": "1.6.12"
34+
"mockery/mockery": "1.6.12",
35+
"larastan/larastan": "^3.9.3@stable",
36+
"phpstan/phpstan": "^2.1.32@stable"
3537
},
3638
"autoload": {
3739
"psr-4": {
@@ -62,6 +64,7 @@
6264
"Composer\\Config::disableProcessTimeout",
6365
"@php vendor/bin/testbench serve --ansi"
6466
],
67+
"analyse": "@php vendor/bin/phpstan analyse --memory-limit=1G",
6568
"dev": [
6669
"@php vendor/bin/testbench solo"
6770
]

phpstan.neon.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
includes:
2+
- vendor/larastan/larastan/extension.neon
3+
4+
parameters:
5+
level: 6
6+
paths:
7+
- src
8+
- tests
9+
- workbench/app
10+
- workbench/routes
11+
tmpDir: build/phpstan

src/Commands/Command.php

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use SoloTerm\Solo\Support\KeyPressListener;
2222
use SplQueue;
2323

24+
/** @phpstan-consistent-constructor */
2425
class Command implements Loopable
2526
{
2627
use ManagesProcess, Ticks;
@@ -43,6 +44,7 @@ class Command implements Loopable
4344

4445
public int $scrollIndex = 0;
4546

47+
/** @var SplQueue<string> */
4648
public SplQueue $lines;
4749

4850
public int $height = 0;
@@ -108,6 +110,9 @@ public function boot(): void
108110
//
109111
}
110112

113+
/**
114+
* @return array<int|string, Hotkey>
115+
*/
111116
public function allHotkeys(): array
112117
{
113118
// In interactive mode, the only hotkey that works is
@@ -125,7 +130,7 @@ public function allHotkeys(): array
125130
$hotkeys['interactive'] = Hotkey::make('i', KeyHandler::Interactive)->label('Enter interactive mode');
126131
}
127132

128-
return array_filter($hotkeys);
133+
return $hotkeys;
129134
}
130135

131136
/**
@@ -138,7 +143,7 @@ public function hotkeys(): array
138143
];
139144
}
140145

141-
public function setDimensions($width, $height): static
146+
public function setDimensions(int $width, int $height): static
142147
{
143148
$existingOutput = isset($this->screen) ? $this->renderScreenBuffer() : null;
144149

@@ -228,12 +233,12 @@ public function isInteractive(): bool
228233
| Actions
229234
|--------------------------------------------------------------------------
230235
*/
231-
public function dd()
236+
public function dd(): never
232237
{
233238
dd($this->screen->printable->buffer);
234239
}
235240

236-
public function addOutput($text)
241+
public function addOutput(string $text): void
237242
{
238243
if ($this->expectsOutputMarkers) {
239244
$text = Str::before($text, $this->outputEndMarker);
@@ -243,7 +248,7 @@ public function addOutput($text)
243248
$this->screen->write($text);
244249
}
245250

246-
public function addLine($line)
251+
public function addLine(string $line): void
247252
{
248253
$this->screen->writeln($line);
249254
}
@@ -301,15 +306,15 @@ public function catchUpScroll(): void
301306
}
302307
}
303308

304-
public function scrollTo($index): void
309+
public function scrollTo(int|float $index): void
305310
{
306311
$this->scrollIndex = max(0, min(
307312
$index,
308313
$this->wrappedLines()->count() - $this->scrollPaneHeight()
309314
));
310315
}
311316

312-
public function scrollDown($amount = 1): void
317+
public function scrollDown(int|float $amount = 1): void
313318
{
314319
$this->paused = true;
315320
$this->scrollTo($this->scrollIndex + $amount);
@@ -320,18 +325,18 @@ public function scrollToBottom(): void
320325
$this->scrollDown(INF);
321326
}
322327

323-
public function pageDown()
328+
public function pageDown(): void
324329
{
325330
$this->scrollDown($this->scrollPaneHeight() - 1);
326331
}
327332

328-
public function scrollUp($amount = 1): void
333+
public function scrollUp(int|float $amount = 1): void
329334
{
330335
$this->paused = true;
331336
$this->scrollTo($this->scrollIndex - $amount);
332337
}
333338

334-
public function pageUp()
339+
public function pageUp(): void
335340
{
336341
$this->scrollUp($this->scrollPaneHeight() - 1);
337342
}
@@ -361,6 +366,9 @@ public function scrollPaneWidth(): int
361366
return max(1, $this->width - 4);
362367
}
363368

369+
/**
370+
* @return Collection<int, string>
371+
*/
364372
public function wrappedLines(): Collection
365373
{
366374
// Check if the screen has changed since last render
@@ -409,7 +417,7 @@ protected function renderScreenBuffer(): string
409417
return implode(PHP_EOL, $lines);
410418
}
411419

412-
protected function makeNewScreen()
420+
protected function makeNewScreen(): Screen
413421
{
414422
$screen = new Screen(
415423
width: $this->scrollPaneWidth(),
@@ -421,7 +429,10 @@ protected function makeNewScreen()
421429
});
422430
}
423431

424-
public function wrapLine($line, $width = null, $continuationIndent = 0, $recursive = false): array
432+
/**
433+
* @return array<int, string>
434+
*/
435+
public function wrapLine(string $line, ?int $width = null, int $continuationIndent = 0, bool $recursive = false): array
425436
{
426437
$defaultWidth = $this->scrollPaneWidth();
427438

@@ -446,15 +457,13 @@ public function wrapLine($line, $width = null, $continuationIndent = 0, $recursi
446457
$first = array_shift($exploded);
447458
$indent = str_repeat(' ', $continuationIndent);
448459

449-
if ($continuationIndent) {
450-
$allIndented = true;
451-
foreach ($exploded as $continuationLine) {
452-
$allIndented = $allIndented && str_starts_with($continuationLine, $indent);
453-
}
460+
$allIndented = true;
461+
foreach ($exploded as $continuationLine) {
462+
$allIndented = $allIndented && str_starts_with($continuationLine, $indent);
463+
}
454464

455-
if ($allIndented) {
456-
return [$first, ...$exploded];
457-
}
465+
if ($allIndented) {
466+
return [$first, ...$exploded];
458467
}
459468

460469
$rest = $indent . ltrim(implode('', $exploded));
@@ -465,13 +474,20 @@ public function wrapLine($line, $width = null, $continuationIndent = 0, $recursi
465474
];
466475
}
467476

477+
/**
478+
* @param Collection<int, string> $lines
479+
* @return Collection<int, string>
480+
*/
468481
protected function modifyWrappedLines(Collection $lines): Collection
469482
{
470483
// Primarily here for any subclasses.
471484
return $lines;
472485
}
473486

474-
public static function __set_state(array $data)
487+
/**
488+
* @param array<string, mixed> $data
489+
*/
490+
public static function __set_state(array $data): static
475491
{
476492
$instance = new static;
477493

0 commit comments

Comments
 (0)