Skip to content

Commit

Permalink
PHPStan level 1 (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Nov 12, 2024
1 parent 4d24b1c commit ee042b4
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 8 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: analyse

on:
push:
branches:
- master
- '*.x'
pull_request:

jobs:
analyse:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.3]
stability: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.RAPIDEZ_ACTIONS_ACCOUNT_PAT }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Analyse
run: composer analyse
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"tormjens/eventy": "^0.8"
},
"require-dev": {
"larastan/larastan": "^2.9",
"laravel/dusk": "^8.2",
"orchestra/testbench": "^9.4",
"orchestra/testbench-dusk": "^9.7",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^10.5.34|^11.3.5"
},
"autoload": {
Expand Down Expand Up @@ -61,6 +63,7 @@
}
},
"scripts": {
"analyse": "phpstan --memory-limit=256M",
"dusk:prepare": [
"./vendor/bin/dusk-updater detect --auto-update",
"@php -r \"file_exists('phpunit.dusk.xml') || copy('phpunit.dusk.xml.dist', 'phpunit.dusk.xml'); \""
Expand Down
1 change: 1 addition & 0 deletions config/rapidez/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'attribute' => Rapidez\Core\Models\Attribute::class,
'product' => Rapidez\Core\Models\Product::class,
'category' => Rapidez\Core\Models\Category::class,
'customer_group' => Rapidez\Core\Models\CustomerGroup::class,
'category_product' => Rapidez\Core\Models\CategoryProduct::class,
'customer' => Rapidez\Core\Models\Customer::class,
'config' => Rapidez\Core\Models\Config::class,
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
includes:
- ./vendor/larastan/larastan/extension.neon

parameters:
paths:
- src/
- tests/
- routes/
ignoreErrors:
- '#^Result of static method TorMorten\\Eventy\\Events::#'
- "#Access to an undefined property#"
level: 1
3 changes: 2 additions & 1 deletion src/Actions/DecodeJwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Lcobucci\JWT\Validation\Constraint\SignedWith;
use Lcobucci\JWT\Validation\ConstraintViolation;
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
use Rapidez\Core\Exceptions\DecryptionException;

class DecodeJwt
{
Expand All @@ -39,7 +40,7 @@ public static function decode(string $jwt): UnencryptedToken
}
}

throw $exception;
throw $exception ?? new DecryptionException('No crypt keys defined.');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/MagentoCartTokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function register()
});

auth()->extend('magento-cart', function (Application $app, string $name, array $config) {
return new static(auth()->createUserProvider($config['provider']), request(), 'mask', 'mask');
return new self(auth()->createUserProvider($config['provider']), request(), 'mask', 'mask');
});

config([
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/MagentoCustomerTokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function register()
});

auth()->extend('magento-customer', function (Application $app, string $name, array $config) {
return new static(auth()->createUserProvider($config['provider']), request(), 'token', 'token');
return new self(auth()->createUserProvider($config['provider']), request(), 'token', 'token');
});

config([
Expand Down
Empty file removed src/Casts/QuoteItems.php
Empty file.
4 changes: 3 additions & 1 deletion src/ContentVariables/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public function __invoke($content)
return preg_replace_callback('/{{widget type="(.*?)" (.*?)}}/ms', function ($matches) {
[$full, $type, $parameters] = $matches;
preg_match_all('/(.*?)="(.*?)"/ms', $parameters, $parameters, PREG_SET_ORDER);

$options = [];
foreach ($parameters as $parameter) {
[$full, $parameter, $value] = $parameter;
$options[trim($parameter)] = trim($value);
}

if (! isset($type)) {
if (! $type) {
return '';
}

Expand Down
1 change: 1 addition & 0 deletions src/Facades/Rapidez.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method static array getStores($storeId = null)
* @method static array getStore($storeId)
* @method static void setStore($store)
* @method static mixed withStore(\Rapidez\Core\Models\Store|array|callable|int|string $store, callable $callback, mixed ...$args)
*
* @see \Rapidez\Core\Rapidez
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function oauthTokens()

public function group()
{
return $this->belongsTo(CustomerGroup::class, 'group_id');
return $this->belongsTo(config('rapidez.models.customer_group'), 'group_id');
}

public function getRememberTokenName()
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function categoryProducts(): HasMany
public function reviewSummary(): HasOne
{
return $this->hasOne(
config('rapidez.models.product_review_summary', Rapidez\Core\Models\ProductReviewSummary::class),
config('rapidez.models.product_review_summary', \Rapidez\Core\Models\ProductReviewSummary::class),
'entity_pk_value'
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ProductReviewSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected static function booting(): void
public function product(): BelongsTo
{
return $this->belongsTo(
config('rapidez.models.product', Rapidez\Core\Models\Product::class),
config('rapidez.models.product', \Rapidez\Core\Models\Product::class),
'entity_pk_value'
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Rapidez.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Rapidez\Core\Exceptions\StoreNotFoundException;
use Rapidez\Core\Models\Store;

class Rapidez
Expand Down
3 changes: 2 additions & 1 deletion tests/DuskTestCaseSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp(): void

Browser::macro('waitUntilIdle', function ($timeout = 120) {
/** @var Browser $this */
$this->waitUntilTrueForDuration('window.app?.$data?.loading !== true && await new Promise((resolve, reject) => window.requestIdleCallback((deadline) => resolve(!deadline.didTimeout), {timeout: 5}))', $timeout);
$this->waitUntilTrueForDuration('window.app?.$data?.loading !== true && await new Promise((resolve, reject) => window.requestIdleCallback((deadline) => resolve(!deadline.didTimeout), {timeout: 5}))', $timeout); // @phpstan-ignore-line

return $this;
});
Expand All @@ -63,6 +63,7 @@ protected function setUp(): void
->visit($productUrl);
}

// @phpstan-ignore-next-line
$this
->waitUntilIdle()
->pressAndWaitFor('@add-to-cart', 60)
Expand Down

0 comments on commit ee042b4

Please sign in to comment.