Skip to content

Commit cda81b7

Browse files
committed
stan lvl 9
1 parent c1a867b commit cda81b7

29 files changed

+215
-106
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
"spatie/laravel-package-tools": "^1.14"
2525
},
2626
"require-dev": {
27+
"larastan/larastan": "^3.0.0",
2728
"laravel/pint": "^1.0",
2829
"nunomaduro/collision": "^8.1",
29-
"larastan/larastan": "^3.0.0",
3030
"orchestra/testbench": "^9.0",
3131
"pestphp/pest": "^3.0",
3232
"pestphp/pest-plugin-arch": "^3.0",
3333
"pestphp/pest-plugin-laravel": "^3.0",
34+
"phpstan/extension-installer": "^1.4",
3435
"phpstan/phpstan-deprecation-rules": "^2.0",
3536
"phpstan/phpstan-phpunit": "^2.0"
3637
},

config/invoices.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Finller\Invoice\Invoice;
46
use Finller\Invoice\InvoiceDiscount;
57
use Finller\Invoice\InvoiceItem;

database/factories/InvoiceFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Finller\Invoice\Database\Factories;
46

57
use Carbon\Carbon;

database/factories/InvoiceItemFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Finller\Invoice\Database\Factories;
46

57
use Brick\Money\Money;
@@ -15,8 +17,10 @@ class InvoiceItemFactory extends Factory
1517

1618
public function definition()
1719
{
18-
$price = Money::ofMinor(fake()->numberBetween(1000, 100000), config('invoices.default_currency'));
19-
$unit_tax = Money::ofMinor(fake()->numberBetween(0, $price->getAmount()->toFloat()), config('invoices.default_currency'));
20+
$currency = config()->string('invoices.default_currency');
21+
22+
$price = Money::ofMinor(fake()->numberBetween(1000, 100000), $currency);
23+
$unit_tax = Money::ofMinor(fake()->numberBetween(0, $price->getAmount()->toFloat()), $currency);
2024

2125
$useTaxPercentage = fake()->boolean();
2226

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
includes:
2-
- vendor/larastan/larastan/extension.neon
2+
- phpstan-baseline.neon
33

44
parameters:
5-
level: 6
5+
level: 9
66
paths:
77
- src
88
- config
@@ -11,6 +11,4 @@ parameters:
1111
checkOctaneCompatibility: true
1212
checkModelProperties: true
1313
checkModelAppends: false
14-
noEnvCallsOutsideOfConfig: false
15-
ignoreErrors:
16-
- '#Method Finller\\Invoice\\InvoiceDiscount::fromLivewire\(\) has no return type specified#'
14+
noEnvCallsOutsideOfConfig: false

pint.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"exclude": [
3-
"build"
4-
]
2+
"preset": "laravel",
3+
"rules": {
4+
"declare_strict_types": true,
5+
"explicit_string_variable": true,
6+
"mb_str_functions": true
7+
}
58
}

resources/lang/en/invoice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
/*
57
|--------------------------------------------------------------------------

resources/lang/fr/invoice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
/*
57
|--------------------------------------------------------------------------

src/Casts/Discounts.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Finller\Invoice\Casts;
46

57
use Finller\Invoice\InvoiceDiscount;
@@ -14,16 +16,29 @@ class Discounts implements CastsAttributes
1416
{
1517
/**
1618
* @param array<string, mixed> $attributes
17-
* @return null|InvoiceDiscount[]
19+
* @return InvoiceDiscount[]
1820
*/
1921
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
2022
{
21-
$data = Json::decode(data_get($attributes, $key, ''));
23+
/**
24+
* @var null|array<array-key, null|array{
25+
* name: ?string,
26+
* code: ?string,
27+
* currency: ?string,
28+
* amount_off: ?int,
29+
* percent_off: ?float,
30+
* }> $data
31+
*/
32+
$data = Json::decode($attributes[$key] ?? '');
33+
34+
/** @var class-string<InvoiceDiscount> $class */
35+
$class = config()->string('invoices.discount_class');
2236

23-
/** @var string $class */
24-
$class = config('invoices.discount_class');
37+
if (! is_array($data)) {
38+
return [];
39+
}
2540

26-
return is_array($data) ? array_map(fn (?array $item) => $class::fromArray($item), $data) : null;
41+
return array_map(fn ($item) => $class::fromArray($item), $data);
2742
}
2843

2944
/**
@@ -35,6 +50,8 @@ public function get(Model $model, string $key, mixed $value, array $attributes):
3550
*/
3651
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
3752
{
38-
return [$key => Json::encode($value)];
53+
return [
54+
$key => blank($value) ? null : Json::encode($value),
55+
];
3956
}
4057
}

0 commit comments

Comments
 (0)