Skip to content

Commit 254da72

Browse files
committed
chore: rector updates
1 parent 820225c commit 254da72

14 files changed

+64
-58
lines changed

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
]);
14+
15+
// register a single rule
16+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17+
18+
// define sets of rules
19+
$rectorConfig->sets([
20+
LevelSetList::UP_TO_PHP_82,
21+
]);
22+
};

src/Html/Builder.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ class Builder
2020
use Macroable;
2121

2222
// Select plugin constants.
23-
const SELECT_STYLE_API = 'api';
23+
final const SELECT_STYLE_API = 'api';
2424

25-
const SELECT_STYLE_SINGLE = 'single';
25+
final const SELECT_STYLE_SINGLE = 'single';
2626

27-
const SELECT_STYLE_MULTI = 'multi';
27+
final const SELECT_STYLE_MULTI = 'multi';
2828

29-
const SELECT_STYLE_OS = 'os';
29+
final const SELECT_STYLE_OS = 'os';
3030

31-
const SELECT_STYLE_MULTI_SHIFT = 'multi+shift';
31+
final const SELECT_STYLE_MULTI_SHIFT = 'multi+shift';
3232

33-
const SELECT_ITEMS_ROW = 'row';
33+
final const SELECT_ITEMS_ROW = 'row';
3434

35-
const SELECT_ITEMS_COLUMN = 'column';
35+
final const SELECT_ITEMS_COLUMN = 'column';
3636

37-
const SELECT_ITEMS_CELL = 'cell';
37+
final const SELECT_ITEMS_CELL = 'cell';
3838

3939
/**
4040
* The default type to use for the DataTables javascript.
@@ -53,7 +53,10 @@ class Builder
5353

5454
protected string $template = '';
5555

56-
protected array $attributes = [];
56+
protected array $attributes = [
57+
'serverSide' => true,
58+
'processing' => true,
59+
];
5760

5861
protected string|array $ajax = '';
5962

@@ -66,10 +69,6 @@ public function __construct(public Repository $config, public Factory $view, pub
6669

6770
$this->collection = new Collection;
6871
$this->tableAttributes = $defaults;
69-
$this->attributes = [
70-
'serverSide' => true,
71-
'processing' => true,
72-
];
7372
}
7473

7574
/**

src/Html/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public function parseRender(mixed $value): ?string
503503
return $value($parameters);
504504
} elseif ($this->isBuiltInRenderFunction($value)) {
505505
return $value;
506-
} elseif (strlen($value) < 256 && $view->exists($value)) {
506+
} elseif (strlen((string) $value) < 256 && $view->exists($value)) {
507507
return $view->make($value)->with($parameters)->render();
508508
}
509509

src/Html/Editor/Editor.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class Editor extends Fluent
2424
use HasAuthorizations;
2525
use HasEvents;
2626

27-
const DISPLAY_LIGHTBOX = 'lightbox';
27+
final const DISPLAY_LIGHTBOX = 'lightbox';
2828

29-
const DISPLAY_ENVELOPE = 'envelope';
29+
final const DISPLAY_ENVELOPE = 'envelope';
3030

31-
const DISPLAY_BOOTSTRAP = 'bootstrap';
31+
final const DISPLAY_BOOTSTRAP = 'bootstrap';
3232

33-
const DISPLAY_FOUNDATION = 'foundation';
33+
final const DISPLAY_FOUNDATION = 'foundation';
3434

35-
const DISPLAY_JQUERYUI = 'jqueryui';
35+
final const DISPLAY_JQUERYUI = 'jqueryui';
3636

3737
public array $events = [];
3838

@@ -43,6 +43,7 @@ class Editor extends Fluent
4343
*/
4444
public function __construct($instance = 'editor')
4545
{
46+
$attributes = [];
4647
$attributes['instance'] = $instance;
4748

4849
parent::__construct($attributes);

src/Html/Editor/Fields/BelongsTo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function model(Builder|string $class, string $text, string $id = '
1919
}
2020

2121
$table = Str::singular($table);
22-
$foreign = $foreign ?? $table.'_id';
22+
$foreign ??= $table.'_id';
2323

2424
return self::make($foreign, Str::title($table))
2525
->modelOptions($class, $text, $id);

src/Html/Editor/Fields/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Field extends Fluent
3131
*/
3232
public function __construct($attributes = [])
3333
{
34-
$attributes['type'] = $attributes['type'] ?? $this->type;
34+
$attributes['type'] ??= $this->type;
3535

3636
parent::__construct($attributes);
3737
}

src/Html/Editor/Fields/Options.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ public static function model(string|EloquentBuilder $model, string $value, strin
3939
$model = $model::query();
4040
}
4141

42-
return $model->get()->map(function ($model) use ($value, $key) {
43-
return [
44-
'value' => $model->{$key},
45-
'label' => $model->{$value},
46-
];
47-
});
42+
return $model->get()->map(fn($model) => [
43+
'value' => $model->{$key},
44+
'label' => $model->{$value},
45+
]);
4846
}
4947

5048
/**
@@ -65,9 +63,7 @@ public static function table(
6563
$callback($query);
6664
}
6765

68-
return $query->get()->map(function ($row) {
69-
return (array) $row;
70-
});
66+
return $query->get()->map(fn($row) => (array) $row);
7167
}
7268

7369
/**

src/Html/Editor/Fields/Select2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function ajaxData(array|string $data): static
8484
if (is_array($data)) {
8585
$script = 'function(params) {';
8686
foreach ($data as $key => $value) {
87-
$value = json_encode($value);
87+
$value = json_encode($value, JSON_THROW_ON_ERROR);
8888
$script .= " params.$key = $value; ";
8989
}
9090
$script .= 'return params; }';

src/Html/HasTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function removeTableClass(array|string $class): static
111111
$currentClass = $this->getTableAttribute('class');
112112

113113
$classes = array_diff(
114-
(array) preg_split('#\s+#', $currentClass, -1, PREG_SPLIT_NO_EMPTY),
114+
(array) preg_split('#\s+#', (string) $currentClass, -1, PREG_SPLIT_NO_EMPTY),
115115
(array) preg_split('#\s+#', $class, -1, PREG_SPLIT_NO_EMPTY)
116116
);
117117
$class = implode(' ', array_unique($classes));

src/Html/HtmlBuilder.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88

99
class HtmlBuilder
1010
{
11-
/**
12-
* The URL generator instance.
13-
*/
14-
protected UrlGenerator $url;
15-
16-
/**
17-
* The View Factory instance.
18-
*/
19-
protected Factory $view;
20-
2111
/**
2212
* Create a new HTML builder instance.
2313
*/
24-
public function __construct(UrlGenerator $url, Factory $view)
14+
public function __construct(
15+
/**
16+
* The URL generator instance.
17+
*/
18+
protected UrlGenerator $url,
19+
/**
20+
* The View Factory instance.
21+
*/
22+
protected Factory $view
23+
)
2524
{
26-
$this->url = $url;
27-
$this->view = $view;
2825
}
2926

3027
/**

0 commit comments

Comments
 (0)