Skip to content

Commit 7e6682a

Browse files
authored
[Enhancement] Fix code style (#1837)
* fix code style
1 parent 7e361e3 commit 7e6682a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+314
-187
lines changed

src/Button.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PowerComponents\LivewirePowerGrid;
44

5+
use Closure;
56
use Illuminate\Support\Traits\Macroable;
67
use Livewire\Wireable;
78

@@ -17,7 +18,7 @@
1718
* @method static route(string $route, array $params, string $target)
1819
* @method static method(string $method)
1920
* @method static target(string $target) _blank, _self, _top, _parent, null
20-
* @method static can(bool|\Closure $allowed = true)
21+
* @method static can(bool|Closure $allowed = true)
2122
* @method static id(string $id = null)
2223
* @method static confirm(string $message = 'Are you sure you want to perform this action?')
2324
* @method static confirmPrompt(string $message = 'Are you sure you want to perform this action?', string $confirmValue = 'Confirm')
@@ -38,7 +39,7 @@ final class Button implements Wireable
3839

3940
public array $iconAttributes = [];
4041

41-
public bool | \Closure $can = true;
42+
public bool|Closure $can = true;
4243

4344
public function __construct(public string $action)
4445
{

src/Column.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace PowerComponents\LivewirePowerGrid;
44

55
use Illuminate\Support\Traits\Macroable;
6+
use Livewire\Wireable;
67

78
/**
89
* Macros
910
* @method static naturalSort()
1011
* @method static searchableRaw(string $sql)
1112
* @method static searchableJson(string $tableName) // sqlite, mysql
1213
*/
13-
final class Column implements \Livewire\Wireable
14+
final class Column implements Wireable
1415
{
1516
use Macroable;
1617

@@ -81,7 +82,7 @@ public static function add(): self
8182
*/
8283
public static function make(string $title, string $field, string $dataField = ''): self
8384
{
84-
return (new static())
85+
return (new Column())
8586
->title($title)
8687
->field($field, $dataField);
8788
}
@@ -91,7 +92,7 @@ public static function make(string $title, string $field, string $dataField = ''
9192
*/
9293
public static function action(string $title): self
9394
{
94-
return (new static())
95+
return (new Column())
9596
->title($title)
9697
->isAction()
9798
->visibleInExport(false);

src/Commands/Actions/AskComponentDatasource.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public static function handle(): string
1212
{
1313
// Must pass options as array<int, "label"> to
1414
// improve users experience when Laravel prompt falls back.
15-
$datasources = Datasource::asOptions();
15+
$datasource = Datasource::asOptions();
1616

1717
$choice = strval(select(
1818
label: 'Select your preferred Data source:',
19-
options: $datasources->values()->toArray(), // @phpstan-ignore-line
19+
options: $datasource->values()->toArray(), // @phpstan-ignore-line
2020
default: 0
2121
));
2222

2323
// Find and return they key based on user's choice.
24-
return (string) $datasources->filter(function ($item) use ($choice) {
24+
return (string) $datasource->filter(function ($item) use ($choice) {
2525
return $item === $choice;
2626
})->keys()[0];
2727
}

src/Commands/Actions/AskComponentName.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public static function handle(): string
3131
private static function checkIfComponentAlreadyExists(): void
3232
{
3333
if (File::exists(powergrid_components_path(self::$componentName . '.php'))) {
34-
$confirmation = (bool) confirm(
35-
"Component [" . self::$componentName . "] already exists. Overwrite it?",
34+
$confirmation = confirm(
35+
'Component [' . self::$componentName . '] already exists. Overwrite it?',
3636
default: false,
3737
hint: '❗ WARNING ❗'
3838
);

src/Commands/Actions/AskDatabaseTableName.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class AskDatabaseTableName
1111
public static function handle(): string
1212
{
1313
$tableExists = false;
14+
$tableName = '';
1415

1516
while (!$tableExists) {
1617
$tableName = suggest(

src/Commands/Actions/AskModelName.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ final class AskModelName
1515
*/
1616
public static function handle(): array
1717
{
18-
{
19-
while (self::$model === '') {
20-
self::setModel(suggest(
21-
label: 'Select a Model or enter its Fully qualified name.',
22-
options: ListModels::handle(),
23-
required: true,
24-
));
25-
}
26-
27-
return ['model' => self::$model, 'fqn' => self::$fqn];
18+
while (self::$model === '') {
19+
self::setModel(suggest(
20+
label: 'Select a Model or enter its Fully qualified name.',
21+
options: ListModels::handle(),
22+
required: true,
23+
));
2824
}
25+
26+
return ['model' => self::$model, 'fqn' => self::$fqn];
2927
}
3028

3129
private static function setModel(string $model): void

src/Commands/Actions/CheckIfDatabaseHasTables.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
namespace PowerComponents\LivewirePowerGrid\Commands\Actions;
44

5+
use Exception;
56
use Illuminate\Support\Facades\Schema;
67

78
final class CheckIfDatabaseHasTables
89
{
910
public static function handle(): bool
1011
{
1112
try {
12-
return count(Schema::getTables()) > 0 ? true : false;
13-
} catch (\Exception $e) {
13+
return count(Schema::getTables()) > 0;
14+
} catch (Exception) {
1415
return false;
1516
}
1617
}

src/Commands/Actions/GetStubVarsFromDbTable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public static function handle(PowerGridComponentMaker $component): array
8383
$columns .= ' Column::make(\'' . $title . '\', \'' . $field . '\')' . "\n" . ' ->sortable()' . "\n" . ' ->searchable(),' . "\n\n";
8484
}
8585

86-
$columns .= " ];";
87-
$filters .= " ];";
86+
$columns .= ' ];';
87+
$filters .= ' ];';
8888

8989
return [
9090
'PowerGridFields' => $datasource,

src/Commands/Actions/GetStubVarsFromFromModel.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PowerComponents\LivewirePowerGrid\Commands\Actions;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\Schema;
67
use Illuminate\Support\Str;
78
use PowerComponents\LivewirePowerGrid\Commands\Support\PowerGridComponentMaker;
@@ -15,7 +16,7 @@ class GetStubVarsFromFromModel
1516
*/
1617
public static function handle(PowerGridComponentMaker $component): array
1718
{
18-
/** @var \Illuminate\Database\Eloquent\Model $model*/
19+
/** @var Model $model */
1920
$model = new $component->modelFqn();
2021

2122
$getFillable = $model->getFillable();
@@ -106,8 +107,8 @@ public static function handle(PowerGridComponentMaker $component): array
106107

107108
$columns .= ' Column::action(\'Action\')' . "\n";
108109

109-
$columns .= " ];";
110-
$filters .= " ];";
110+
$columns .= ' ];';
111+
$filters .= ' ];';
111112

112113
return [
113114
'PowerGridFields' => $datasource,

src/Commands/Actions/ListDatabaseTables.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PowerComponents\LivewirePowerGrid\Commands\Actions;
44

5+
use Exception;
56
use Illuminate\Support\Facades\Schema;
67

78
final class ListDatabaseTables
@@ -18,8 +19,8 @@ public static function handle(): array
1819
return array_values(collect(Schema::getTables())
1920
->pluck('name')
2021
->diff(self::HIDDEN_TABLES)
21-
->toArray());
22-
} catch (\Exception $e) {
22+
->all());
23+
} catch (Exception) {
2324
return [];
2425
}
2526
}

src/Commands/Actions/ListModels.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
namespace PowerComponents\LivewirePowerGrid\Commands\Actions;
44

55
use Illuminate\Support\Facades\File;
6+
use ReflectionClass;
7+
use ReflectionException;
68
use Symfony\Component\Finder\SplFileInfo;
79

810
final class ListModels
911
{
1012
/**
1113
* List files in Models
12-
*
1314
*/
1415
public static function handle(): array
1516
{
1617
$directories = config('livewire-powergrid.auto_discover_models_paths', [app_path('Models')]);
1718

18-
/** @var Array<int,string> $directories */
19+
/** @var array<int,string> $directories */
1920
return collect($directories)
2021
->filter(fn (string $directory) => File::exists($directory))
2122
->map(fn (string $directory) => File::allFiles($directory))
@@ -33,8 +34,10 @@ public static function handle(): array
3334
->filter()
3435

3536
// Remove classes that do not extend an Eloquent Model
36-
/** @phpstan-ignore-next-line */
37-
->reject(fn (string $fqnClass) => rescue(fn () => (new \ReflectionClass($fqnClass))->isSubclassOf(\Illuminate\Database\Eloquent\Model::class), false) === false)
38-
->toArray();
37+
/** @phpstan-ignore-next-line
38+
* @throws ReflectionException
39+
*/
40+
->reject(fn (string $fqnClass) => rescue(fn () => (new ReflectionClass($fqnClass))->isSubclassOf(\Illuminate\Database\Eloquent\Model::class), false) === false)
41+
->all();
3942
}
4043
}

src/Commands/Actions/ParseFqnClassInCode.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
namespace PowerComponents\LivewirePowerGrid\Commands\Actions;
44

5+
use Exception;
6+
57
final class ParseFqnClassInCode
68
{
79
/**
810
* Parse namespace from PHP source code
911
* Inspired by: https://gist.github.com/ludofleury/1886076
10-
* @throws \Exception
12+
* @throws Exception
1113
*/
1214
public static function handle(string $sourceCode): string
1315
{
1416
if (preg_match('#^namespace\s+(.+?);.*class\s+(\w+).+;$#sm', $sourceCode, $matches)) {
1517
return $matches[1] . '\\' . $matches[2];
1618
}
1719

18-
throw new \Exception('could not find a FQN Class is source-code');
20+
throw new Exception('could not find a FQN Class is source-code');
1921
}
2022
}

src/Commands/Actions/SanitizeComponentName.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public static function handle(string $componentName): string
1515
//Convert multiple spaces into forward slashes
1616
->replaceMatches('/\s+/', '//')
1717
//multiple back slashes into forward slashes
18-
->replaceMatches('/\\\{2,}/', "\\")
18+
->replaceMatches('/\\\{2,}/', '\\')
1919
//Multiple forward slashes
20-
->replaceMatches('/\/{2,}/', "\\")
20+
->replaceMatches('/\/{2,}/', '\\')
2121
//Multile dots
22-
->replaceMatches('/\.{2,}/', ".")
22+
->replaceMatches('/\.{2,}/', '.')
2323
->replace('.', '\\')
2424
//Left over backslahes into forward slashes
2525
->replace('/', '\\')

src/Commands/CreateCommand.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PowerComponents\LivewirePowerGrid\Commands;
44

5+
use Exception;
56
use Illuminate\Console\Command;
67

78
use function Laravel\Prompts\{error, info, note};
@@ -34,17 +35,17 @@ public function handle(): int
3435

3536
try {
3637
$this
37-
->step1()
38-
->step2()
39-
->step3()
40-
->step4()
41-
->step5()
42-
->step6()
43-
->save()
44-
->feedback();
38+
->step1()
39+
->step2()
40+
->step3()
41+
->step4()
42+
->step5()
43+
->step6()
44+
->save()
45+
->feedback();
4546

4647
return self::SUCCESS;
47-
} catch (\Exception $e) {
48+
} catch (Exception $e) {
4849
error($e->getMessage());
4950

5051
return self::FAILURE;
@@ -130,7 +131,7 @@ public function feedback(): void
130131

131132
note("💡 include the <comment>{$this->component?->name}</comment> component using the tag: <comment>{$this->component?->htmlTag}</comment>");
132133

133-
info("👍 Please consider <comment>⭐ starring ⭐</comment> <info>our repository. Visit: </info><comment>https://github.com/Power-Components/livewire-powergrid</comment>" . PHP_EOL);
134+
info('👍 Please consider <comment>⭐ starring ⭐</comment> <info>our repository. Visit: </info><comment>https://github.com/Power-Components/livewire-powergrid</comment>' . PHP_EOL);
134135
}
135136

136137
private function AutoImportLabel(): string

src/Commands/Enums/Datasource.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public static function from(string $datasource): mixed
2020
public function label(): string
2121
{
2222
return match ($this) {
23-
Datasource::ELOQUENT_BUILDER => "Eloquent Builder",
24-
Datasource::QUERY_BUILDER => "Query Builder",
25-
Datasource::COLLECTION => "Collection"
23+
Datasource::ELOQUENT_BUILDER => 'Eloquent Builder',
24+
Datasource::QUERY_BUILDER => 'Query Builder',
25+
Datasource::COLLECTION => 'Collection'
2626
};
2727
}
2828

@@ -70,7 +70,7 @@ public function stubTemplate(): string
7070
}
7171

7272
/**
73-
* Datasource with labels for dropdown select
73+
* Datasource with labels for dropdown select
7474
*
7575
* @return Collection<string,string>
7676
*/

src/Commands/InteractsWithVersions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InteractsWithVersions
2525
*/
2626
public function ensureLatestVersion(): array
2727
{
28-
$composer = Factory::create(new NullIo(), null, false);
28+
$composer = Factory::create(new NullIo());
2929
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
3030

3131
return $this->searchPackage($localRepo);
@@ -73,7 +73,7 @@ public function getLatestVersion(): string
7373

7474
/** @phpstan-ignore-next-line */
7575
$version = collect($package['packages']['power-components/livewire-powergrid'])
76-
->first()['version'];
76+
->first()['version'];
7777

7878
if (!is_string($version)) {
7979
throw new Exception('Error: could find PowerGrid version.');

0 commit comments

Comments
 (0)