Skip to content

Commit

Permalink
Updated deps to better support laravel 9; Updated typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin.schmick committed Jun 29, 2022
1 parent 5b79ae2 commit 817966e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"homepage": "https://github.com/always-open/laravel-model-auditlog",
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"php": "^8.0.0|^8.1.0",
"awobaz/compoships": "^2.0.3",
"fico7489/laravel-pivot": "^3.0.1",
"laravel/framework": "^8.0|^9.0",
"always-open/laravel-process-stamps": "^5.0"
"laravel/framework": "^9.0",
"always-open/laravel-process-stamps": "^6.0"
},
"require-dev": {
"doctrine/dbal": "^2.9|^3.0",
"orchestra/testbench": "^6.0",
"doctrine/dbal": "^3.0",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
Expand Down
12 changes: 6 additions & 6 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(Model $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(Model $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(Model $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(Model $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(Model $subject_model, array $config): void
{
$tablename = $this->generateAuditTableName($subject_model, $config);
$fileslug = "create_{$tablename}_table";
Expand Down Expand Up @@ -176,7 +176,7 @@ public function getStubWithReplacements(string $file, array $replacements): stri
*
* @return string
*/
public function generateMigrationSubjectForeignKeys($subject_model, array $config): string
public function generateMigrationSubjectForeignKeys(Model $subject_model, array $config): string
{
if (Arr::get($config, 'enable_subject_foreign_keys') === true) {
return '$table->foreign(\'subject_id\')
Expand Down
21 changes: 8 additions & 13 deletions src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class BaseModel extends Model
{
public $casts = [
self::CREATED_AT => 'datetime:Y-m-d H:i:s.u',
self::CREATED_AT => 'datetime:Y-m-d H:i:s.u',
self::UPDATED_AT => 'datetime:Y-m-d H:i:s.u',
'occurred_at' => 'datetime:Y-m-d H:i:s.u',
];

Expand All @@ -42,7 +42,7 @@ public function recordChanges(int $event_type, Model $model): void

/**
* @param array $changes
* @param $model
* @param Model $model
*
* @return Collection
*/
Expand All @@ -68,7 +68,7 @@ public function passingChanges(array $changes, Model $model): Collection
public function saveChanges(Collection $passing_changes, int $event_type, Model $model): void
{
$passing_changes
->each(function ($change, $key) use ($event_type, $model) {
->each(function ($change, string $key) use ($event_type, $model) {
$log = new static();
$log->event_type = $event_type;
$log->occurred_at = now();
Expand All @@ -94,7 +94,7 @@ public function saveChanges(Collection $passing_changes, int $event_type, Model

/**
* @param int $event_type
* @param $model
* @param Model $model
* @param string $relationName
* @param array $pivotIds
*/
Expand All @@ -114,9 +114,9 @@ public function recordPivotChanges(int $event_type, Model $model, string $relati
}

/**
* @param $pivot
* @param $model
* @param $pivotIds
* @param string $pivot
* @param Model $model
* @param array $pivotIds
*
* @return array
*/
Expand Down Expand Up @@ -181,24 +181,19 @@ public static function getChangesByType(int $event_type, Model $model): array
switch ($event_type) {
case EventType::CREATED:
return $model->getAttributes();
break;
case EventType::RESTORED:
return $model->getChanges();
break;
case EventType::FORCE_DELETED:
return []; // if force deleted we want to stop execution here as there would be nothing to correlate records to
break;
case EventType::DELETED:
if (method_exists($model, 'getDeletedAtColumn')) {
return $model->only($model->getDeletedAtColumn());
}

return [];
break;
case EventType::UPDATED:
default:
return $model->getDirty();
break;
}
}

Expand All @@ -223,7 +218,7 @@ public function getSubjectModelClassname(): string
*
* @return mixed
*/
public function getSubjectModelClassInstance()
public function getSubjectModelClassInstance() : mixed
{
$class = $this->getSubjectModelClassname();

Expand Down
2 changes: 1 addition & 1 deletion src/Observers/AuditLogObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function pivotDetached(Model $model, string $relationName, array $pivotId
*
* @return mixed
*/
protected function getAuditLogModel(Model $model)
protected function getAuditLogModel(Model $model) : mixed
{
return $model->getAuditLogModelInstance();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/AuditLoggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getAuditLogModelName(): string
*
* @return mixed
*/
public function getAuditLogModelInstance()
public function getAuditLogModelInstance() : mixed
{
$class = $this->getAuditLogModelName();

Expand Down

0 comments on commit 817966e

Please sign in to comment.