Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
933c8e5
feat: phpstan level 5
SRWieZ Dec 12, 2024
91c5275
fix: $database undefined
SRWieZ Dec 12, 2024
5be8381
fix: Unsafe usage of new static()
SRWieZ Dec 12, 2024
f009309
fix: ignore NativeAppServiceProvider not existing
SRWieZ Dec 12, 2024
cc1cb87
fix: FreshCommand constructor invoked with 1 parameter, 0 required
SRWieZ Dec 12, 2024
03bd832
fix: MenuBuilder facade function duplicates and arguments
SRWieZ Dec 12, 2024
3c7e958
fix: Type void cannot be part of a union type declaration.
SRWieZ Dec 12, 2024
f0a5baf
fix: Php compactor missing imports and return statement
SRWieZ Dec 12, 2024
7ebe7f9
fix: missing SeedDatabaseCommand@handle return statement
SRWieZ Dec 12, 2024
585fb47
Fix: cannot assign a value to a public readonly property outside of t…
SRWieZ Dec 12, 2024
8fb93e9
Fix: PowerMonitor invoked Client::get() with 2 parameters, 1 required
SRWieZ Dec 12, 2024
cac9ea1
fix: alternative for FreshCommand migrator argument
SRWieZ Dec 12, 2024
7aa74f1
Revert "fix: alternative for FreshCommand migrator argument"
SRWieZ Dec 12, 2024
d1a90f4
Revert "fix: FreshCommand constructor invoked with 1 parameter, 0 req…
SRWieZ Dec 12, 2024
6b88d13
fix: trying something
SRWieZ Dec 12, 2024
36ff261
fix: phpstan.yml
SRWieZ Dec 12, 2024
c3c2e63
Revert "fix: trying something"
SRWieZ Dec 12, 2024
2ce6334
fix: trying to lower the minimum laravel 10 dependency
SRWieZ Dec 12, 2024
b9dc748
fix: final fix 🎉
SRWieZ Dec 12, 2024
e69562e
Revert "Fix: cannot assign a value to a public readonly property outs…
SRWieZ Dec 18, 2024
e3aeca8
fix: put back previous fixes and ignore phpstan errors
SRWieZ Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ composer.lock
coverage
docs
phpunit.xml
phpstan.neon
testbench.yaml
vendor
node_modules
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"require-dev": {
"guzzlehttp/guzzle": "^7.0",
"larastan/larastan": "^2.0|^3.0",
"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",
Expand All @@ -52,8 +52,7 @@
},
"autoload": {
"psr-4": {
"Native\\Laravel\\": "src/",
"Native\\Laravel\\Database\\Factories\\": "database/factories/"
"Native\\Laravel\\": "src/"
}
},
"autoload-dev": {
Expand All @@ -62,6 +61,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",
Expand Down
Empty file removed phpstan-baseline.neon
Empty file.
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:

paths:
- src/
- config/
# - tests/


# Level 9 is the highest level
level: 5

ignoreErrors:
- '#Class App\\Providers\\NativeAppServiceProvider not found#'
# - '#PHPDoc tag @var#'
#
# excludePaths:
# - ./*/*/FileToBeExcluded.php
13 changes: 0 additions & 13 deletions phpstan.neon.dist

This file was deleted.

23 changes: 10 additions & 13 deletions src/ChildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

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;

public function __construct(protected Client $client) {}
final public function __construct(protected Client $client) {}

public function get(?string $alias = null): ?static
{
Expand Down Expand Up @@ -54,7 +54,6 @@ public function all(): array

/**
* @param string|string[] $cmd
* @return $this
*/
public function start(
string|array $cmd,
Expand All @@ -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();
Expand All @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SeedDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function handle()
{
(new NativeServiceProvider($this->laravel))->rewriteDatabase();

parent::handle();
return parent::handle();
}
}
5 changes: 3 additions & 2 deletions src/Compactor/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Native\Laravel\Compactor;

use PhpToken;
use RuntimeException;
use Webmozart\Assert\Assert;

class Php
{
Expand All @@ -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
Expand Down Expand Up @@ -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('<?php '.$attributeBody);
Expand Down
2 changes: 1 addition & 1 deletion src/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Dock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 2 additions & 3 deletions src/Facades/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down
33 changes: 19 additions & 14 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});

Expand Down Expand Up @@ -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']);

Expand All @@ -163,7 +166,7 @@ public function removeDatabase()

@unlink($databasePath);
@unlink($databasePath.'-shm');
@unlink($database.'-wal');
@unlink($databasePath.'-wal');
}

protected function configureDisks(): void
Expand All @@ -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',
],
]);
}
}
}
2 changes: 1 addition & 1 deletion src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading