Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
tomschlick authored and StyleCIBot committed Apr 16, 2020
1 parent 460d099 commit a8da728
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 39 deletions.
22 changes: 11 additions & 11 deletions src/Console/Commands/MakeModelAuditLogTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle()
*
* @return string
*/
public function generateAuditTableName($subject_model, array $config) : string
public function generateAuditTableName($subject_model, array $config): string
{
return $subject_model->getTable() . $config['table_suffix'];
}
Expand All @@ -70,7 +70,7 @@ public function generateAuditTableName($subject_model, array $config) : string
*
* @return string
*/
public function generateAuditModelName($subject_model, array $config) : string
public function generateAuditModelName($subject_model, array $config): string
{
return class_basename($subject_model) . $config['model_suffix'];
}
Expand All @@ -82,7 +82,7 @@ public function generateAuditModelName($subject_model, array $config) : string
*
* @return string
*/
public function getModelNamespace($subject_model) : string
public function getModelNamespace($subject_model): string
{
return (new ReflectionClass($subject_model))->getNamespaceName();
}
Expand All @@ -93,7 +93,7 @@ public function getModelNamespace($subject_model) : string
*
* @throws \ReflectionException
*/
public function createModel($subject_model, array $config) : void
public function createModel($subject_model, array $config): void
{
$modelname = $this->generateAuditModelName($subject_model, $config);

Expand All @@ -114,7 +114,7 @@ public function createModel($subject_model, array $config) : void
* @param Model $subject_model
* @param array $config
*/
public function createMigration($subject_model, array $config) : void
public function createMigration($subject_model, array $config): void
{
$tablename = $this->generateAuditTableName($subject_model, $config);
$fileslug = "create_{$tablename}_table";
Expand All @@ -139,7 +139,7 @@ public function createMigration($subject_model, array $config) : void
*
* @return string
*/
public function generateMigrationFilename(string $fileslug) : string
public function generateMigrationFilename(string $fileslug): string
{
return Str::snake(Str::lower(date('Y_m_d_His') . ' ' . $fileslug . '.php'));
}
Expand All @@ -149,7 +149,7 @@ public function generateMigrationFilename(string $fileslug) : string
*
* @return string
*/
public function generateMigrationClassname(string $fileslug) : string
public function generateMigrationClassname(string $fileslug): string
{
return Str::studly($fileslug);
}
Expand All @@ -160,7 +160,7 @@ public function generateMigrationClassname(string $fileslug) : string
*
* @return string
*/
public function getStubWithReplacements(string $file, array $replacements) : string
public function getStubWithReplacements(string $file, array $replacements): string
{
return str_replace(
array_keys($replacements),
Expand All @@ -175,7 +175,7 @@ public function getStubWithReplacements(string $file, array $replacements) : str
*
* @return string
*/
public function generateMigrationSubjectForeignKeys($subject_model, array $config) : string
public function generateMigrationSubjectForeignKeys($subject_model, array $config): string
{
if (Arr::get($config, 'enable_subject_foreign_keys') === true) {
return '$table->foreign(\'subject_id\')
Expand All @@ -191,7 +191,7 @@ public function generateMigrationSubjectForeignKeys($subject_model, array $confi
*
* @return string
*/
public function generateMigrationUserForeignKeys(array $config) : string
public function generateMigrationUserForeignKeys(array $config): string
{
$user_model = new $config['user_model']();
if (Arr::get($config, 'enable_user_foreign_keys') === true && ! empty($user_model)) {
Expand All @@ -211,7 +211,7 @@ public function generateMigrationUserForeignKeys(array $config) : string
*
* @return string
*/
public function generateMigrationProcessStamps(array $config) : string
public function generateMigrationProcessStamps(array $config): string
{
if (Arr::get($config, 'enable_process_stamps') === true) {
return '$table->processIds();';
Expand Down
22 changes: 11 additions & 11 deletions src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class BaseModel extends Model
* @param int $event_type
* @param Model $model
*/
public function recordChanges(int $event_type, $model) : void
public function recordChanges(int $event_type, $model): void
{
$changes = self::getChangesByType($event_type, $model);

Expand All @@ -38,7 +38,7 @@ public function recordChanges(int $event_type, $model) : void
*
* @return Collection
*/
public function passingChanges(array $changes, $model) : Collection
public function passingChanges(array $changes, $model): Collection
{
return collect($changes)
->except(config('model-auditlog.global_ignored_fields'))
Expand All @@ -57,7 +57,7 @@ public function passingChanges(array $changes, $model) : Collection
* @param int $event_type
* @param Model $model
*/
public function saveChanges(Collection $passing_changes, int $event_type, $model) : void
public function saveChanges(Collection $passing_changes, int $event_type, $model): void
{
$passing_changes
->each(function ($change, $key) use ($event_type, $model) {
Expand All @@ -74,7 +74,7 @@ public function saveChanges(Collection $passing_changes, int $event_type, $model
}

$log->setAttribute('field_name', $key);
if($event_type !== EventType::DELETED and $model->getRawOriginal($key) !== $change) {
if ($event_type !== EventType::DELETED and $model->getRawOriginal($key) !== $change) {
$log->setAttribute('field_value_old', $model->getRawOriginal($key));
}
$log->setAttribute('field_value_new', $change);
Expand All @@ -90,7 +90,7 @@ public function saveChanges(Collection $passing_changes, int $event_type, $model
* @param string $relationName
* @param array $pivotIds
*/
public function recordPivotChanges(int $event_type, $model, string $relationName, array $pivotIds) : void
public function recordPivotChanges(int $event_type, $model, string $relationName, array $pivotIds): void
{
$pivot = $model->{$relationName}()->getPivotClass();

Expand All @@ -112,7 +112,7 @@ public function recordPivotChanges(int $event_type, $model, string $relationName
*
* @return array
*/
public function getPivotChanges($pivot, $model, array $pivotIds) : array
public function getPivotChanges($pivot, $model, array $pivotIds): array
{
$columns = (new $pivot())->getAuditLogForeignKeyColumns();
$key = in_array($model->getForeignKey(), $columns) ? $model->getForeignKey() : $model->getKeyName();
Expand All @@ -136,7 +136,7 @@ public function getPivotChanges($pivot, $model, array $pivotIds) : array
* @param int $event_type
* @param $pivot
*/
public function savePivotChanges(Collection $passing_changes, int $event_type, $pivot) : void
public function savePivotChanges(Collection $passing_changes, int $event_type, $pivot): void
{
$passing_changes
->each(function ($change, $key) use ($event_type, $passing_changes, $pivot) {
Expand All @@ -162,12 +162,12 @@ public function savePivotChanges(Collection $passing_changes, int $event_type, $
}

/**
* @param int $event_type
* @param int $event_type
* @param Model $model
*
* @return array
*/
public static function getChangesByType(int $event_type, $model) : array
public static function getChangesByType(int $event_type, $model): array
{
switch ($event_type) {
case EventType::CREATED:
Expand Down Expand Up @@ -196,15 +196,15 @@ public static function getChangesByType(int $event_type, $model) : array
/**
* @return BelongsTo|null
*/
public function subject() : ?BelongsTo
public function subject(): ?BelongsTo
{
return $this->belongsTo($this->getSubjectModelClassname(), 'subject_id');
}

/**
* @return string
*/
public function getSubjectModelClassname() : string
public function getSubjectModelClassname(): string
{
return str_replace(config('model-auditlog.model_suffix'), '', get_class($this));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Observers/AuditLogObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AuditLogObserver
/**
* @param Model $model
*/
public function created($model) : void
public function created($model): void
{
$this->getAuditLogModel($model)
->recordChanges(EventType::CREATED, $model);
Expand All @@ -19,7 +19,7 @@ public function created($model) : void
/**
* @param Model $model
*/
public function updated($model) : void
public function updated($model): void
{
$this->getAuditLogModel($model)
->recordChanges(EventType::UPDATED, $model);
Expand All @@ -28,7 +28,7 @@ public function updated($model) : void
/**
* @param Model $model
*/
public function deleted($model) : void
public function deleted($model): void
{
/*
* If a model is hard deleting, either via a force delete or that model does not implement
Expand All @@ -45,7 +45,7 @@ public function deleted($model) : void
/**
* @param Model $model
*/
public function restored($model) : void
public function restored($model): void
{
$this->getAuditLogModel($model)
->recordChanges(EventType::RESTORED, $model);
Expand Down
16 changes: 8 additions & 8 deletions src/Traits/AuditLoggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ trait AuditLoggable
/**
* Boots the trait and sets the observer.
*/
public static function bootAuditLoggable() : void
public static function bootAuditLoggable(): void
{
static::observe(AuditLogObserver::class);
}

/**
* @return string
*/
public function getAuditLogModelName() : string
public function getAuditLogModelName(): string
{
return get_class($this) . config('model-auditlog.model_suffix');
}
Expand All @@ -38,7 +38,7 @@ public function getAuditLogModelInstance()
/**
* @return string
*/
public function getAuditLogTableName() : string
public function getAuditLogTableName(): string
{
return $this->getTable() . config('model-auditlog.table_suffix');
}
Expand All @@ -48,7 +48,7 @@ public function getAuditLogTableName() : string
*
* @return array
*/
public function getAuditLogIgnoredFields() : array
public function getAuditLogIgnoredFields(): array
{
return [];
}
Expand All @@ -58,7 +58,7 @@ public function getAuditLogIgnoredFields() : array
*
* @return array
*/
public function getAuditLogForeignKeyColumns() : array
public function getAuditLogForeignKeyColumns(): array
{
return ['subject_id' => $this->getKeyName()];
}
Expand All @@ -68,7 +68,7 @@ public function getAuditLogForeignKeyColumns() : array
*
* @return array
*/
public function getAuditLogForeignKeyColumnKeys() : array
public function getAuditLogForeignKeyColumnKeys(): array
{
return array_keys($this->getAuditLogForeignKeyColumns());
}
Expand All @@ -78,7 +78,7 @@ public function getAuditLogForeignKeyColumnKeys() : array
*
* @return array
*/
public function getAuditLogForeignKeyColumnValues() : array
public function getAuditLogForeignKeyColumnValues(): array
{
return array_values($this->getAuditLogForeignKeyColumns());
}
Expand All @@ -88,7 +88,7 @@ public function getAuditLogForeignKeyColumnValues() : array
*
* @return HasMany|null
*/
public function auditLogs() : ?HasMany
public function auditLogs(): ?HasMany
{
return $this->hasMany($this->getAuditLogModelName(), 'subject_id');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/AuditLoggablePivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait AuditLoggablePivot
*
* @return array
*/
public function getAuditLogForeignKeyColumns() : array
public function getAuditLogForeignKeyColumns(): array
{
return $this->audit_loggable_keys;
}
Expand All @@ -25,7 +25,7 @@ public function getAuditLogForeignKeyColumns() : array
*
* @return HasMany|null
*/
public function auditLogs() : ?HasMany
public function auditLogs(): ?HasMany
{
return $this->hasMany(
$this->getAuditLogModelName(),
Expand Down
2 changes: 1 addition & 1 deletion tests/Fakes/Models/IgnoredFieldsPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IgnoredFieldsPost extends Model

protected $table = 'posts';

public function getAuditLogIgnoredFields() : array
public function getAuditLogIgnoredFields(): array
{
return ['posted_at'];
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Fakes/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Post extends Model

public function tags()
{
return $this->belongsToMany(Tag::class,
return $this->belongsToMany(
Tag::class,
'post_tag',
'post_id',
'tag_id'
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class TestCase extends Orchestra
/**
* SetUp.
*/
protected function setUp() : void
protected function setUp(): void
{
parent::setUp();

Expand Down

0 comments on commit a8da728

Please sign in to comment.