Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 5d65600

Browse files
committed
refactor(lint): Format code with pint
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent de6cb82 commit 5d65600

File tree

14 files changed

+187
-179
lines changed

14 files changed

+187
-179
lines changed

src/Console/Commands/DisableCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public function handle()
1616
$pluginId = $plugin['id'];
1717
$pluginName = $plugin['name'] ?? $pluginId;
1818

19-
if (!($plugin['enabled'] ?? false)) {
19+
if (! ($plugin['enabled'] ?? false)) {
2020
$this->info("Plugin [{$pluginName}] is already disabled.");
21+
2122
return 0;
2223
}
2324

24-
2525
// Update the plugin's enabled status
26-
$manifestPath = $plugin['path'] . '/plugin.json';
26+
$manifestPath = $plugin['path'].'/plugin.json';
2727
$manifest = json_decode(file_get_contents($manifestPath), true);
2828
$manifest['enabled'] = false;
29-
29+
3030
file_put_contents(
3131
$manifestPath,
3232
json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
@@ -41,6 +41,7 @@ public function handle()
4141
return 0;
4242
} catch (\RuntimeException $e) {
4343
$this->error($e->getMessage());
44+
4445
return 1;
4546
}
4647
}

src/Console/Commands/DiscoverCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ class DiscoverCommand extends PluginCommand
1111
public function handle()
1212
{
1313
$this->info('Discovering plugins...');
14-
14+
1515
$plugins = $this->pluginManager->discover();
16-
16+
1717
if ($plugins->isEmpty()) {
1818
$this->warn('No plugins found.');
19+
1920
return 0;
2021
}
2122

22-
$this->info("Discovered {$plugins->count()} " . str('plugin')->plural($plugins->count()) . ".");
23-
23+
$this->info("Discovered {$plugins->count()} ".str('plugin')->plural($plugins->count()).'.');
24+
2425
// Trigger registration of plugins
2526
$this->pluginManager->registerPlugins();
26-
27+
2728
$this->info('Plugins discovered and registered successfully.');
28-
29+
2930
return 0;
3031
}
3132
}

src/Console/Commands/EnableCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ public function handle()
1818

1919
if (($plugin['enabled'] ?? false)) {
2020
$this->info("Plugin [{$pluginName}] is already enabled.");
21+
2122
return 0;
2223
}
2324

2425
// Update the plugin's enabled status
25-
$manifestPath = $plugin['path'] . '/plugin.json';
26+
$manifestPath = $plugin['path'].'/plugin.json';
2627
$manifest = json_decode(file_get_contents($manifestPath), true);
2728
$manifest['enabled'] = true;
28-
29+
2930
file_put_contents(
3031
$manifestPath,
3132
json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
@@ -40,6 +41,7 @@ public function handle()
4041
return 0;
4142
} catch (\RuntimeException $e) {
4243
$this->error($e->getMessage());
44+
4345
return 1;
4446
}
4547
}

src/Console/Commands/InfoCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function handle()
5555
return 0;
5656
} catch (\RuntimeException $e) {
5757
$this->error($e->getMessage());
58+
5859
return 1;
5960
}
6061
}

src/Console/Commands/InstallCommand.php

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,164 +2,162 @@
22

33
namespace Trakli\PluginEngine\Console\Commands;
44

5-
use Illuminate\Support\Facades\Http;
65
use Illuminate\Support\Str;
7-
use RuntimeException;
86
use Symfony\Component\Process\Process;
9-
use ZipArchive;
107

118
class InstallCommand extends PluginCommand
129
{
1310
protected $signature = 'plugin:install
1411
{package : The package name (vendor/name) or URL of the plugin to install}
1512
{--dev : Install development dependencies}'
16-
. '{--no-dev : Do not install development dependencies}'
17-
. '{--no-scripts : Skip running installation scripts}'
18-
. '{--no-plugins : Skip installing plugins}'
19-
. '{--no-scripts : Skip running scripts}'
20-
. '{--prefer-source : Install packages from source when possible}'
21-
. '{--prefer-dist : Install packages from dist when possible}'
22-
. '{--optimize-autoloader : Optimize autoloader during autoloader dump}'
23-
. '{--classmap-authoritative : Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`}'
24-
. '{--apcu-autoloader : Use APCu to cache found/not-found classes}';
13+
.'{--no-dev : Do not install development dependencies}'
14+
.'{--no-scripts : Skip running installation scripts}'
15+
.'{--no-plugins : Skip installing plugins}'
16+
.'{--no-scripts : Skip running scripts}'
17+
.'{--prefer-source : Install packages from source when possible}'
18+
.'{--prefer-dist : Install packages from dist when possible}'
19+
.'{--optimize-autoloader : Optimize autoloader during autoloader dump}'
20+
.'{--classmap-authoritative : Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`}'
21+
.'{--apcu-autoloader : Use APCu to cache found/not-found classes}';
2522

2623
protected $description = 'Install a plugin';
2724

2825
public function handle()
2926
{
3027
$package = $this->argument('package');
31-
28+
3229
try {
3330
$this->info("Installing plugin: {$package}");
34-
31+
3532
// Check if it's a URL or a package name
3633
if (filter_var($package, FILTER_VALIDATE_URL)) {
3734
return $this->installFromUrl($package);
3835
}
39-
36+
4037
// Otherwise, treat as a Composer package
4138
return $this->installWithComposer($package);
42-
39+
4340
} catch (\Exception $e) {
44-
$this->error("Failed to install plugin: " . $e->getMessage());
41+
$this->error('Failed to install plugin: '.$e->getMessage());
4542
if ($this->getOutput()->isVerbose()) {
4643
$this->error($e->getTraceAsString());
4744
}
45+
4846
return 1;
4947
}
5048
}
51-
49+
5250
protected function installFromUrl(string $url): int
5351
{
5452
$this->info("Downloading plugin from URL: {$url}");
55-
53+
5654
// Extract the plugin name from the URL or generate a random one
5755
$pluginName = basename(parse_url($url, PHP_URL_PATH), '.git');
5856
$pluginName = preg_replace('/[^a-z0-9\-_]/i', '', $pluginName);
59-
57+
6058
if (empty($pluginName)) {
61-
$pluginName = 'plugin-' . Str::random(8);
59+
$pluginName = 'plugin-'.Str::random(8);
6260
}
63-
64-
$tempDir = sys_get_temp_dir() . '/trakli-plugin-' . Str::random(8);
61+
62+
$tempDir = sys_get_temp_dir().'/trakli-plugin-'.Str::random(8);
6563
mkdir($tempDir, 0755, true);
66-
64+
6765
try {
6866
// Clone the repository
6967
$process = new Process(['git', 'clone', '--depth', '1', $url, $tempDir]);
7068
$process->setTimeout(300);
7169
$process->run();
72-
73-
if (!$process->isSuccessful()) {
70+
71+
if (! $process->isSuccessful()) {
7472
throw new \RuntimeException($process->getErrorOutput());
7573
}
76-
74+
7775
// Install the plugin
7876
return $this->installFromPath($tempDir, $pluginName);
79-
77+
8078
} finally {
8179
// Clean up
8280
$this->removeDirectory($tempDir);
8381
}
8482
}
85-
83+
8684
protected function installWithComposer(string $package): int
8785
{
8886
$this->info("Installing plugin using Composer: {$package}");
89-
87+
9088
// Build the Composer command
9189
$command = array_merge(
9290
['composer', 'require', $package],
9391
$this->getComposerOptions()
9492
);
95-
93+
9694
$process = new Process($command, base_path(), null, null, null);
9795
$process->setTty(Process::isTtySupported());
98-
96+
9997
$process->run(function ($type, $buffer) {
10098
$this->output->write($buffer);
10199
});
102-
103-
if (!$process->isSuccessful()) {
100+
101+
if (! $process->isSuccessful()) {
104102
throw new \RuntimeException("Failed to install package: {$package}");
105103
}
106-
104+
107105
return 0;
108106
}
109-
107+
110108
protected function installFromPath(string $path, string $pluginName): int
111109
{
112110
$pluginsPath = config('plugins.path', base_path('plugins'));
113-
$targetPath = rtrim($pluginsPath, '/') . '/' . $pluginName;
114-
111+
$targetPath = rtrim($pluginsPath, '/').'/'.$pluginName;
112+
115113
// Create plugins directory if it doesn't exist
116-
if (!is_dir($pluginsPath)) {
114+
if (! is_dir($pluginsPath)) {
117115
mkdir($pluginsPath, 0755, true);
118116
}
119-
117+
120118
// Check if plugin already exists
121119
if (is_dir($targetPath)) {
122120
throw new \RuntimeException("Plugin directory already exists: {$targetPath}");
123121
}
124-
122+
125123
// Move the plugin to the plugins directory
126124
rename($path, $targetPath);
127-
125+
128126
$this->info("Plugin installed successfully to: {$targetPath}");
129-
127+
130128
// Run plugin discovery
131129
$this->call('plugin:discover');
132-
130+
133131
return 0;
134132
}
135-
133+
136134
protected function getComposerOptions(): array
137135
{
138136
$options = [];
139-
137+
140138
// Add boolean options
141139
foreach (['dev', 'no-dev', 'no-scripts', 'no-plugins', 'prefer-source', 'prefer-dist', 'optimize-autoloader', 'classmap-authoritative', 'apcu-autoloader'] as $option) {
142140
if ($this->option($option)) {
143-
$options[] = '--' . $option;
141+
$options[] = '--'.$option;
144142
}
145143
}
146-
144+
147145
return $options;
148146
}
149-
147+
150148
protected function removeDirectory(string $directory): bool
151149
{
152-
if (!is_dir($directory)) {
150+
if (! is_dir($directory)) {
153151
return false;
154152
}
155-
153+
156154
$files = array_diff(scandir($directory), ['.', '..']);
157-
155+
158156
foreach ($files as $file) {
159-
$path = $directory . '/' . $file;
157+
$path = $directory.'/'.$file;
160158
is_dir($path) ? $this->removeDirectory($path) : unlink($path);
161159
}
162-
160+
163161
return rmdir($directory);
164162
}
165163
}

src/Console/Commands/ListCommand.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,24 @@ public function handle()
2222
return 0;
2323
}
2424

25-
2625
$rows = [];
2726

2827
foreach ($plugins as $plugin) {
2928
$validation = $this->pluginManager->validatePlugin($plugin);
3029
$pluginId = $validation['id'] ?? 'unknown';
3130
$error = $validation['error'] ?? null;
32-
31+
3332
// Set status based on validation
3433
if ($error) {
3534
$hasErrors = true;
3635
$status = '<fg=yellow>Error</>';
3736
$errorMessages[] = "Plugin {$pluginId}: {$error}";
3837
} else {
3938
$status = $plugin['enabled'] ? '<fg=green>Enabled</>' : '<fg=red>Disabled</>';
40-
39+
4140
// Additional debug checks for valid plugins
42-
if ($debug && !empty($plugin['provider'])) {
43-
if (!class_exists($plugin['provider'])) {
41+
if ($debug && ! empty($plugin['provider'])) {
42+
if (! class_exists($plugin['provider'])) {
4443
$error = "Provider class not found: {$plugin['provider']}";
4544
$status = '<fg=yellow>Error</>';
4645
$errorMessages[] = "Plugin {$pluginId}: {$error}";
@@ -65,7 +64,7 @@ public function handle()
6564

6665
if ($hasErrors) {
6766
$this->warn('Some plugins have errors. Use --debug for more details.');
68-
67+
6968
if ($debug) {
7069
$this->line('');
7170
$this->warn('Detailed errors:');

0 commit comments

Comments
 (0)