Skip to content

Commit

Permalink
♻️ doc types first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
willpower232 committed Jan 18, 2025
1 parent 559b391 commit 0a99ae0
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 101 deletions.
19 changes: 10 additions & 9 deletions src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ trait Audit
/**
* Audit data.
*
* @var array
* @var array<string,mixed>
*/
protected $data = [];

/**
* The Audit attributes that belong to the metadata.
*
* @var array
* @var array<int,string>
*/
protected $metadata = [];

/**
* The Auditable attributes that were modified.
*
* @var array
* @var array<int,string>
*/
protected $modified = [];

Expand Down Expand Up @@ -118,8 +118,6 @@ public function resolveData(): array
/**
* Get the formatted value of an Eloquent model.
*
* @param Model $model
* @param string $key
* @param mixed $value
*
* @return mixed
Expand Down Expand Up @@ -162,6 +160,11 @@ protected function getFormattedValue(Model $model, string $key, $value)
return $value;
}

/**
* @param Model $model
* @param mixed $value
* @return mixed
*/
private function castDatetimeUTC($model, $value)
{
if (!is_string($value)) {
Expand Down Expand Up @@ -216,8 +219,6 @@ public function getDataValue(string $key)
/**
* Decode attribute value.
*
* @param Contracts\Auditable $auditable
* @param string $attribute
* @param mixed $value
*
* @return mixed
Expand Down Expand Up @@ -291,9 +292,9 @@ public function getModified(bool $json = false, int $options = 0, int $depth = 5
/**
* Get the Audit tags as an array.
*
* @return array
* @return array<string>|false
*/
public function getTags(): array
public function getTags()
{
return preg_split('/,/', $this->tags, -1, PREG_SPLIT_NO_EMPTY);
}
Expand Down
18 changes: 1 addition & 17 deletions src/AuditableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class AuditableObserver
/**
* Handle the retrieved event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function retrieved(Auditable $model)
Expand All @@ -32,8 +30,6 @@ public function retrieved(Auditable $model)
/**
* Handle the created event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function created(Auditable $model)
Expand All @@ -44,8 +40,6 @@ public function created(Auditable $model)
/**
* Handle the updated event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function updated(Auditable $model)
Expand All @@ -59,8 +53,6 @@ public function updated(Auditable $model)
/**
* Handle the deleted event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function deleted(Auditable $model)
Expand All @@ -71,8 +63,6 @@ public function deleted(Auditable $model)
/**
* Handle the restoring event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function restoring(Auditable $model)
Expand All @@ -86,8 +76,6 @@ public function restoring(Auditable $model)
/**
* Handle the restored event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return void
*/
public function restored(Auditable $model)
Expand All @@ -99,7 +87,7 @@ public function restored(Auditable $model)
static::$restoring = false;
}

protected function dispatchAudit(Auditable $model)
protected function dispatchAudit(Auditable $model): void
{
if (!$model->readyForAuditing()) {
return;
Expand All @@ -121,10 +109,6 @@ protected function dispatchAudit(Auditable $model)

/**
* Fire the Auditing event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return bool
*/
protected function fireDispatchingAuditEvent(Auditable $model): bool
{
Expand Down
7 changes: 0 additions & 7 deletions src/Auditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ public function execute(Auditable $model): void

/**
* Create an instance of the Database audit driver.
*
* @return \OwenIt\Auditing\Drivers\Database
*/
protected function createDatabaseDriver(): Database
{
Expand All @@ -104,11 +102,6 @@ protected function createDatabaseDriver(): Database

/**
* Fire the Auditing event.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
* @param \OwenIt\Auditing\Contracts\AuditDriver $driver
*
* @return bool
*/
protected function fireAuditingEvent(Auditable $model, AuditDriver $driver): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InstallCommand extends Command
/**
* {@inheritdoc}
*/
public function handle()
public function handle(): void
{
$this->comment('Publishing Auditing Configuration...');
$this->callSilent('vendor:publish', ['--tag' => 'config']);
Expand Down
2 changes: 0 additions & 2 deletions src/Contracts/AttributeRedactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface AttributeRedactor extends AttributeModifier
* Redact an attribute value.
*
* @param mixed $value
*
* @return string
*/
public static function redact($value): string;
}
14 changes: 7 additions & 7 deletions src/Contracts/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function user();
/**
* Audit data resolver.
*
* @return array
* @return array<string,mixed>
*/
public function resolveData(): array;

Expand All @@ -55,21 +55,21 @@ public function getDataValue(string $key);
* Get the Audit metadata.
*
* @param bool $json
* @param int $options
* @param int $depth
* @param int $options
* @param int<1, max> $depth
*
* @return array|string
* @return array<string,mixed>|string
*/
public function getMetadata(bool $json = false, int $options = 0, int $depth = 512);

/**
* Get the Auditable modified attributes.
*
* @param bool $json
* @param int $options
* @param int $depth
* @param int $options
* @param int<1, max> $depth
*
* @return array|string
* @return array<string,mixed>|string
*/
public function getModified(bool $json = false, int $options = 0, int $depth = 512);
}
8 changes: 0 additions & 8 deletions src/Contracts/AuditDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@ interface AuditDriver
{
/**
* Perform an audit.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return \OwenIt\Auditing\Contracts\Audit
*/
public function audit(Auditable $model): ?Audit;

/**
* Remove older audits that go over the threshold.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*
* @return bool
*/
public function prune(Auditable $model): bool;
}
34 changes: 8 additions & 26 deletions src/Contracts/Auditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public function audits(): MorphMany;

/**
* Set the Audit event.
*
* @param string $event
*
* @return Auditable
*/
public function setAuditEvent(string $event): Auditable;

Expand All @@ -32,14 +28,12 @@ public function getAuditEvent();
/**
* Get the events that trigger an Audit.
*
* @return array
* @return array<string>
*/
public function getAuditEvents(): array;

/**
* Is the model ready for auditing?
*
* @return bool
*/
public function readyForAuditing(): bool;

Expand All @@ -48,35 +42,31 @@ public function readyForAuditing(): bool;
*
* @throws \OwenIt\Auditing\Exceptions\AuditingException
*
* @return array
* @return array<string,mixed>
*/
public function toAudit(): array;

/**
* Get the (Auditable) attributes included in audit.
*
* @return array
* @return array<string>
*/
public function getAuditInclude(): array;

/**
* Get the (Auditable) attributes excluded from audit.
*
* @return array
* @return array<string>
*/
public function getAuditExclude(): array;

/**
* Get the strict audit status.
*
* @return bool
*/
public function getAuditStrict(): bool;

/**
* Get the audit (Auditable) timestamps status.
*
* @return bool
*/
public function getAuditTimestamps(): bool;

Expand All @@ -89,43 +79,35 @@ public function getAuditDriver();

/**
* Get the Audit threshold.
*
* @return int
*/
public function getAuditThreshold(): int;

/**
* Get the Attribute modifiers.
*
* @return array
* @return array<string,string>
*/
public function getAttributeModifiers(): array;

/**
* Transform the data before performing an audit.
*
* @param array $data
*
* @return array
* @param array<string,mixed> $data
* @return array<string,mixed>
*/
public function transformAudit(array $data): array;

/**
* Generate an array with the model tags.
*
* @return array
* @return array<string>
*/
public function generateTags(): array;

/**
* Transition to another model state from an Audit.
*
* @param Audit $audit
* @param bool $old
*
* @throws \OwenIt\Auditing\Exceptions\AuditableTransitionException
*
* @return Auditable
*/
public function transitionTo(Audit $audit, bool $old = false): Auditable;
}
2 changes: 0 additions & 2 deletions src/Events/AuditCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class AuditCustom

/**
* Create a new Auditing event instance.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
*/
public function __construct(Auditable $model)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Events/Audited.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class Audited

/**
* Create a new Audited event instance.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
* @param \OwenIt\Auditing\Contracts\AuditDriver $driver
* @param \OwenIt\Auditing\Contracts\Audit|null $audit
*/
public function __construct(Auditable $model, AuditDriver $driver, ?Audit $audit = null)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Events/Auditing.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Auditing

/**
* Create a new Auditing event instance.
*
* @param \OwenIt\Auditing\Contracts\Auditable $model
* @param \OwenIt\Auditing\Contracts\AuditDriver $driver
*/
public function __construct(Auditable $model, AuditDriver $driver)
{
Expand Down
Loading

0 comments on commit 0a99ae0

Please sign in to comment.