From 933c8e5ef25138431661512417a984b6b1e81c55 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 10:47:58 +0100 Subject: [PATCH 01/21] feat: phpstan level 5 --- .gitignore | 1 - composer.json | 7 ++++++- phpstan-baseline.neon | 0 phpstan.neon | 16 ++++++++++++++++ phpstan.neon.dist | 13 ------------- 5 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon delete mode 100644 phpstan.neon.dist diff --git a/.gitignore b/.gitignore index e26945a..3dd7896 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ composer.lock coverage docs phpunit.xml -phpstan.neon testbench.yaml vendor node_modules diff --git a/composer.json b/composer.json index c3950b1..bcc5f06 100644 --- a/composer.json +++ b/composer.json @@ -38,9 +38,9 @@ }, "require-dev": { "guzzlehttp/guzzle": "^7.0", + "larastan/larastan": "^2.9", "laravel/pint": "^1.0", "nunomaduro/collision": "^7.9", - "nunomaduro/larastan": "^2.0.1", "orchestra/testbench": "^8.0", "pestphp/pest": "^2.0", "pestphp/pest-plugin-arch": "^2.0", @@ -62,6 +62,11 @@ } }, "scripts": { + "qa" : [ + "@composer format", + "@composer analyse", + "@composer test" + ], "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/pest", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index e69de29..0000000 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..476fe95 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,16 @@ +parameters: + + paths: + - src/ + - config/ +# - tests/ + + + # Level 9 is the highest level + level: 5 + +# ignoreErrors: +# - '#PHPDoc tag @var#' +# +# excludePaths: +# - ./*/*/FileToBeExcluded.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 260b5e1..0000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,13 +0,0 @@ -includes: - - phpstan-baseline.neon - -parameters: - level: 4 - paths: - - src - - config - - database - tmpDir: build/phpstan - checkOctaneCompatibility: true - checkModelProperties: true - From 91c527519743e50441ebaab1894436cad6bd3115 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 10:49:17 +0100 Subject: [PATCH 02/21] fix: $database undefined --- src/NativeServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 9701766..11da0cf 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -163,7 +163,7 @@ public function removeDatabase() @unlink($databasePath); @unlink($databasePath.'-shm'); - @unlink($database.'-wal'); + @unlink($databasePath.'-wal'); } protected function configureDisks(): void From 5be83818de1091efa29301f381671e09a0ee4faa Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 10:55:29 +0100 Subject: [PATCH 03/21] fix: Unsafe usage of new static() --- src/ChildProcess.php | 2 +- src/Dialog.php | 2 +- src/Notification.php | 2 +- src/ProgressBar.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ChildProcess.php b/src/ChildProcess.php index 634e3f4..9897f32 100644 --- a/src/ChildProcess.php +++ b/src/ChildProcess.php @@ -19,7 +19,7 @@ class ChildProcess implements ChildProcessContract public readonly bool $persistent; - public function __construct(protected Client $client) {} + final public function __construct(protected Client $client) {} public function get(?string $alias = null): ?static { diff --git a/src/Dialog.php b/src/Dialog.php index 6188efa..5b8d891 100644 --- a/src/Dialog.php +++ b/src/Dialog.php @@ -26,7 +26,7 @@ class Dialog protected $windowReference; - public function __construct(protected Client $client) {} + final public function __construct(protected Client $client) {} public static function new() { diff --git a/src/Notification.php b/src/Notification.php index 85c7a73..82d13d8 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -12,7 +12,7 @@ class Notification protected string $event = ''; - public function __construct(protected Client $client) {} + final public function __construct(protected Client $client) {} public static function new() { diff --git a/src/ProgressBar.php b/src/ProgressBar.php index 74ca9d7..c9e318f 100644 --- a/src/ProgressBar.php +++ b/src/ProgressBar.php @@ -16,7 +16,7 @@ class ProgressBar protected float $maxSecondsBetweenRedraws = 1; - public function __construct(protected int $maxSteps, protected Client $client) {} + final public function __construct(protected int $maxSteps, protected Client $client) {} public static function create(int $maxSteps): static { From f0093099b29fb360a0744bd33af6b0003981d730 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 10:56:12 +0100 Subject: [PATCH 04/21] fix: ignore NativeAppServiceProvider not existing --- phpstan.neon | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 476fe95..6214410 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,7 +9,8 @@ parameters: # Level 9 is the highest level level: 5 -# ignoreErrors: + ignoreErrors: + - '#Class App\\Providers\\NativeAppServiceProvider not found#' # - '#PHPDoc tag @var#' # # excludePaths: From cc1cb879145df52c11751f2370471a298f25b0a2 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 10:57:46 +0100 Subject: [PATCH 05/21] fix: FreshCommand constructor invoked with 1 parameter, 0 required --- src/NativeServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 11da0cf..dab1a3b 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -46,8 +46,8 @@ public function packageRegistered() { $this->mergeConfigFrom($this->package->basePath('/../config/nativephp-internal.php'), 'nativephp-internal'); - $this->app->singleton(FreshCommand::class, function ($app) { - return new FreshCommand($app['migrator']); + $this->app->singleton(FreshCommand::class, function () { + return new FreshCommand; }); $this->app->singleton(MigrateCommand::class, function ($app) { From 03bd8327f9d62b0cf60e5833f7a33c57d01a70ad Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:03:59 +0100 Subject: [PATCH 06/21] fix: MenuBuilder facade function duplicates and arguments --- src/Facades/Menu.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Facades/Menu.php b/src/Facades/Menu.php index e12c2cb..332de24 100644 --- a/src/Facades/Menu.php +++ b/src/Facades/Menu.php @@ -3,6 +3,7 @@ namespace Native\Laravel\Facades; use Illuminate\Support\Facades\Facade; +use Native\Laravel\Contracts\MenuItem; use Native\Laravel\Menu\Items\Checkbox; use Native\Laravel\Menu\Items\Label; use Native\Laravel\Menu\Items\Link; @@ -11,7 +12,7 @@ use Native\Laravel\Menu\Items\Separator; /** - * @method static \Native\Laravel\Menu\Menu make(\Native\Laravel\Menu\Items\MenuItem ...$items) + * @method static \Native\Laravel\Menu\Menu make(MenuItem ...$items) * @method static Checkbox checkbox(string $label, bool $checked = false, ?string $hotkey = null) * @method static Label label(string $label) * @method static Link link(string $url, string $label = null, ?string $hotkey = null) @@ -23,7 +24,6 @@ * @method static Role view() * @method static Role window() * @method static Role help() - * @method static Role window() * @method static Role fullscreen() * @method static Role separator() * @method static Role devTools() @@ -37,7 +37,6 @@ * @method static Role minimize() * @method static Role close() * @method static Role quit() - * @method static Role help() * @method static Role hide() * @method static void create(MenuItem ...$items) * @method static void default() From 3c7e958fb4f2b108ae03707ef13aa8fa9c0c4d9f Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:05:41 +0100 Subject: [PATCH 07/21] fix: Type void cannot be part of a union type declaration. --- src/Dock.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Dock.php b/src/Dock.php index bdbb298..9691ff8 100644 --- a/src/Dock.php +++ b/src/Dock.php @@ -43,12 +43,14 @@ public function cancelBounce() $this->client->post('dock/cancel-bounce'); } - public function badge(?string $label = null): void|string + public function badge(?string $label = null): ?string { if (is_null($label)) { return $this->client->get('dock/badge'); } $this->client->post('dock/badge', ['label' => $label]); + + return null; } } From f0a5baf21a84f6bb1cd0eeac1b341432805b6c7e Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:08:24 +0100 Subject: [PATCH 08/21] fix: Php compactor missing imports and return statement --- src/Compactor/Php.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Compactor/Php.php b/src/Compactor/Php.php index f4838bf..7b5d3ad 100644 --- a/src/Compactor/Php.php +++ b/src/Compactor/Php.php @@ -3,6 +3,8 @@ namespace Native\Laravel\Compactor; use PhpToken; +use RuntimeException; +use Webmozart\Assert\Assert; class Php { @@ -17,7 +19,7 @@ public function compact(string $file, string $contents): string return $this->compactContent($contents); } - $this->compactContent($contents); + return $this->compactContent($contents); } protected function compactContent(string $contents): string @@ -145,7 +147,6 @@ private function retokenizeAttribute(array &$tokens, int $opener): ?array { Assert::keyExists($tokens, $opener); - /** @var PhpToken $token */ $token = $tokens[$opener]; $attributeBody = mb_substr($token->text, 2); $subTokens = PhpToken::tokenize(' Date: Thu, 12 Dec 2024 11:09:29 +0100 Subject: [PATCH 09/21] fix: missing SeedDatabaseCommand@handle return statement --- src/Commands/SeedDatabaseCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/SeedDatabaseCommand.php b/src/Commands/SeedDatabaseCommand.php index c83879e..cdc032e 100644 --- a/src/Commands/SeedDatabaseCommand.php +++ b/src/Commands/SeedDatabaseCommand.php @@ -15,6 +15,6 @@ public function handle() { (new NativeServiceProvider($this->laravel))->rewriteDatabase(); - parent::handle(); + return parent::handle(); } } From 585fb4727ced16a729f18a32a188a99a7b1cd1ea Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:21:20 +0100 Subject: [PATCH 10/21] Fix: cannot assign a value to a public readonly property outside of the constructor --- src/ChildProcess.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ChildProcess.php b/src/ChildProcess.php index 9897f32..5ea047f 100644 --- a/src/ChildProcess.php +++ b/src/ChildProcess.php @@ -7,17 +7,17 @@ class ChildProcess implements ChildProcessContract { - public readonly int $pid; + public int $pid; - public readonly string $alias; + public string $alias; - public readonly array $cmd; + public array $cmd; - public readonly ?string $cwd; + public ?string $cwd; - public readonly ?array $env; + public ?array $env; - public readonly bool $persistent; + public bool $persistent; final public function __construct(protected Client $client) {} @@ -54,7 +54,6 @@ public function all(): array /** * @param string|string[] $cmd - * @return $this */ public function start( string|array $cmd, @@ -78,16 +77,15 @@ public function start( /** * @param string|string[] $cmd - * @return $this */ - public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self + public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): static { $cmd = is_array($cmd) ? array_values($cmd) : [$cmd]; $process = $this->client->post('child-process/start-php', [ 'alias' => $alias, 'cmd' => $cmd, - 'cwd' => $cwd ?? base_path(), + 'cwd' => base_path(), 'env' => $env, 'persistent' => $persistent, ])->json(); @@ -97,9 +95,8 @@ public function php(string|array $cmd, string $alias, ?array $env = null, ?bool /** * @param string|string[] $cmd - * @return $this */ - public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self + public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): static { $cmd = is_array($cmd) ? array_values($cmd) : [$cmd]; From 8fb93e9636221203adc8158c31dc78efd3591f78 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:23:38 +0100 Subject: [PATCH 11/21] Fix: PowerMonitor invoked Client::get() with 2 parameters, 1 required --- src/Client/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/Client.php b/src/Client/Client.php index e444ea4..9a8ec81 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -21,9 +21,9 @@ public function __construct() ->asJson(); } - public function get(string $endpoint): Response + public function get(string $endpoint, array|string|null $query = null): Response { - return $this->client->get($endpoint); + return $this->client->get($endpoint, $query); } public function post(string $endpoint, array $data = []): Response From cac9ea1442e5a8a4019e97aa58fdc39b9b3aa4c9 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:29:46 +0100 Subject: [PATCH 12/21] fix: alternative for FreshCommand migrator argument --- src/NativeServiceProvider.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index dab1a3b..228ed34 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -46,8 +46,14 @@ public function packageRegistered() { $this->mergeConfigFrom($this->package->basePath('/../config/nativephp-internal.php'), 'nativephp-internal'); - $this->app->singleton(FreshCommand::class, function () { - return new FreshCommand; + $this->app->singleton(FreshCommand::class, function ($app) { + + // if Laravel 11 or higher, send the migrator instance to the FreshCommand + if (version_compare($app->version(), '11.0.0', '>=')) { + return new FreshCommand($app['migrator']); + } + + return new FreshCommand(); }); $this->app->singleton(MigrateCommand::class, function ($app) { From 7aa74f12154dcc0a7d308e55f150260f01dcb8cb Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:33:00 +0100 Subject: [PATCH 13/21] Revert "fix: alternative for FreshCommand migrator argument" This reverts commit cac9ea1442e5a8a4019e97aa58fdc39b9b3aa4c9. --- src/NativeServiceProvider.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 228ed34..dab1a3b 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -46,14 +46,8 @@ public function packageRegistered() { $this->mergeConfigFrom($this->package->basePath('/../config/nativephp-internal.php'), 'nativephp-internal'); - $this->app->singleton(FreshCommand::class, function ($app) { - - // if Laravel 11 or higher, send the migrator instance to the FreshCommand - if (version_compare($app->version(), '11.0.0', '>=')) { - return new FreshCommand($app['migrator']); - } - - return new FreshCommand(); + $this->app->singleton(FreshCommand::class, function () { + return new FreshCommand; }); $this->app->singleton(MigrateCommand::class, function ($app) { From d1a90f4940f5c8fde724e86df6a5e429e6957db4 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:33:01 +0100 Subject: [PATCH 14/21] Revert "fix: FreshCommand constructor invoked with 1 parameter, 0 required" This reverts commit cc1cb879145df52c11751f2370471a298f25b0a2. --- src/NativeServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index dab1a3b..11da0cf 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -46,8 +46,8 @@ public function packageRegistered() { $this->mergeConfigFrom($this->package->basePath('/../config/nativephp-internal.php'), 'nativephp-internal'); - $this->app->singleton(FreshCommand::class, function () { - return new FreshCommand; + $this->app->singleton(FreshCommand::class, function ($app) { + return new FreshCommand($app['migrator']); }); $this->app->singleton(MigrateCommand::class, function ($app) { From 6b88d133254bcb8881df7b4fc88a4aa5f4edc72a Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:47:26 +0100 Subject: [PATCH 15/21] fix: trying something --- .github/workflows/run-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 107761b..22025b3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -32,6 +32,8 @@ jobs: exclude: - laravel: 11.* php: 8.1 + - laravel: 10.* + prefer-lowest: true name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 36ff2612885ec2963dec518a29c3549d155492b2 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:53:34 +0100 Subject: [PATCH 16/21] fix: phpstan.yml --- .github/workflows/phpstan.yml | 40 ++++++++++++++++++++++++----------- composer.json | 5 ++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 3855a08..84219d8 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,26 +1,42 @@ name: PHPStan on: + workflow_dispatch: push: - paths: - - '**.php' - - 'phpstan.neon.dist' + branches-ignore: + - 'dependabot/npm_and_yarn/*' jobs: phpstan: - name: phpstan - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + php: [8.3] + steps: - - uses: actions/checkout@v4 + + - name: Checkout code + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' - coverage: none + php-version: ${{ matrix.php }} + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer- - - name: Install composer dependencies - uses: ramsey/composer-install@v3 + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - name: Run PHPStan - run: ./vendor/bin/phpstan --error-format=github + - name: Run analysis + run: ./vendor/bin/phpstan analyse --error-format=github diff --git a/composer.json b/composer.json index bcc5f06..3864704 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ }, "require-dev": { "guzzlehttp/guzzle": "^7.0", - "larastan/larastan": "^2.9", + "larastan/larastan": "^2.9|^3.0", "laravel/pint": "^1.0", "nunomaduro/collision": "^7.9", "orchestra/testbench": "^8.0", @@ -52,8 +52,7 @@ }, "autoload": { "psr-4": { - "Native\\Laravel\\": "src/", - "Native\\Laravel\\Database\\Factories\\": "database/factories/" + "Native\\Laravel\\": "src/" } }, "autoload-dev": { From c3c2e63df4a1e489632718460042a34560d0a4e6 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 11:55:47 +0100 Subject: [PATCH 17/21] Revert "fix: trying something" This reverts commit 6b88d133254bcb8881df7b4fc88a4aa5f4edc72a. --- .github/workflows/run-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 22025b3..107761b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -32,8 +32,6 @@ jobs: exclude: - laravel: 11.* php: 8.1 - - laravel: 10.* - prefer-lowest: true name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From 2ce633409a939d5c3e7b2721b8994dd8aab1d215 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 12:06:14 +0100 Subject: [PATCH 18/21] fix: trying to lower the minimum laravel 10 dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3864704..9f7b760 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ }, "require-dev": { "guzzlehttp/guzzle": "^7.0", - "larastan/larastan": "^2.9|^3.0", + "larastan/larastan": "^2.0|^3.0", "laravel/pint": "^1.0", "nunomaduro/collision": "^7.9", "orchestra/testbench": "^8.0", From b9dc7480a19eeab9628bf848aabb83a1e807e0b9 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 12 Dec 2024 12:11:38 +0100 Subject: [PATCH 19/21] =?UTF-8?q?fix:=20final=20fix=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/NativeServiceProvider.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 11da0cf..f7beecb 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -47,6 +47,7 @@ public function packageRegistered() $this->mergeConfigFrom($this->package->basePath('/../config/nativephp-internal.php'), 'nativephp-internal'); $this->app->singleton(FreshCommand::class, function ($app) { + /* @phpstan-ignore-next-line (beacause we support Laravel 10 & 11) */ return new FreshCommand($app['migrator']); }); @@ -137,13 +138,15 @@ public function rewriteDatabase() } } - config(['database.connections.nativephp' => [ - 'driver' => 'sqlite', - 'url' => env('DATABASE_URL'), - 'database' => $databasePath, - 'prefix' => '', - 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), - ]]); + config([ + 'database.connections.nativephp' => [ + 'driver' => 'sqlite', + 'url' => env('DATABASE_URL'), + 'database' => $databasePath, + 'prefix' => '', + 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), + ], + ]); config(['database.default' => 'nativephp']); @@ -186,12 +189,14 @@ protected function configureDisks(): void continue; } - config(['filesystems.disks.'.$disk => [ - 'driver' => 'local', - 'root' => env($env, ''), - 'throw' => false, - 'links' => 'skip', - ]]); + config([ + 'filesystems.disks.'.$disk => [ + 'driver' => 'local', + 'root' => env($env, ''), + 'throw' => false, + 'links' => 'skip', + ], + ]); } } } From e69562edd27b531db403da71f670aa6e31f5efb2 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 19 Dec 2024 00:34:39 +0100 Subject: [PATCH 20/21] Revert "Fix: cannot assign a value to a public readonly property outside of the constructor" This reverts commit 585fb4727ced16a729f18a32a188a99a7b1cd1ea. --- src/ChildProcess.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ChildProcess.php b/src/ChildProcess.php index 5ea047f..9897f32 100644 --- a/src/ChildProcess.php +++ b/src/ChildProcess.php @@ -7,17 +7,17 @@ class ChildProcess implements ChildProcessContract { - public int $pid; + public readonly int $pid; - public string $alias; + public readonly string $alias; - public array $cmd; + public readonly array $cmd; - public ?string $cwd; + public readonly ?string $cwd; - public ?array $env; + public readonly ?array $env; - public bool $persistent; + public readonly bool $persistent; final public function __construct(protected Client $client) {} @@ -54,6 +54,7 @@ public function all(): array /** * @param string|string[] $cmd + * @return $this */ public function start( string|array $cmd, @@ -77,15 +78,16 @@ public function start( /** * @param string|string[] $cmd + * @return $this */ - public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): static + public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self { $cmd = is_array($cmd) ? array_values($cmd) : [$cmd]; $process = $this->client->post('child-process/start-php', [ 'alias' => $alias, 'cmd' => $cmd, - 'cwd' => base_path(), + 'cwd' => $cwd ?? base_path(), 'env' => $env, 'persistent' => $persistent, ])->json(); @@ -95,8 +97,9 @@ public function php(string|array $cmd, string $alias, ?array $env = null, ?bool /** * @param string|string[] $cmd + * @return $this */ - public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): static + public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self { $cmd = is_array($cmd) ? array_values($cmd) : [$cmd]; From e3aeca812af912c39f7a0dbb8a4b74c81bf41dd5 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Thu, 19 Dec 2024 00:50:21 +0100 Subject: [PATCH 21/21] fix: put back previous fixes and ignore phpstan errors --- phpstan.neon | 3 ++- src/ChildProcess.php | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 6214410..33be1e3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,7 +11,8 @@ parameters: ignoreErrors: - '#Class App\\Providers\\NativeAppServiceProvider not found#' -# - '#PHPDoc tag @var#' + - '#Class Native\\Laravel\\ChildProcess has an uninitialized readonly property#' + # # excludePaths: # - ./*/*/FileToBeExcluded.php diff --git a/src/ChildProcess.php b/src/ChildProcess.php index 9897f32..f524370 100644 --- a/src/ChildProcess.php +++ b/src/ChildProcess.php @@ -21,7 +21,7 @@ class ChildProcess implements ChildProcessContract final public function __construct(protected Client $client) {} - public function get(?string $alias = null): ?static + public function get(?string $alias = null): ?self { $alias = $alias ?? $this->alias; @@ -62,7 +62,7 @@ public function start( ?string $cwd = null, ?array $env = null, bool $persistent = false - ): static { + ): self { $cmd = is_array($cmd) ? array_values($cmd) : [$cmd]; $process = $this->client->post('child-process/start', [ @@ -87,7 +87,7 @@ public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $process = $this->client->post('child-process/start-php', [ 'alias' => $alias, 'cmd' => $cmd, - 'cwd' => $cwd ?? base_path(), + 'cwd' => base_path(), 'env' => $env, 'persistent' => $persistent, ])->json(); @@ -115,7 +115,7 @@ public function stop(?string $alias = null): void ])->json(); } - public function restart(?string $alias = null): ?static + public function restart(?string $alias = null): ?self { $process = $this->client->post('child-process/restart', [ 'alias' => $alias ?? $this->alias, @@ -128,7 +128,7 @@ public function restart(?string $alias = null): ?static return $this->fromRuntimeProcess($process); } - public function message(string $message, ?string $alias = null): static + public function message(string $message, ?string $alias = null): self { $this->client->post('child-process/message', [ 'alias' => $alias ?? $this->alias, @@ -138,9 +138,10 @@ public function message(string $message, ?string $alias = null): static return $this; } - protected function fromRuntimeProcess($process): static + protected function fromRuntimeProcess($process) { if (isset($process['pid'])) { + // @phpstan-ignore-next-line $this->pid = $process['pid']; }