Skip to content

Commit 7339563

Browse files
authored
Pint only on pull request (#1003)
* Pint only on pull request * Add paths * Fix styling --------- Co-authored-by: erikn69 <4933954+erikn69@users.noreply.github.com>
1 parent 2c2b9c7 commit 7339563

39 files changed

+734
-725
lines changed

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: Fix PHP code style issues
22

33
on:
4-
push:
4+
pull_request:
55
paths:
66
- '**.php'
7+
- '.github/workflows/fix-php-code-style-issues.yml'
8+
- '.pint.json'
79

810
jobs:
911
php-code-styling:
@@ -12,8 +14,6 @@ jobs:
1214
steps:
1315
- name: Checkout code
1416
uses: actions/checkout@v4
15-
with:
16-
ref: ${{ github.head_ref }}
1717

1818
- name: Fix PHP code style issues
1919
uses: aglipanci/laravel-pint-action@v2

config/audit.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
|
2525
*/
2626

27-
'user' => [
27+
'user' => [
2828
'morph_prefix' => 'user',
29-
'guards' => [
29+
'guards' => [
3030
'web',
31-
'api'
31+
'api',
3232
],
33-
'resolver' => OwenIt\Auditing\Resolvers\UserResolver::class
33+
'resolver' => OwenIt\Auditing\Resolvers\UserResolver::class,
3434
],
3535

3636
/*
@@ -44,7 +44,7 @@
4444
'resolvers' => [
4545
'ip_address' => OwenIt\Auditing\Resolvers\IpAddressResolver::class,
4646
'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
47-
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
47+
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
4848
],
4949

5050
/*
@@ -60,7 +60,7 @@
6060
'created',
6161
'updated',
6262
'deleted',
63-
'restored'
63+
'restored',
6464
],
6565

6666
/*
@@ -101,9 +101,9 @@
101101
|
102102
*/
103103

104-
'empty_values' => true,
104+
'empty_values' => true,
105105
'allowed_empty_values' => [
106-
'retrieved'
106+
'retrieved',
107107
],
108108

109109
/*
@@ -164,7 +164,7 @@
164164

165165
'drivers' => [
166166
'database' => [
167-
'table' => 'audits',
167+
'table' => 'audits',
168168
'connection' => null,
169169
],
170170
],
@@ -179,10 +179,10 @@
179179
*/
180180

181181
'queue' => [
182-
'enable' => false,
182+
'enable' => false,
183183
'connection' => 'sync',
184-
'queue' => 'default',
185-
'delay' => 0,
184+
'queue' => 'default',
185+
'delay' => 0,
186186
],
187187

188188
/*

src/Audit.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function user()
4949
{
5050
$morphPrefix = Config::get('audit.user.morph_prefix', 'user');
5151

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

5555
/**
@@ -77,37 +77,37 @@ public function resolveData(): array
7777

7878
// Metadata
7979
$this->data = [
80-
'audit_id' => $this->getKey(),
81-
'audit_event' => $this->event,
82-
'audit_tags' => $this->tags,
80+
'audit_id' => $this->getKey(),
81+
'audit_event' => $this->event,
82+
'audit_tags' => $this->tags,
8383
'audit_created_at' => $this->serializeDate($this->{$this->getCreatedAtColumn()}),
8484
'audit_updated_at' => $this->serializeDate($this->{$this->getUpdatedAtColumn()}),
85-
'user_id' => $this->getAttribute($morphPrefix . '_id'),
86-
'user_type' => $this->getAttribute($morphPrefix . '_type'),
85+
'user_id' => $this->getAttribute($morphPrefix.'_id'),
86+
'user_type' => $this->getAttribute($morphPrefix.'_type'),
8787
];
8888

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

9696
if ($this->user) {
9797
foreach ($this->user->getArrayableAttributes() as $attribute => $value) {
98-
$this->data['user_' . $attribute] = $value;
98+
$this->data['user_'.$attribute] = $value;
9999
}
100100
}
101101

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

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

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

113113
$this->modified = array_diff_key(array_keys($this->data), $this->metadata);
@@ -118,8 +118,7 @@ public function resolveData(): array
118118
/**
119119
* Get the formatted value of an Eloquent model.
120120
*
121-
* @param mixed $value
122-
*
121+
* @param mixed $value
123122
* @return mixed
124123
*/
125124
protected function getFormattedValue(Model $model, string $key, $value)
@@ -139,12 +138,13 @@ protected function getFormattedValue(Model $model, string $key, $value)
139138
$model->getCasts()
140139
) && $model->getCasts()[$key] == 'Illuminate\Database\Eloquent\Casts\AsArrayObject') {
141140
$arrayObject = new \Illuminate\Database\Eloquent\Casts\ArrayObject(json_decode($value, true) ?: []);
141+
142142
return $arrayObject;
143143
}
144144

145145
// Cast to native PHP type
146146
if ($model->hasCast($key)) {
147-
if ($model->getCastType($key) == 'datetime' ) {
147+
if ($model->getCastType($key) == 'datetime') {
148148
$value = $this->castDatetimeUTC($model, $value);
149149
}
150150

@@ -168,7 +168,7 @@ protected function getFormattedValue(Model $model, string $key, $value)
168168
*/
169169
private function castDatetimeUTC($model, $value)
170170
{
171-
if (!is_string($value)) {
171+
if (! is_string($value)) {
172172
return $value;
173173
}
174174

@@ -198,7 +198,7 @@ private function castDatetimeUTC($model, $value)
198198
*/
199199
public function getDataValue(string $key)
200200
{
201-
if (!array_key_exists($key, $this->data)) {
201+
if (! array_key_exists($key, $this->data)) {
202202
return;
203203
}
204204

@@ -226,15 +226,14 @@ public function getDataValue(string $key)
226226
/**
227227
* Decode attribute value.
228228
*
229-
* @param mixed $value
230-
*
229+
* @param mixed $value
231230
* @return mixed
232231
*/
233232
protected function decodeAttributeValue(Contracts\Auditable $auditable, string $attribute, $value)
234233
{
235234
$attributeModifiers = $auditable->getAttributeModifiers();
236235

237-
if (!array_key_exists($attribute, $attributeModifiers)) {
236+
if (! array_key_exists($attribute, $attributeModifiers)) {
238237
return $value;
239238
}
240239

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

265264
if ($value instanceof DateTimeInterface) {
266-
$metadata[$key] = !is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
265+
$metadata[$key] = ! is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
267266
}
268267
}
269268

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

295294
if ($value instanceof DateTimeInterface) {
296-
$modified[$attribute][$state] = !is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
295+
$modified[$attribute][$state] = ! is_null($this->auditable) ? $this->auditable->serializeDate($value) : $this->serializeDate($value);
297296
}
298297
}
299298

300-
301299
if (! $json) {
302300
return $modified;
303301
}
@@ -312,6 +310,6 @@ public function getModified(bool $json = false, int $options = 0, int $depth = 5
312310
*/
313311
public function getTags(): array
314312
{
315-
return preg_split('/,/', $this->tags, -1, PREG_SPLIT_NO_EMPTY)?: [];
313+
return preg_split('/,/', $this->tags, -1, PREG_SPLIT_NO_EMPTY) ?: [];
316314
}
317315
}

0 commit comments

Comments
 (0)