chore: phpcs + phpstan
This commit is contained in:
parent
b61fd77a6d
commit
0d09b01a2d
14 changed files with 58 additions and 43 deletions
|
|
@ -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<string,array<int,\App\Models\Brand>|array<int,\App\Models\Font>> $data
|
||||
* @return array<'settings'|'brands'|'fonts'|'ranges'|'products',string|array<string,string>>
|
||||
* @return array{
|
||||
* settings: string,
|
||||
* brands: array<int, string>,
|
||||
* fonts: array<int, string>,
|
||||
* ranges: array<int, string>,
|
||||
* products: array<int, string>
|
||||
* }
|
||||
*/
|
||||
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,string>|string> $filesToZip
|
||||
* @phpcs:ignore
|
||||
* @param array{settings: string,brands: array<int, string>,fonts: array<string>,ranges: array<int, string>,products: array<int, string>} $filesToZip
|
||||
* @return array<string>
|
||||
* @throws \RuntimeException If temp folder caanot be cleared in order to work.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class ActivityLog extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'is_anonymous',
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Brand extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Font extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'font_name',
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Product extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Range extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class Settings extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class StaticPage extends Model
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'seo_title',
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class User extends Authenticatable
|
|||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'first_name',
|
||||
|
|
@ -44,7 +44,7 @@ class User extends Authenticatable
|
|||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var list<string>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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#'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue