Skip to content

Commit bb6abd5

Browse files
committed
feature: apply rector
1 parent 74c4132 commit bb6abd5

14 files changed

Lines changed: 22 additions & 36 deletions

File tree

src/Amis.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function getAssets(): array
120120
{
121121
$assets = (array)ConfigHelper::get('assets', []);
122122

123-
$assets['js'] = $assets['js'] ?? [];
123+
$assets['js'] ??= [];
124124
if (is_callable($assets['js'])) {
125125
$assets['js'] = call_user_func($assets['js']);
126126
}
@@ -134,12 +134,12 @@ private function getAssets(): array
134134
return $item;
135135
}, $assets['js']);
136136

137-
$assets['lang'] = $assets['lang'] ?? 'zh';
137+
$assets['lang'] ??= 'zh';
138138
if (is_callable($assets['lang'])) {
139139
$assets['lang'] = (string)call_user_func($assets['lang']);
140140
}
141141

142-
$assets['locale'] = $assets['locale'] ?? 'zh-CN';
142+
$assets['locale'] ??= 'zh-CN';
143143
if (is_callable($assets['locale'])) {
144144
$assets['locale'] = (string)call_user_func($assets['locale']);
145145
}

src/Amis/DetailAttribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DetailAttribute extends Component
5858
public function copyable(string $content = null)
5959
{
6060
$this->schema['copyable'] = [
61-
'content' => $content === null ? "\${$this->schema['name']}" : $content,
61+
'content' => $content ?? "\${$this->schema['name']}",
6262
];
6363
return $this;
6464
}
@@ -68,7 +68,7 @@ public function copyable(string $content = null)
6868
*/
6969
public function __call(string $name, array $arguments)
7070
{
71-
if (strlen($name) > 4 && strpos($name, 'type') === 0) {
71+
if (strlen($name) > 4 && str_starts_with($name, 'type')) {
7272
$this->schema['type'] = 'static-' . lcfirst(substr($name, 4));
7373
$this->schema($arguments[0] ?? []);
7474
} else {

src/Amis/FormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function __call(string $name, array $arguments)
112112
{
113113
if (strlen($name) > 4 && str_starts_with($name, 'type')) {
114114
/** @phpstan-ignore-next-line */
115-
$this->schema['type'] = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '-$1', lcfirst(substr($name, 4))));
115+
$this->schema['type'] = strtolower((string) preg_replace('/(?<=[a-z])([A-Z])/', '-$1', lcfirst(substr($name, 4))));
116116
$this->schema($arguments[0] ?? []);
117117
} else {
118118
$this->callToSetSchema($name, $arguments);

src/Amis/GridColumn.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function toArray(): array
9696
*/
9797
public function __call(string $name, array $arguments)
9898
{
99-
if (strlen($name) > 4 && strpos($name, 'type') === 0) {
99+
if (strlen($name) > 4 && str_starts_with($name, 'type')) {
100100
$this->schema['type'] = lcfirst(substr($name, 4));
101101
$this->schema($arguments[0] ?? []);
102102
} else {
@@ -124,8 +124,8 @@ protected function solveSearchable(): void
124124
if ($autoSolve) {
125125
$searchable = ['type' => 'input-text'];
126126
}
127-
$searchable['name'] = $searchable['name'] ?? $this->schema['name'];
128-
$searchable['clearable'] = $searchable['clearable'] ?? true;
127+
$searchable['name'] ??= $this->schema['name'];
128+
$searchable['clearable'] ??= true;
129129

130130
if (!$autoSolve) {
131131
$this->schema['searchable'] = $searchable;
@@ -176,7 +176,7 @@ private function buildTypeSelectBySchemaMap(array $map): array
176176
'options' => array_map(
177177
function (array $item) {
178178
if (isset($item['label'])) {
179-
$item['label'] = strip_tags($item['label']); // 去除 html 结构,使得 map 带 html 格式时支持
179+
$item['label'] = strip_tags((string) $item['label']); // 去除 html 结构,使得 map 带 html 格式时支持
180180
}
181181
return $item;
182182
},

src/Amis/Traits/ActionButtonSupport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ public function withButtonDrawer(int $index, string $label, $body, array $schema
144144
*/
145145
public function withButton(int $index, string $label, array $schema = [])
146146
{
147-
$schema['type'] = $schema['type'] ?? 'button';
148-
$schema['label'] = $schema['label'] ?? $label;
147+
$schema['type'] ??= 'button';
148+
$schema['label'] ??= $label;
149149
$this->setActionButton($index, $schema);
150150
return $this;
151151
}

src/Controller/AmisSourceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected function buildGridColumn(array $gridColumns): array
178178
if ($item instanceof Component) {
179179
$item = $item->toArray();
180180
}
181-
$item['label'] = $item['label'] ?? $this->repository()->getLabel($item['name']);
181+
$item['label'] ??= $this->repository()->getLabel($item['name']);
182182
}
183183
unset($item);
184184

src/Controller/Traits/AmisSourceController/DetailTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function buildDetailAttributes(array $detailAttributes): array
9494
if ($item instanceof Amis\Component) {
9595
$item = $item->toArray();
9696
}
97-
$item['label'] = $item['label'] ?? $this->repository()->getLabel($item['name']);
97+
$item['label'] ??= $this->repository()->getLabel($item['name']);
9898
}
9999
unset($item);
100100
return $detailAttributes;

src/Exceptions/ValidationException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66

77
class ValidationException extends RuntimeException
88
{
9-
public array $errors;
10-
11-
public function __construct(array $errors, string $message = null)
9+
public function __construct(public array $errors, string $message = null)
1210
{
13-
$this->errors = $errors;
1411
parent::__construct($message ?? 'Validation Error', 422);
1512
}
1613
}

src/Helper/ArrayHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function get(array $array, $key, $default = null)
5858
return $array[$key];
5959
}
6060

61-
if (strpos($key, '.') === false) {
61+
if (!str_contains($key, '.')) {
6262
return $array[$key] ?? $default;
6363
}
6464

src/Helper/DTO/PresetItemDTO.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,14 @@ class PresetItemDTO
2626
private const NULL_VALUE = '%NULL%';
2727
private const SCENE_DEFAULT = 'default';
2828
private const SCENE_UPDATE_APPEND_RULE = 'sometimes';
29-
30-
protected string $key;
31-
protected array $define;
3229
protected array $attributes = [];
3330
protected array $config = [
3431
'defaultCanEdit' => true, // 默认是否可以编辑
3532
];
3633

37-
public function __construct(string $key, array $define, array $config = [])
34+
public function __construct(protected string $key, protected array $define, array $config = [])
3835
{
39-
$this->key = $key;
4036
$this->config = array_merge($this->config, $config);
41-
$this->define = $define;
4237
}
4338

4439
/**
@@ -131,7 +126,7 @@ protected function buildFilter($value)
131126
return fn($query, $value, $attribute) => $query
132127
->whereBetween($attribute, array_map(
133128
fn($timestamp) => date('Y-m-d H:i:s', (int)$timestamp),
134-
explode(',', $value)
129+
explode(',', (string) $value)
135130
));
136131
}
137132
// TODO 扩展其他 filter,或者方式(比如 static 直接注入?)

0 commit comments

Comments
 (0)