Phpstan
This commit is contained in:
parent
fb062e11aa
commit
8278419606
44 changed files with 510 additions and 223 deletions
|
|
@ -15,10 +15,10 @@ class HtmlColor implements CastsAttributes
|
|||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
@ -32,10 +32,10 @@ class HtmlColor implements CastsAttributes
|
|||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return integer
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ class RgbaColor extends HtmlColor
|
|||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
@ -24,6 +24,7 @@ class RgbaColor extends HtmlColor
|
|||
public function get($model, $key, $value, $attributes)
|
||||
{
|
||||
// phpcs:enable
|
||||
/** @var \Illuminate\Support\Collection<array-key, float> */
|
||||
$intValues = collect(\str_split($this->zeropad(\dechex(\intval($value)), 8), 2))->map(function ($hex) {
|
||||
return intval(\hexdec($hex));
|
||||
});
|
||||
|
|
@ -35,10 +36,10 @@ class RgbaColor extends HtmlColor
|
|||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return integer
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
|
|||
|
|
@ -26,28 +26,28 @@ class CreateAdmin extends Command
|
|||
/**
|
||||
* The firstname of the new user.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $firstname;
|
||||
|
||||
/**
|
||||
* The lastname of the new user.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $lastname;
|
||||
|
||||
/**
|
||||
* The email of the new user.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* The password of the new user.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ enum CookingModeEnum: int
|
|||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::withoutCooking->name => 'Sans cuisson',
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ enum DifficultyEnum: int
|
|||
case medium = 2;
|
||||
case hard = 3;
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::easy->name => 'Facile',
|
||||
self::medium->name => 'Moyen',
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ enum NutriscoreEnum: int
|
|||
case dLetter = 5;
|
||||
case eLetter = 6;
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::noLetter->name => 'N/A',
|
||||
self::aLetter->name => 'A',
|
||||
|
|
@ -24,6 +30,11 @@ enum NutriscoreEnum: int
|
|||
self::eLetter->name => 'E'
|
||||
];
|
||||
|
||||
/**
|
||||
* Enum stickers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private const STICKERS = [
|
||||
self::noLetter->name => '',
|
||||
self::aLetter->name => 'resources/assets/images/nutriscore/logo-nutriscore-A.png',
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ enum PreparationTimeEnum: int
|
|||
case interval3 = 3;
|
||||
case interval4 = 4;
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::interval1->name => '0-30 min',
|
||||
self::interval2->name => '30min - 2h',
|
||||
|
|
@ -20,6 +26,11 @@ enum PreparationTimeEnum: int
|
|||
self::interval4->name => '> 4h',
|
||||
];
|
||||
|
||||
/**
|
||||
* Enum times
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private const TIMES = [
|
||||
self::interval1->name => ['min' => 0, 'max' => 30],
|
||||
self::interval2->name => ['min' => 31, 'max' => 120],
|
||||
|
|
@ -40,7 +51,7 @@ enum PreparationTimeEnum: int
|
|||
/**
|
||||
* Get enum images
|
||||
*
|
||||
* @return array<string>
|
||||
* @return array<string, array<string, int>>
|
||||
*/
|
||||
public static function toTimes(): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@ enum SignsEnum: int
|
|||
case uexpress = 10;
|
||||
case netto = 11;
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::leclerc->name => 'Leclerc',
|
||||
self::auchan->name => 'Auchan',
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ class CertificationController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $certifications */
|
||||
$certifications = Certification::query();
|
||||
|
|
@ -43,9 +43,9 @@ class CertificationController extends Controller
|
|||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.certifications.create');
|
||||
}
|
||||
|
|
@ -54,9 +54,9 @@ class CertificationController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Certifications\StoreCertificationRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreCertificationRequest $request)
|
||||
public function store(StoreCertificationRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$certification = new Certification();
|
||||
|
|
@ -84,9 +84,9 @@ class CertificationController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Certification $certification
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Certification $certification)
|
||||
public function edit(Certification $certification): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.certifications.edit', [
|
||||
'certificationModel' => $certification,
|
||||
|
|
@ -98,10 +98,12 @@ class CertificationController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Certifications\UpdateCertificationRequest $request
|
||||
* @param \App\Models\Certification $certification
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateCertificationRequest $request, Certification $certification)
|
||||
{
|
||||
public function update(
|
||||
UpdateCertificationRequest $request,
|
||||
Certification $certification
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
return DB::transaction(function () use ($request, $certification) {
|
||||
$certification->fill($request->validated());
|
||||
|
||||
|
|
@ -126,9 +128,9 @@ class CertificationController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Certification $certification
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Certification $certification)
|
||||
public function destroy(Certification $certification): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($certification->deleteOrFail()) {
|
||||
return redirect()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
|
|
@ -12,7 +11,7 @@ class DashboardController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): View
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.dashboard');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ class ProductController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $products */
|
||||
$products = Product::query();
|
||||
|
|
@ -50,9 +50,9 @@ class ProductController extends Controller
|
|||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$ranges = Range::all();
|
||||
$certifications = Certification::all();
|
||||
|
|
@ -65,9 +65,9 @@ class ProductController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Products\StoreProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreProductRequest $request)
|
||||
public function store(StoreProductRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$product = new Product();
|
||||
|
|
@ -97,9 +97,9 @@ class ProductController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Product $product)
|
||||
public function edit(Product $product): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$ranges = Range::all();
|
||||
$certifications = Certification::all();
|
||||
|
|
@ -118,9 +118,9 @@ class ProductController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Products\UpdateProductRequest $request
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateProductRequest $request, Product $product)
|
||||
public function update(UpdateProductRequest $request, Product $product): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $product) {
|
||||
$product->fill($request->validated());
|
||||
|
|
@ -148,9 +148,9 @@ class ProductController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Product $product)
|
||||
public function destroy(Product $product): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($product->deleteOrFail()) {
|
||||
return redirect()
|
||||
|
|
|
|||
|
|
@ -6,23 +6,21 @@ use App\Http\Controllers\Controller;
|
|||
use App\Http\Requests\Bo\Ranges\UpdateRangeRequest;
|
||||
use App\Models\Range;
|
||||
use App\Traits\Controllers\UpdateModelStatus;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RangeController extends Controller
|
||||
{
|
||||
use ChangesModelOrder;
|
||||
use UpdateModelStatus;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $ranges */
|
||||
$ranges = Range::query();
|
||||
|
|
@ -48,9 +46,9 @@ class RangeController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Range $range)
|
||||
public function edit(Range $range): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.ranges.edit', [
|
||||
'rangeModel' => $range
|
||||
|
|
@ -62,9 +60,9 @@ class RangeController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Ranges\UpdateRangeRequest $request
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateRangeRequest $request, Range $range)
|
||||
public function update(UpdateRangeRequest $request, Range $range): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $range) {
|
||||
$range->fill($request->validated());
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ class RecipeController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $recipes */
|
||||
$recipes = Recipe::query();
|
||||
|
|
@ -48,9 +48,9 @@ class RecipeController extends Controller
|
|||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$products = Product::all();
|
||||
$recipes = Recipe::all();
|
||||
|
|
@ -65,9 +65,9 @@ class RecipeController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Recipes\StoreRecipeRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreRecipeRequest $request)
|
||||
public function store(StoreRecipeRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$recipe = new Recipe();
|
||||
|
|
@ -98,12 +98,12 @@ class RecipeController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Recipe $recipe
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Recipe $recipe)
|
||||
public function edit(Recipe $recipe): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$products = Product::all();
|
||||
$recipes = Recipe::where('id', '!=', $recipe->id)->get();
|
||||
$recipes = Recipe::query()->where('id', '!=', $recipe->id)->get();
|
||||
|
||||
return view('bo.pages.recipes.edit', [
|
||||
'recipeModel' => $recipe,
|
||||
|
|
@ -117,9 +117,9 @@ class RecipeController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Recipes\UpdateRecipeRequest $request
|
||||
* @param \App\Models\Recipe $recipe
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateRecipeRequest $request, Recipe $recipe)
|
||||
public function update(UpdateRecipeRequest $request, Recipe $recipe): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $recipe) {
|
||||
$recipe->products()->sync($request->product_list);
|
||||
|
|
@ -149,9 +149,9 @@ class RecipeController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Recipe $recipe
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Recipe $recipe)
|
||||
public function destroy(Recipe $recipe): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
DB::table('recipe_recipe')->where($recipe->recipes()->getRelatedPivotKeyName(), $recipe->id)->delete();
|
||||
$recipe->products()->sync([]);
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ class ShopController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $shops */
|
||||
$shops = Shop::query();
|
||||
|
|
@ -46,9 +46,9 @@ class ShopController extends Controller
|
|||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.shops.create');
|
||||
}
|
||||
|
|
@ -57,9 +57,9 @@ class ShopController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Shops\StoreShopRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreShopRequest $request)
|
||||
public function store(StoreShopRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$shop = new Shop();
|
||||
|
|
@ -87,9 +87,9 @@ class ShopController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Shop $shop
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Shop $shop)
|
||||
public function edit(Shop $shop): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.shops.edit', [
|
||||
'shopModel' => $shop,
|
||||
|
|
@ -101,9 +101,9 @@ class ShopController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Shops\UpdateShopRequest $request
|
||||
* @param \App\Models\Shop $shop
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateShopRequest $request, Shop $shop)
|
||||
public function update(UpdateShopRequest $request, Shop $shop): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $shop) {
|
||||
$shop->fill($request->validated());
|
||||
|
|
@ -129,9 +129,9 @@ class ShopController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Shop $shop
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Shop $shop)
|
||||
public function destroy(Shop $shop): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($shop->deleteOrFail()) {
|
||||
return redirect()
|
||||
|
|
|
|||
|
|
@ -111,10 +111,7 @@ class Controller extends BaseController
|
|||
Session::remove("$rName.sort_way");
|
||||
}
|
||||
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
||||
if (
|
||||
!isset($ignore) or
|
||||
(isset($ignore) and !in_array(request()->sort_col, $ignore))
|
||||
) {
|
||||
if (!in_array(request()->sort_col, $ignore)) {
|
||||
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
||||
}
|
||||
} elseif (Schema::hasColumn($table, 'order')) {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@ class HomeController extends Controller
|
|||
public function index()
|
||||
{
|
||||
// Gammes.
|
||||
$ranges = Range::where('status', true)
|
||||
$ranges = Range::query()->where('status', true)
|
||||
->get();
|
||||
|
||||
// 3 Recettes.
|
||||
$publishedRecipes = Recipe::where('status', true)
|
||||
$publishedRecipes = Recipe::query()
|
||||
->where('status', true)
|
||||
->inRandomOrder()
|
||||
->take(3)
|
||||
->get();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ProductsController extends Controller
|
|||
public function index()
|
||||
{
|
||||
// Gammes.
|
||||
$ranges = Range::where('status', true)
|
||||
$ranges = Range::query()->where('status', true)
|
||||
->get();
|
||||
|
||||
return view('fo.pages.products.index', compact('ranges'));
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ class RecipesController extends Controller
|
|||
$relatedRecipes = $publishedRecipe->recipes()->where('status', true)->get();
|
||||
|
||||
// 3 Recettes.
|
||||
$publishedRecipes = Recipe::where('status', true)
|
||||
$publishedRecipes = Recipe::query()
|
||||
->where('status', true)
|
||||
->where('id', '!=', $publishedRecipe->id)
|
||||
->take(3)
|
||||
->get();
|
||||
|
|
@ -84,7 +85,6 @@ class RecipesController extends Controller
|
|||
*
|
||||
* @param \App\Models\Recipe $publishedRecipe
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return void
|
||||
*/
|
||||
public function printRecipe(Recipe $publishedRecipe): \Symfony\Component\HttpFoundation\Response
|
||||
{
|
||||
|
|
@ -104,17 +104,17 @@ class RecipesController extends Controller
|
|||
/**
|
||||
* Generate recipe PDF
|
||||
*
|
||||
* @param \App\Models\Recipe $recipe
|
||||
* @param string $title
|
||||
* @param \App\Models\Recipe $recipe
|
||||
* @param string $title
|
||||
* @return \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
*/
|
||||
private function generateRecipePdf(Recipe $recipe, string $title): \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
{
|
||||
$tabRecipe = \json_decode(\json_encode(new RecipeResource($recipe)));
|
||||
/** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */
|
||||
|
||||
$mpdf = app('laravel-mpdf');
|
||||
/** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */
|
||||
$pdf = $mpdf->loadView(
|
||||
$pdf = $mpdf->loadView(
|
||||
'fo.documents.recipe',
|
||||
// * Dirty convert to object.
|
||||
[
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ class ShopController extends Controller
|
|||
/**
|
||||
* Get all shops
|
||||
*
|
||||
* @return json
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
public function index(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
if (request()->wantsJson()) {
|
||||
return response()
|
||||
|
|
@ -28,10 +28,10 @@ class ShopController extends Controller
|
|||
/**
|
||||
* Get the 5 nearest shops with the given coords in the request.
|
||||
*
|
||||
* @param App\Http\Requests\Fo\Shop\GetNearestShopRequest $request
|
||||
* @return json
|
||||
* @param \App\Http\Requests\Fo\Shop\GetNearestShopRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getNearest(GetNearestShopRequest $request)
|
||||
public function getNearest(GetNearestShopRequest $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
if (!$request->wantsJson()) {
|
||||
return abort(404);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class StoreCertificationRequest extends FormRequest
|
|||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'status' => $this->status ? true : false
|
||||
'status' => $this->boolean('status')
|
||||
]);
|
||||
$this->mergePicture('sticker');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ChangeOrderRequest extends FormRequest
|
|||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'direction' => $this->action === 'up' ? true : false
|
||||
'direction' => $this->direction === 'up' ? true : false
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,6 @@ class ChangeOrderRequest extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
'action' => 'required|string|in:up,down',
|
||||
'direction' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ class StoreProductRequest extends FormRequest
|
|||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'status' => $this->status ? true : false,
|
||||
'nutritional_values' => $this->nutritional_values ?? [],
|
||||
'status' => $this->boolean('status'),
|
||||
'nutritional_values' => $this->input('nutritional_values') ?? [],
|
||||
'certification_list' => \collect($this->certifications)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'recipe_list' => \collect($this->recipes)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'description' => (string)Str::of($this->post('description'))
|
||||
'description' => (string)Str::of($this->input('description'))
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('sticker');
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ class UpdateRangeRequest extends FormRequest
|
|||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->name)),
|
||||
'status' => $this->status ? true : false
|
||||
'slug' => Str::slug(strip_tags($this->input('name'))),
|
||||
'status' => $this->boolean('status')
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('banner');
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ class StoreRecipeRequest extends FormRequest
|
|||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->title)),
|
||||
'status' => $this->status ? true : false,
|
||||
'ingredients' => $this->ingredients ?? [],
|
||||
'products' => $this->products ?? [],
|
||||
'recipes' => $this->recipes ?? [],
|
||||
'cooking_time' => $this->cooking_time ?? 0,
|
||||
'slug' => Str::slug(strip_tags($this->input('title'))),
|
||||
'status' => $this->boolean('status'),
|
||||
'ingredients' => $this->input('ingredients') ?? [],
|
||||
'products' => $this->input('products') ?? [],
|
||||
'recipes' => $this->input('recipes') ?? [],
|
||||
'cooking_time' => $this->input('cooking_time') ?? 0,
|
||||
// * For sync relations
|
||||
'product_list' => \collect($this->products)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
|||
$rules = array_merge($rules, [
|
||||
"data.$iptName.value" => [
|
||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
}
|
||||
],
|
||||
$this->compileValidate(
|
||||
|
|
|
|||
|
|
@ -45,9 +45,12 @@ class RecipeResource extends JsonResource
|
|||
*
|
||||
* @param \Illuminate\Http\Request|null $request
|
||||
* @return array
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray(?Request $request = null): array
|
||||
{
|
||||
// phpcs:enable
|
||||
return array_intersect_key(
|
||||
[
|
||||
'id' => $this->recipe->id,
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class ExceptionsHelper
|
|||
$traceStr .= self::handleArgs($stack);
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
} elseif (isset($stack['function'])) {
|
||||
} else {
|
||||
$traceStr .= "{$stack['function']}(";
|
||||
if (isset($stack['args'])) {
|
||||
$traceStr .= self::handleArgs($stack);
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class FileStorageHelper
|
|||
);
|
||||
|
||||
return str_replace('/private/', '', $newPath);
|
||||
}//end if
|
||||
} //end if
|
||||
if (\is_object($file) and $file instanceof \SplFileInfo) {
|
||||
/** @var \SplFileInfo $file */
|
||||
$filename = $filename ?: $file->getBaseName();
|
||||
|
|
@ -309,7 +309,6 @@ class FileStorageHelper
|
|||
$private ? 'app/private/modelfiles' : 'app/public/modelfiles',
|
||||
$tableName,
|
||||
$filename,
|
||||
$private
|
||||
);
|
||||
$filename = self::getFileUniqueName($folderPath, $filename);
|
||||
return "{$folderPath}/{$filename}";
|
||||
|
|
@ -404,7 +403,7 @@ class FileStorageHelper
|
|||
$filename = Str::of($filename)->ltrim('.-');
|
||||
// * Optional beautification
|
||||
if ($beautify) {
|
||||
$filename = static::beautifyFilename($filename);
|
||||
$filename = self::beautifyFilename($filename);
|
||||
}
|
||||
// * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||
/** @var string */
|
||||
|
|
|
|||
|
|
@ -170,11 +170,10 @@ class ToolboxHelper
|
|||
$url = $match;
|
||||
try {
|
||||
$request = Request::create($url);
|
||||
// If a route is match then it do not throws exception.
|
||||
if (
|
||||
\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST) &&
|
||||
$routes->match($request)
|
||||
) {
|
||||
// Assert route matches existing routes.
|
||||
$routes->match($request);
|
||||
// ? Is url internal ?
|
||||
if (\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST)) {
|
||||
// Removes the matched url.
|
||||
throw ValidationException::withMessages([
|
||||
$field => trans(
|
||||
|
|
@ -200,14 +199,14 @@ class ToolboxHelper
|
|||
* @param array|string $replace
|
||||
* @param array|string $subject
|
||||
* @param integer $count
|
||||
* @return array|string
|
||||
* @return array|string|false
|
||||
*/
|
||||
public static function mbReplace(
|
||||
array|string $search,
|
||||
array|string $replace,
|
||||
array|string $subject,
|
||||
int &$count = 0
|
||||
): array|string {
|
||||
): array|string|false {
|
||||
if (!is_array($search) && is_array($replace)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -284,9 +283,12 @@ class ToolboxHelper
|
|||
public static function getOriginal(Model $model, string $attribute): mixed
|
||||
{
|
||||
if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model))) {
|
||||
// @phpstan-ignore-next-line
|
||||
return $model->getTranslation(
|
||||
$attribute,
|
||||
// @phpstan-ignore-next-line
|
||||
$model->getLocale(),
|
||||
// @phpstan-ignore-next-line
|
||||
$model->useFallbackLocale()
|
||||
);
|
||||
}
|
||||
|
|
@ -310,7 +312,7 @@ class ToolboxHelper
|
|||
): Builder {
|
||||
$currentLocale = app()->currentLocale();
|
||||
$locales = collect(config('app.locales'))
|
||||
->mapWithKeys(fn (string $locale) => [$locale => $locale]);
|
||||
->mapWithKeys(fn (string $locale) => [$locale => $locale]);
|
||||
if (!$locales->has($defaultLocale)) {
|
||||
// * Remove default locale.
|
||||
$locales->pull($defaultLocale);
|
||||
|
|
@ -356,55 +358,55 @@ class ToolboxHelper
|
|||
/**
|
||||
* Convert deeply an object to array
|
||||
*
|
||||
* @param array|object $input
|
||||
* @param mixed $input
|
||||
* @return array
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function objectToArray($input): array
|
||||
public static function objectToArray(mixed $input): array
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (is_object($input) or is_array($input)) {
|
||||
$ret = (array)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::objectToArray($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
} else {
|
||||
if (!(is_object($input) or is_array($input))) {
|
||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||
}
|
||||
$ret = (array)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::objectToArray($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert deeply an array to object
|
||||
*
|
||||
* @param array|object $input
|
||||
* @param mixed $input
|
||||
* @return object
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function arrayToObject($input): object
|
||||
public static function arrayToObject(mixed $input): object
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (is_object($input) or is_array($input)) {
|
||||
$ret = (object)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::arrayToObject($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
} else {
|
||||
if (!(is_object($input) or is_array($input))) {
|
||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||
}
|
||||
$ret = (object)$input;
|
||||
foreach ($ret as &$item) {
|
||||
// Recursively process EACH element only if not scalar.
|
||||
$item = (is_object($item) or is_array($item)) ?
|
||||
self::arrayToObject($item) : $item;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate picture
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
* @param callback $fail
|
||||
* @param callable $fail
|
||||
* @param object $sizes
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -427,7 +429,7 @@ class ToolboxHelper
|
|||
'attribute' => $attribute
|
||||
]));
|
||||
}
|
||||
if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) {
|
||||
if (!($dimensions = \getimagesize($fileFullPath))) {
|
||||
$fail(trans(':attribute impossible de valider les dimensions', [
|
||||
'attribute' => $attribute
|
||||
]));
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Certification extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -38,7 +38,7 @@ class Certification extends Model
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'status' => 'bool'
|
||||
|
|
@ -61,7 +61,7 @@ class Certification extends Model
|
|||
$model->sticker = FileStorageHelper::storeFile($model, $model->sticker, true);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
$model->sticker = FileStorageHelper::removeOldFile($model, 'sticker');
|
||||
FileStorageHelper::removeOldFile($model, 'sticker');
|
||||
self::flashStatus($model, true);
|
||||
});
|
||||
static::deleting(function (self $model) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Product extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -47,7 +47,7 @@ class Product extends Model
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
/** @var array<ingredient> */
|
||||
|
|
@ -67,7 +67,7 @@ class Product extends Model
|
|||
// * EVENT CLOSURES.
|
||||
static::creating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
static::assertFieldIsUnique('name', $model->name);
|
||||
self::assertFieldIsUnique('name', $model->name);
|
||||
ToolboxHelper::assertNoInternalBoUrls('description', $model->description);
|
||||
ToolboxHelper::assertNoInternalBoUrls('preparation', $model->preparation ?? '');
|
||||
ToolboxHelper::assertNoInternalBoUrls('ingredients', $model->ingredients);
|
||||
|
|
@ -82,7 +82,7 @@ class Product extends Model
|
|||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
static::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
ToolboxHelper::assertNoInternalBoUrls('description', $model->description);
|
||||
ToolboxHelper::assertNoInternalBoUrls('preparation', $model->preparation ?? '');
|
||||
ToolboxHelper::assertNoInternalBoUrls('ingredients', $model->ingredients);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Range extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -80,8 +80,8 @@ class Range extends Model
|
|||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
static::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
static::assertAtLeastOneIsPublished($model);
|
||||
self::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::assertAtLeastOneIsPublished($model);
|
||||
|
||||
// * TRANSFORMATIONS
|
||||
$model->slug = Str::slug($model->name);
|
||||
|
|
@ -90,9 +90,9 @@ class Range extends Model
|
|||
$model->sticker = FileStorageHelper::storeFile($model, $model->sticker, true);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
$model->picture = FileStorageHelper::removeOldFile($model, 'picture');
|
||||
$model->banner = FileStorageHelper::removeOldFile($model, 'banner');
|
||||
$model->banner = FileStorageHelper::removeOldFile($model, 'sticker');
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
FileStorageHelper::removeOldFile($model, 'banner');
|
||||
FileStorageHelper::removeOldFile($model, 'sticker');
|
||||
static::flashStatus($model, true);
|
||||
});
|
||||
static::deleting(function () {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Recipe extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -47,7 +47,7 @@ class Recipe extends Model
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'ingredients' => 'array',
|
||||
|
|
@ -65,14 +65,14 @@ class Recipe extends Model
|
|||
{
|
||||
// * EVENT CLOSURES.
|
||||
static::creating(function (self $model) {
|
||||
static::assertFieldIsUnique('name', $model->name);
|
||||
self::assertFieldIsUnique('name', $model->name);
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::created(function (self $model) {
|
||||
self::flashStatus($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
static::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
|
|
@ -91,10 +91,10 @@ class Recipe extends Model
|
|||
/**
|
||||
* Manage fields on this model event.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(Model $model)
|
||||
private static function manageFields(self $model)
|
||||
{
|
||||
// * ASSERTIONS
|
||||
ToolboxHelper::assertNoInternalBoUrls('description', $model->description);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class Shop extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
@ -29,7 +29,7 @@ class Shop extends Model
|
|||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'signs' => SignsEnum::class,
|
||||
|
|
@ -45,11 +45,11 @@ class Shop extends Model
|
|||
// * EVENT CLOSURES.
|
||||
static::creating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
static::assertFieldIsUnique('name', $model->name);
|
||||
self::assertFieldIsUnique('name', $model->name);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
// * ASSERTIONS
|
||||
static::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
self::assertFieldIsUnique('name', $model->name, $model->id);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
return request()->getClientIp();
|
||||
} else {
|
||||
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
||||
request()->getClientIp();
|
||||
request()->getClientIp();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
// * GAMMES
|
||||
if (Schema::hasTable('ranges')) {
|
||||
// On partage les ranges (gammes produit).
|
||||
$ranges = Range::where('status', true)->get();
|
||||
$ranges = Range::query()->where('status', true)->get();
|
||||
View::share('PublishedRangesGlobal', $ranges);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class TranslationServiceProvider extends ServiceProvider
|
|||
/**
|
||||
* Gather provided langs checking from files
|
||||
*
|
||||
* @return \Illuminate\Support\Collection<string, string>
|
||||
* @return \Illuminate\Support\Collection<int, string>
|
||||
*/
|
||||
private function collectLocalesStrings(): Collection
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,59 +3,56 @@
|
|||
namespace App\Traits\Controllers;
|
||||
|
||||
use App\Http\Requests\Bo\ChangeOrderRequest;
|
||||
use App\Traits\Models\IsCachedAsCollection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait ChangesModelOrder
|
||||
{
|
||||
/**
|
||||
* Change order
|
||||
*
|
||||
* ! requires x64 server + order column as unique integer
|
||||
* Change order.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ChangeOrderRequest $request
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \RuntimeException Si le nom du parametre de la route ne correspond pas au model utilisé.
|
||||
*/
|
||||
public function changeOrder(ChangeOrderRequest $request, Model $model): RedirectResponse
|
||||
public function changeOrder(ChangeOrderRequest $request, Model $model): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $model) {
|
||||
$params = collect(request()->route()->parameterNames);
|
||||
$className = Str::ucfirst(Str::lower($params->get($params->count() - 2)));
|
||||
$className = "\\App\\Models\\$className";
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new \RuntimeException("The $className class doesn't exist.");
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Model|null */
|
||||
$model = $className::query()->where($model->getRouteKeyName(), $model->getRouteKey())->first();
|
||||
|
||||
if (!$model) {
|
||||
return back()->with('error', trans('crud.messages.order_not_changed'));
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($request, $className, $model) {
|
||||
/** @var \Illuminate\Database\Eloquent\Model|null */
|
||||
$tmp = (\get_class($model))::where('order', $request->direction ? '<' : '>', $model->order)
|
||||
$tmp = $className::query()->where('order', $request->direction ? '<' : '>', $model->getOriginal('order'))
|
||||
->orderBy('order', $request->direction ? 'DESC' : 'ASC')->first();
|
||||
|
||||
if (!$tmp) {
|
||||
return back()->with('bo.error', trans('L\'ordre n\'a pas pu être modifié'));
|
||||
return back()->with('error', trans('crud.messages.order_not_changed'));
|
||||
}
|
||||
$oldOrder = $model->order;
|
||||
$newOrder = $tmp->order;
|
||||
|
||||
// * Silent update timestamps.
|
||||
$tmp->timestamps = false;
|
||||
$model->timestamps = false;
|
||||
$newOrder = $tmp->getOriginal('order');
|
||||
// Didn't use ->update() because it didn't work with Models which use MiniCrudModel.
|
||||
$tmp->fill(['order' => $model->getOriginal('order')]);
|
||||
$tmp->save();
|
||||
$model->fill(['order' => $newOrder]);
|
||||
$model->save();
|
||||
|
||||
$saveOk = false;
|
||||
Session::flash('success', trans('crud.messages.order_changed'));
|
||||
|
||||
// ! Fake value to prevent unique SQL key to trigger.
|
||||
$tmp->order = 4294967295;
|
||||
$saveOk = $tmp->saveQuietly();
|
||||
$model->order = $newOrder;
|
||||
$saveOk = $model->saveQuietly() & $saveOk;
|
||||
$tmp->order = $oldOrder;
|
||||
$saveOk = $tmp->saveQuietly() & $saveOk;
|
||||
if (\in_array(IsCachedAsCollection::class, class_uses_recursive(\get_class($model)))) {
|
||||
$model::removeCached();
|
||||
}
|
||||
if (!$saveOk) {
|
||||
throw ValidationException::withMessages([
|
||||
'error' => \trans('L\'ordre n\'a pas pu être modifié')
|
||||
]);
|
||||
}
|
||||
Session::flash('bo.success', trans('L\'ordre a été modifié'));
|
||||
return back();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,19 +12,14 @@ use Illuminate\Database\Eloquent\Model;
|
|||
trait UpdateModelStatus
|
||||
{
|
||||
/**
|
||||
* Change model published
|
||||
* Change model published.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changePublished(Model $model)
|
||||
{
|
||||
$model->status = !$model->status;
|
||||
$model->saveOrFail();
|
||||
|
||||
if (!$model->saveOrFail()) {
|
||||
return redirect()->back()->with('error', __('The status could not be changed'));
|
||||
}
|
||||
return redirect()->back()->with('success', __('The status has been changed'));
|
||||
$model->update(['published' => !$model->getOriginal('published')]);
|
||||
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ trait BaseEnum
|
|||
/**
|
||||
* Fetch enum using value
|
||||
*
|
||||
* @param \App\Traits\Enums\BaseEnum|integer|string $value
|
||||
* @return \App\Traits\Enums\BaseEnum|null
|
||||
* @param self|integer|string $value
|
||||
* @return self|null
|
||||
*/
|
||||
public static function make(self|int|string $value): self|null
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ use Illuminate\Support\Facades\Cache;
|
|||
/**
|
||||
* ! Use this only on limited elements, (not on tags, or products, or posts for ex.)
|
||||
*
|
||||
* @property private static array $cacheConditions Eloquent condition to cache elements (to be used in where statement).
|
||||
* @property array<string,string|integer|float|boolean> $cacheConditions
|
||||
* Eloquent condition to cache elements (to be used in where statement).
|
||||
*/
|
||||
trait IsCachedAsCollection
|
||||
{
|
||||
|
|
@ -52,7 +53,7 @@ trait IsCachedAsCollection
|
|||
{
|
||||
$conditions = [];
|
||||
if (property_exists(get_called_class(), 'cacheConditions')) {
|
||||
$conditions = collect(static::${'cacheConditions'})->all();
|
||||
$conditions = collect(get_called_class()::${'cacheConditions'})->all();
|
||||
}
|
||||
Cache::put(static::getCacheKeyName(), static::queryCached(static::query())
|
||||
->where($conditions)->get()
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ trait HasPicture
|
|||
$name => [
|
||||
!$nullable ? 'required' : 'nullable',
|
||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
}
|
||||
]
|
||||
];
|
||||
|
|
@ -101,7 +101,7 @@ trait HasPicture
|
|||
"{$name}Validate.*" => [
|
||||
'required',
|
||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||
return $this->validatePicture($attribute, $value, $fail, $sizes);
|
||||
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||
}
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
"fakerphp/faker": "^1.9.1",
|
||||
"kitloong/laravel-migrations-generator": "^6.8",
|
||||
"krlove/eloquent-model-generator": "dev-l10-compatibility",
|
||||
"larastan/larastan": "^2.6",
|
||||
"laravel-lang/lang": "10.0",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
|
|
|
|||
249
composer.lock
generated
249
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3dbef383b0ae1a746367c2068cccb9ca",
|
||||
"content-hash": "5337e7d480ce4959f67c40a20691a553",
|
||||
"packages": [
|
||||
{
|
||||
"name": "axlon/laravel-postal-code-validation",
|
||||
|
|
@ -9359,6 +9359,108 @@
|
|||
},
|
||||
"time": "2023-01-30T20:15:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "larastan/larastan",
|
||||
"version": "v2.9.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/larastan/larastan.git",
|
||||
"reference": "340badd89b0eb5bddbc503a4829c08cf9a2819d7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/larastan/larastan/zipball/340badd89b0eb5bddbc503a4829c08cf9a2819d7",
|
||||
"reference": "340badd89b0eb5bddbc503a4829c08cf9a2819d7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"illuminate/console": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/container": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/contracts": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/database": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/http": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/pipeline": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"illuminate/support": "^9.52.16 || ^10.28.0 || ^11.0",
|
||||
"php": "^8.0.2",
|
||||
"phpmyadmin/sql-parser": "^5.9.0",
|
||||
"phpstan/phpstan": "^1.11.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^12.0",
|
||||
"nikic/php-parser": "^4.19.1",
|
||||
"orchestra/canvas": "^7.11.1 || ^8.11.0 || ^9.0.2",
|
||||
"orchestra/testbench": "^7.33.0 || ^8.13.0 || ^9.0.3",
|
||||
"phpunit/phpunit": "^9.6.13 || ^10.5.16"
|
||||
},
|
||||
"suggest": {
|
||||
"orchestra/testbench": "Using Larastan for analysing a package needs Testbench"
|
||||
},
|
||||
"type": "phpstan-extension",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
},
|
||||
"phpstan": {
|
||||
"includes": [
|
||||
"extension.neon"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Larastan\\Larastan\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Can Vural",
|
||||
"email": "can9119@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nuno Maduro",
|
||||
"email": "enunomaduro@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel",
|
||||
"keywords": [
|
||||
"PHPStan",
|
||||
"code analyse",
|
||||
"code analysis",
|
||||
"larastan",
|
||||
"laravel",
|
||||
"package",
|
||||
"php",
|
||||
"static analysis"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/larastan/larastan/issues",
|
||||
"source": "https://github.com/larastan/larastan/tree/v2.9.8"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.paypal.com/paypalme/enunomaduro",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/canvural",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nunomaduro",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/nunomaduro",
|
||||
"type": "patreon"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-06T17:46:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-lang/lang",
|
||||
"version": "10.0.0",
|
||||
|
|
@ -9906,6 +10008,93 @@
|
|||
},
|
||||
"time": "2022-02-21T01:04:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpmyadmin/sql-parser",
|
||||
"version": "5.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpmyadmin/sql-parser.git",
|
||||
"reference": "91d980ab76c3f152481e367f62b921adc38af451"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/91d980ab76c3f152481e367f62b921adc38af451",
|
||||
"reference": "91d980ab76c3f152481e367f62b921adc38af451",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2 || ^8.0",
|
||||
"symfony/polyfill-mbstring": "^1.3",
|
||||
"symfony/polyfill-php80": "^1.16"
|
||||
},
|
||||
"conflict": {
|
||||
"phpmyadmin/motranslator": "<3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpbench/phpbench": "^1.1",
|
||||
"phpmyadmin/coding-standard": "^3.0",
|
||||
"phpmyadmin/motranslator": "^4.0 || ^5.0",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan": "^1.9.12",
|
||||
"phpstan/phpstan-phpunit": "^1.3.3",
|
||||
"phpunit/phpunit": "^8.5 || ^9.6",
|
||||
"psalm/plugin-phpunit": "^0.16.1",
|
||||
"vimeo/psalm": "^4.11",
|
||||
"zumba/json-serializer": "~3.0.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance",
|
||||
"phpmyadmin/motranslator": "Translate messages to your favorite locale"
|
||||
},
|
||||
"bin": [
|
||||
"bin/highlight-query",
|
||||
"bin/lint-query",
|
||||
"bin/sql-parser",
|
||||
"bin/tokenize-query"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpMyAdmin\\SqlParser\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "The phpMyAdmin Team",
|
||||
"email": "developers@phpmyadmin.net",
|
||||
"homepage": "https://www.phpmyadmin.net/team/"
|
||||
}
|
||||
],
|
||||
"description": "A validating SQL lexer and parser with a focus on MySQL dialect.",
|
||||
"homepage": "https://github.com/phpmyadmin/sql-parser",
|
||||
"keywords": [
|
||||
"analysis",
|
||||
"lexer",
|
||||
"parser",
|
||||
"query linter",
|
||||
"sql",
|
||||
"sql lexer",
|
||||
"sql linter",
|
||||
"sql parser",
|
||||
"sql syntax highlighter",
|
||||
"sql tokenizer"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpmyadmin/sql-parser/issues",
|
||||
"source": "https://github.com/phpmyadmin/sql-parser"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.phpmyadmin.net/donate/",
|
||||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2024-08-29T20:56:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpdoc-parser",
|
||||
"version": "1.30.0",
|
||||
|
|
@ -9953,6 +10142,64 @@
|
|||
},
|
||||
"time": "2024-08-29T09:54:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
"version": "1.12.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpstan.git",
|
||||
"reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/0ca1c7bb55fca8fe6448f16fff0f311ccec960a1",
|
||||
"reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2|^8.0"
|
||||
},
|
||||
"conflict": {
|
||||
"phpstan/phpstan-shim": "*"
|
||||
},
|
||||
"bin": [
|
||||
"phpstan",
|
||||
"phpstan.phar"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "PHPStan - PHP Static Analysis Tool",
|
||||
"keywords": [
|
||||
"dev",
|
||||
"static analysis"
|
||||
],
|
||||
"support": {
|
||||
"docs": "https://phpstan.org/user-guide/getting-started",
|
||||
"forum": "https://github.com/phpstan/phpstan/discussions",
|
||||
"issues": "https://github.com/phpstan/phpstan/issues",
|
||||
"security": "https://github.com/phpstan/phpstan/security/policy",
|
||||
"source": "https://github.com/phpstan/phpstan-src"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/ondrejmirtes",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/phpstan",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-05T16:09:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
"version": "10.1.16",
|
||||
|
|
|
|||
10
phpstan.neon
Normal file
10
phpstan.neon
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
includes:
|
||||
- vendor/larastan/larastan/extension.neon
|
||||
|
||||
parameters:
|
||||
|
||||
paths:
|
||||
- app/
|
||||
|
||||
# Level 9 is the highest level
|
||||
level: 5
|
||||
Loading…
Add table
Reference in a new issue