Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Jul 11, 2022
1 parent 40ad24a commit 9eaa816
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/AmastyLabelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Rapidez\AmastyLabel;

use Illuminate\Support\ServiceProvider;
use Rapidez\AmastyLabel\Models\Scopes\WithProductAmastyLabelScope;
use Rapidez\AmastyLabel\Models\Casts\CastAmastyLabelVariables;
use Rapidez\AmastyLabel\Models\Scopes\WithProductAmastyLabelScope;
use TorMorten\Eventy\Facades\Eventy;

class AmastyLabelServiceProvider extends ServiceProvider
Expand All @@ -15,7 +15,7 @@ public function boot()
->bootEventyFilters();
}

public function bootEventyFilters() : self
public function bootEventyFilters(): self
{
Eventy::addFilter('product.scopes', fn ($scopes) => array_merge($scopes ?: [], [WithProductAmastyLabelScope::class]));
Eventy::addFilter('product.casts', fn ($casts) => array_merge($casts ?: [], ['amasty_label' => CastAmastyLabelVariables::class]));
Expand All @@ -30,7 +30,7 @@ public function bootEventyFilters() : self
return $this;
}

public function bootViews() : self
public function bootViews(): self
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'amastylabel');

Expand Down
24 changes: 12 additions & 12 deletions src/Models/Casts/CastAmastyLabelVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Rapidez\AmastyLabel\Models\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Rapidez\Core\Models\Model;
use Illuminate\Support\Collection;
use Rapidez\Core\Models\Model;

class CastAmastyLabelVariables implements CastsAttributes
{
protected $variableRegex = '/(?<={)[a-zA-Z0-9_:]+(?=})/';

public function get($model, string $key, $value, array $attributes) : Collection
public function get($model, string $key, $value, array $attributes): Collection
{
$labels = collect(json_decode($value));
if (!$labels->count()) {
Expand All @@ -36,27 +36,27 @@ public function get($model, string $key, $value, array $attributes) : Collection
return $labels;
}

protected function parseVariables(string $text, string $type, string $var, Model $model) : string
protected function parseVariables(string $text, string $type, string $var, Model $model): string
{
return match($type) {
'flat' => str_replace("{{$var}}", price($model->{strtolower($var)}), $text),
'amount' => str_replace("{{$var}}", price($model->price - $model->special_price), $text),
'percent' => str_replace("{{$var}}", (100 - floor(($model->special_price / $model->price) * 100)) . '%', $text),
return match ($type) {
'flat' => str_replace("{{$var}}", price($model->{strtolower($var)}), $text),
'amount' => str_replace("{{$var}}", price($model->price - $model->special_price), $text),
'percent' => str_replace("{{$var}}", (100 - floor(($model->special_price / $model->price) * 100)).'%', $text),
};
}

public function set($model, string $key, $value, array $attributes) : string
public function set($model, string $key, $value, array $attributes): string
{
return $value;
}

protected function getType(string $type)
{
return [
'SPECIAL_PRICE' => 'flat',
'PRICE' => 'flat',
'SAVE_AMOUNT' => 'amount',
'SAVE_PERCENT' => 'percent'
'SPECIAL_PRICE' => 'flat',
'PRICE' => 'flat',
'SAVE_AMOUNT' => 'amount',
'SAVE_PERCENT' => 'percent',
][$type] ?? null;
}
}

0 comments on commit 9eaa816

Please sign in to comment.