Skip to content

Commit b82ab1f

Browse files
committed
fixed psalm
1 parent 637e733 commit b82ab1f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<psalm
33
errorLevel="1"
44
resolveFromConfigFile="true"
5+
findUnusedCode="false"
56
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
67
xmlns="https://getpsalm.org/schema/config"
78
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
@@ -20,7 +21,6 @@
2021
<RedundantPropertyInitializationCheck errorLevel="suppress" />
2122
<PropertyNotSetInConstructor errorLevel="suppress" />
2223
</issueHandlers>
23-
2424
<projectFiles>
2525
<directory name="src" />
2626
<ignoreFiles>

src/Casts/MoneyCast.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public function get($model, string $key, $value, array $attributes): Money
1818
throw new UnexpectedValueException;
1919
}
2020

21-
/** @var null|array{amount:mixed, currency:string} $value */
22-
$value = json_decode($value, true);
21+
/** @var null|array{amount:mixed, currency:string} $extractedValue */
22+
$extractedValue = json_decode($value, true);
2323

24-
if (! is_array($value) || ! isset($value['amount']) || ! isset($value['currency'])) {
24+
if (! is_array($extractedValue) || ! isset($extractedValue['amount']) || ! isset($extractedValue['currency'])) {
2525
throw new UnexpectedValueException;
2626
}
2727

2828
return new Money(
29-
$value['amount'],
30-
new Currency($value['currency'])
29+
$extractedValue['amount'],
30+
new Currency($extractedValue['currency'])
3131
);
3232
}
3333

@@ -37,7 +37,7 @@ public function set($model, string $key, $value, array $attributes): string
3737
throw new UnexpectedValueException;
3838
}
3939

40-
return json_encode([
40+
return (string) json_encode([
4141
'amount' => $value->getAmount(),
4242
'currency' => $value->getCurrency()->getCurrency(),
4343
]);

src/Currency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function toArray(): array
360360

361361
public function toJson($options = 0): string
362362
{
363-
return json_encode($this->toArray(), $options);
363+
return (string) json_encode($this->toArray(), $options);
364364
}
365365

366366
public function jsonSerialize(): array

src/Money.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function parseAmount(mixed $amount, bool $convert = false): int|float
245245

246246
protected function parseAmountFromCallable(mixed $amount): mixed
247247
{
248-
if (!is_callable($amount)) {
248+
if (! is_callable($amount)) {
249249
return $amount;
250250
}
251251

@@ -254,15 +254,15 @@ protected function parseAmountFromCallable(mixed $amount): mixed
254254

255255
protected function parseAmountFromString(mixed $amount): mixed
256256
{
257-
if (!is_string($amount)) {
257+
if (! is_string($amount)) {
258258
return $amount;
259259
}
260260

261261
$thousandsSeparator = $this->currency->getThousandsSeparator();
262262
$decimalMark = $this->currency->getDecimalMark();
263263

264264
$amount = str_replace($this->currency->getSymbol(), '', $amount);
265-
$amount = preg_replace('/[^\d\\' . $thousandsSeparator . '\\' . $decimalMark . '\-\+]/', '', $amount);
265+
$amount = (string) preg_replace('/[^\d\\' . $thousandsSeparator . '\\' . $decimalMark . '\-\+]/', '', $amount);
266266
$amount = str_replace($this->currency->getThousandsSeparator(), '', $amount);
267267
$amount = str_replace($this->currency->getDecimalMark(), '.', $amount);
268268

@@ -277,7 +277,7 @@ protected function parseAmountFromString(mixed $amount): mixed
277277

278278
protected function convertAmount(int|float $amount, bool $convert = false): int|float
279279
{
280-
if (!$convert) {
280+
if (! $convert) {
281281
return $amount;
282282
}
283283

@@ -329,7 +329,7 @@ public static function setLocale(?string $locale): void
329329
*/
330330
protected function assertSameCurrency(Money $other): void
331331
{
332-
if (!$this->isSameCurrency($other)) {
332+
if (! $this->isSameCurrency($other)) {
333333
throw new InvalidArgumentException('Different currencies "' . $this->currency . '" and "' . $other->currency . '"');
334334
}
335335
}
@@ -657,7 +657,7 @@ public function toArray(): array
657657

658658
public function toJson($options = 0): string
659659
{
660-
return json_encode($this->toArray(), $options);
660+
return (string) json_encode($this->toArray(), $options);
661661
}
662662

663663
public function jsonSerialize(): mixed

src/Provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function registerValidationRules(): void
3939
Validator::extend('currency_code', function (mixed $attribute, string $value, mixed $parameters, mixed $validator) {
4040
$status = false;
4141

42-
$currencies = config('money.currencies');
42+
$currencies = (array) config('money.currencies');
4343

4444
if (array_key_exists($value, $currencies)) {
4545
$status = true;

0 commit comments

Comments
 (0)