diff --git a/app/Jobs/ShowroomExport.php b/app/Jobs/ShowroomExport.php index 92cf85e..0dec976 100644 --- a/app/Jobs/ShowroomExport.php +++ b/app/Jobs/ShowroomExport.php @@ -81,8 +81,7 @@ class ShowroomExport implements ShouldQueue, ShouldBeUnique $data = $this->getData(); $associatedFileList = $this->getAssociatedFileList($data); $fileContent = $this->getFile($data); - $schemaContent = SchemaValidator::getSchemaContents('app.schema.json'); - $this->assertSchemaIsValid($schemaContent, json_encode($fileContent)); + $this->assertSchemaIsValid('app.schema.json', json_encode($fileContent)); $filesToZip = $this->preparePicturesForZip($associatedFileList); $dataFilePath = "{$this->tempFolder}/data.json"; @@ -152,21 +151,27 @@ class ShowroomExport implements ShouldQueue, ShouldBeUnique /** * Assert schema is valid * - * @param array $schema + * @param string $schemaFileName * @param string $fileContent * @return void * @throws \Carsdotcom\JsonSchemaValidation\Exceptions\JsonSchemaValidationException In case of failure. */ - protected function assertSchemaIsValid(array $schema, string $fileContent): void + protected function assertSchemaIsValid(string $schemaFileName, string $fileContent): void { - SchemaValidator::validateEncodedStringOrThrow($fileContent, 'app.schema.json'); + SchemaValidator::validateEncodedStringOrThrow($fileContent, $schemaFileName); } /** * Get associated files list to export * * @param array|array> $data - * @return array<'settings'|'brands'|'fonts'|'ranges'|'products',string|array> + * @return array{ + * settings: string, + * brands: array, + * fonts: array, + * ranges: array, + * products: array + * } */ protected function getAssociatedFileList(array $data): array { @@ -231,14 +236,19 @@ class ShowroomExport implements ShouldQueue, ShouldBeUnique }), 'items' => Arr::map(Arr::get($data, 'brands'), function (Brand $brand) { $this->setPictureExportPath($brand); - $brand->setRelation('ranges', $brand->ranges->map(function (Range $range) { - $this->setPictureExportPath($range); - $range->setRelation('products', $range->products->map(function (Product $product) { - $this->setPictureExportPath($product); - return $product; - })); - return $range; - })); + $brand->setRelation( + 'ranges', + // @phpstan-ignore argument.type + $brand->ranges->map(function (Range $range) { + $this->setPictureExportPath($range); + // @phpstan-ignore argument.type + $range->setRelation('products', $range->products->map(function (Product $product) { + $this->setPictureExportPath($product); + return $product; + })); + return $range; + }) + ); return $brand; }) ]; @@ -249,7 +259,8 @@ class ShowroomExport implements ShouldQueue, ShouldBeUnique /** * Get the files that should be zipped * - * @param array<'brands'|'fonts'|'products'|'ranges'|'settings',array|string> $filesToZip + * @phpcs:ignore + * @param array{settings: string,brands: array,fonts: array,ranges: array,products: array} $filesToZip * @return array * @throws \RuntimeException If temp folder caanot be cleared in order to work. */ diff --git a/app/Lib/Helpers/ExceptionsHelper.php b/app/Lib/Helpers/ExceptionsHelper.php index 30deb54..e867b9e 100644 --- a/app/Lib/Helpers/ExceptionsHelper.php +++ b/app/Lib/Helpers/ExceptionsHelper.php @@ -80,7 +80,7 @@ class ExceptionsHelper foreach ($params as &$param) { $type = \strtolower(\gettype($param)); if (\is_string($param)) { - $type = \explode(' ', \trim(strtolower($param)))[0] ?? null; + $type = \explode(' ', \trim(strtolower($param)))[0]; } switch (true) { case $type === 'lambda': diff --git a/app/Lib/Helpers/FileStorageHelper.php b/app/Lib/Helpers/FileStorageHelper.php index 1254ec3..9c5a918 100644 --- a/app/Lib/Helpers/FileStorageHelper.php +++ b/app/Lib/Helpers/FileStorageHelper.php @@ -103,7 +103,7 @@ class FileStorageHelper */ public static function storeFile( Model $model, - $file, + \Illuminate\Http\UploadedFile|\SplFileInfo|string $file, bool $slugify = false, string $filename = null, bool $private = false @@ -133,7 +133,7 @@ class FileStorageHelper return str_replace('/private/', '', $newPath); } //end if - if (\is_object($file) and $file instanceof \SplFileInfo) { + if ($file instanceof \SplFileInfo) { /** @var \SplFileInfo $file */ $filename = $filename ?: $file->getBaseName(); $filename = $slugify ? self::slugifyFileName($filename) : $filename; diff --git a/app/Lib/Helpers/ToolboxHelper.php b/app/Lib/Helpers/ToolboxHelper.php index d7cb8c7..443f806 100644 --- a/app/Lib/Helpers/ToolboxHelper.php +++ b/app/Lib/Helpers/ToolboxHelper.php @@ -322,7 +322,7 @@ class ToolboxHelper } } else { $parts = mb_split(preg_quote($search), $subject); - $count = count($parts) - 1; + $count = \intval(count($parts) - 1); $subject = implode($replace, $parts); } //end if return $subject; diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index 0f333d0..aee0869 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -32,7 +32,7 @@ class ActivityLog extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'is_anonymous', diff --git a/app/Models/Brand.php b/app/Models/Brand.php index e6b361b..bd421e9 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -32,7 +32,7 @@ class Brand extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', @@ -99,7 +99,7 @@ class Brand extends Model /** * Get all of the ranges for the Brand * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\Range, $this> */ public function ranges(): HasMany { diff --git a/app/Models/Font.php b/app/Models/Font.php index 6797098..5c84f75 100644 --- a/app/Models/Font.php +++ b/app/Models/Font.php @@ -26,7 +26,7 @@ class Font extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'font_name', diff --git a/app/Models/Product.php b/app/Models/Product.php index 412bae8..f95f95f 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -30,7 +30,7 @@ class Product extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', diff --git a/app/Models/Range.php b/app/Models/Range.php index 36242d0..cbe33e3 100644 --- a/app/Models/Range.php +++ b/app/Models/Range.php @@ -36,7 +36,7 @@ class Range extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'name', @@ -129,7 +129,7 @@ class Range extends Model /** * Get all of the products for the Brand * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\Product, $this> */ public function products(): HasMany { diff --git a/app/Models/Settings.php b/app/Models/Settings.php index dd60954..30284c4 100644 --- a/app/Models/Settings.php +++ b/app/Models/Settings.php @@ -27,7 +27,7 @@ class Settings extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'sub_title', @@ -58,7 +58,7 @@ class Settings extends Model // * TRANSFORMATIONS $model->logo = FileStorageHelper::storeFile($model, $model->logo, true); }); - static::created(fn () => self::removeCached()); + static::created(fn() => self::removeCached()); static::updating(function (self $model) { // * TRANSFORMATIONS $model->logo = FileStorageHelper::storeFile($model, $model->logo, true); diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 204758e..b9b12a3 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -27,7 +27,7 @@ class StaticPage extends Model /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'seo_title', diff --git a/app/Models/User.php b/app/Models/User.php index 6195ef8..9228fec 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -30,7 +30,7 @@ class User extends Authenticatable /** * The attributes that are mass assignable. * - * @var array + * @var list */ protected $fillable = [ 'first_name', @@ -44,7 +44,7 @@ class User extends Authenticatable /** * The attributes that should be hidden for serialization. * - * @var array + * @var list */ protected $hidden = [ 'remember_token' @@ -91,16 +91,4 @@ class User extends Authenticatable ); }); } - - // * RELATIONS - - /** - * Activities logs One-to-many relationship. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function activityLogs(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(ActivityLog::class); - } } diff --git a/app/Traits/Models/ActivityLog.php b/app/Traits/Models/ActivityLog.php index 67973e1..b956ca7 100644 --- a/app/Traits/Models/ActivityLog.php +++ b/app/Traits/Models/ActivityLog.php @@ -3,6 +3,7 @@ namespace App\Traits\Models; use App\Observers\ModelObserver; +use App\Models\ActivityLog as ActivityLogModel; /** * If there is a static function in a trait (named boot[TraitName]), @@ -20,4 +21,16 @@ trait ActivityLog { static::observe(ModelObserver::class); } + + // * RELATIONS + + /** + * Activities logs HasMany relationship. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function activityLogs(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ActivityLogModel::class, 'model_id')->with('user'); + } } diff --git a/phpstan.neon b/phpstan.neon index df74d87..aa2a9bb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,6 @@ parameters: # Level 9 is the highest level level: 5 + + ignoreErrors: + - '#Trait App\\Traits\\Models\\MiniCrudModel is used zero times and is not analysed#'