Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin_repo/master' into v14-redo
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Feb 17, 2025
2 parents 99f30c4 + 7339563 commit 34cf3f8
Show file tree
Hide file tree
Showing 36 changed files with 730 additions and 717 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Fix PHP code style issues

on:
push:
pull_request:
paths:
- '**.php'
- '.github/workflows/fix-php-code-style-issues.yml'
- '.pint.json'

jobs:
php-code-styling:
Expand All @@ -12,8 +14,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@v2
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PHPStan

on:
push:
pull_request:
paths:
- '**.php'
- 'phpstan.neon.dist'
Expand All @@ -10,6 +10,9 @@ jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
timeout-minutes: 15
env:
COMPOSER_NO_INTERACTION: 1
steps:
- uses: actions/checkout@v4

Expand All @@ -24,8 +27,8 @@ jobs:

- name: Install larastan
run: |
composer require "larastan/larastan" --no-interaction --no-update
composer update --prefer-dist --no-interaction
composer require "larastan/larastan" --no-update
composer update --prefer-dist --no-suggest
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
24 changes: 12 additions & 12 deletions config/audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
|
*/

'user' => [
'user' => [
'morph_prefix' => 'user',
'guards' => [
'guards' => [
'web',
'api'
'api',
],
'resolver' => OwenIt\Auditing\Resolvers\UserResolver::class
'resolver' => OwenIt\Auditing\Resolvers\UserResolver::class,
],

/*
Expand All @@ -44,7 +44,7 @@
'resolvers' => [
'ip_address' => OwenIt\Auditing\Resolvers\IpAddressResolver::class,
'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
],

/*
Expand All @@ -60,7 +60,7 @@
'created',
'updated',
'deleted',
'restored'
'restored',
],

/*
Expand Down Expand Up @@ -101,9 +101,9 @@
|
*/

'empty_values' => true,
'empty_values' => true,
'allowed_empty_values' => [
'retrieved'
'retrieved',
],

/*
Expand Down Expand Up @@ -164,7 +164,7 @@

'drivers' => [
'database' => [
'table' => 'audits',
'table' => 'audits',
'connection' => null,
],
],
Expand All @@ -179,10 +179,10 @@
*/

'queue' => [
'enable' => false,
'enable' => false,
'connection' => 'sync',
'queue' => 'default',
'delay' => 0,
'queue' => 'default',
'delay' => 0,
],

/*
Expand Down
42 changes: 20 additions & 22 deletions src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function user()
{
$morphPrefix = Config::get('audit.user.morph_prefix', 'user');

return $this->morphTo(__FUNCTION__, $morphPrefix . '_type', $morphPrefix . '_id');
return $this->morphTo(__FUNCTION__, $morphPrefix.'_type', $morphPrefix.'_id');
}

/**
Expand Down Expand Up @@ -77,37 +77,37 @@ public function resolveData(): array

// Metadata
$this->data = [
'audit_id' => $this->getKey(),
'audit_event' => $this->event,
'audit_tags' => $this->tags,
'audit_id' => $this->getKey(),
'audit_event' => $this->event,
'audit_tags' => $this->tags,
'audit_created_at' => $this->serializeDate($this->{$this->getCreatedAtColumn()}),
'audit_updated_at' => $this->serializeDate($this->{$this->getUpdatedAtColumn()}),
'user_id' => $this->getAttribute($morphPrefix . '_id'),
'user_type' => $this->getAttribute($morphPrefix . '_type'),
'user_id' => $this->getAttribute($morphPrefix.'_id'),
'user_type' => $this->getAttribute($morphPrefix.'_type'),
];

// add resolvers data to metadata
$resolverData = [];
foreach (array_keys(Config::get('audit.resolvers', [])) as $name) {
$resolverData['audit_' . $name] = $this->$name;
$resolverData['audit_'.$name] = $this->$name;
}
$this->data = array_merge($this->data, $resolverData);

if ($this->user) {
foreach ($this->user->getArrayableAttributes() as $attribute => $value) {
$this->data['user_' . $attribute] = $value;
$this->data['user_'.$attribute] = $value;
}
}

$this->metadata = array_keys($this->data);

// Modified Auditable attributes
foreach ($this->new_values ?? [] as $key => $value) {
$this->data['new_' . $key] = $value;
$this->data['new_'.$key] = $value;
}

foreach ($this->old_values ?? [] as $key => $value) {
$this->data['old_' . $key] = $value;
$this->data['old_'.$key] = $value;
}

$this->modified = array_diff_key(array_keys($this->data), $this->metadata);
Expand All @@ -118,8 +118,7 @@ public function resolveData(): array
/**
* Get the formatted value of an Eloquent model.
*
* @param mixed $value
*
* @param mixed $value
* @return mixed
*/
protected function getFormattedValue(Model $model, string $key, $value)
Expand All @@ -139,12 +138,13 @@ protected function getFormattedValue(Model $model, string $key, $value)
$model->getCasts()
) && $model->getCasts()[$key] == 'Illuminate\Database\Eloquent\Casts\AsArrayObject') {
$arrayObject = new \Illuminate\Database\Eloquent\Casts\ArrayObject(json_decode($value, true) ?: []);

return $arrayObject;
}

// Cast to native PHP type
if ($model->hasCast($key)) {
if ($model->getCastType($key) == 'datetime' ) {
if ($model->getCastType($key) == 'datetime') {
$value = $this->castDatetimeUTC($model, $value);
}

Expand All @@ -168,7 +168,7 @@ protected function getFormattedValue(Model $model, string $key, $value)
*/
private function castDatetimeUTC($model, $value)
{
if (!is_string($value)) {
if (! is_string($value)) {
return $value;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ private function castDatetimeUTC($model, $value)
*/
public function getDataValue(string $key)
{
if (!array_key_exists($key, $this->data)) {
if (! array_key_exists($key, $this->data)) {
return;
}

Expand Down Expand Up @@ -226,15 +226,14 @@ public function getDataValue(string $key)
/**
* Decode attribute value.
*
* @param mixed $value
*
* @param mixed $value
* @return mixed
*/
protected function decodeAttributeValue(Contracts\Auditable $auditable, string $attribute, $value)
{
$attributeModifiers = $auditable->getAttributeModifiers();

if (!array_key_exists($attribute, $attributeModifiers)) {
if (! array_key_exists($attribute, $attributeModifiers)) {
return $value;
}

Expand Down Expand Up @@ -263,7 +262,7 @@ public function getMetadata(bool $json = false, int $options = 0, int $depth = 5
$metadata[$key] = $value;

if ($value instanceof DateTimeInterface) {
$metadata[$key] = !is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
$metadata[$key] = ! is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
}
}

Expand Down Expand Up @@ -293,11 +292,10 @@ public function getModified(bool $json = false, int $options = 0, int $depth = 5
$modified[$attribute][$state] = $value;

if ($value instanceof DateTimeInterface) {
$modified[$attribute][$state] = !is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
$modified[$attribute][$state] = ! is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
}
}


if (! $json) {
return $modified;
}
Expand All @@ -312,6 +310,6 @@ public function getModified(bool $json = false, int $options = 0, int $depth = 5
*/
public function getTags(): array
{
return preg_split('/,/', $this->tags, -1, PREG_SPLIT_NO_EMPTY)?: [];
return preg_split('/,/', $this->tags, -1, PREG_SPLIT_NO_EMPTY) ?: [];
}
}
Loading

0 comments on commit 34cf3f8

Please sign in to comment.