diff --git a/app/Commands/FixCommand.php b/app/Commands/FixCommand.php
index c7c7f3d..50e8220 100644
--- a/app/Commands/FixCommand.php
+++ b/app/Commands/FixCommand.php
@@ -30,7 +30,7 @@ public function handle(): int
} catch (Exception $exception) {
$this->error($exception->getMessage());
- return 1;
+ return Command::FAILURE;
}
}
}
diff --git a/app/Commands/GitHubActionsCommand.php b/app/Commands/GitHubActionsCommand.php
index 96c37a4..ffc568f 100644
--- a/app/Commands/GitHubActionsCommand.php
+++ b/app/Commands/GitHubActionsCommand.php
@@ -2,13 +2,14 @@
namespace App\Commands;
+use App\Concerns\CommandHelpers;
use Illuminate\Support\Str;
use LaravelZero\Framework\Commands\Command;
-use function Termwind\render;
-
class GitHubActionsCommand extends Command
{
+ use CommandHelpers;
+
protected $signature = 'github-actions';
protected $description = 'Publish GitHub Actions';
@@ -47,16 +48,4 @@ public function handle(): int
return Command::SUCCESS;
}
-
- private function success(string $message): void
- {
- render(<<
-
Success
-
- {$message}
-
-
- HTML);
- }
}
diff --git a/app/Commands/HuskyHooksCommand.php b/app/Commands/HuskyHooksCommand.php
index 42bac65..917e16a 100644
--- a/app/Commands/HuskyHooksCommand.php
+++ b/app/Commands/HuskyHooksCommand.php
@@ -2,24 +2,23 @@
namespace App\Commands;
+use App\Concerns\CommandHelpers;
use LaravelZero\Framework\Commands\Command;
use RuntimeException;
use Symfony\Component\Process\Process;
-use function Termwind\render;
-
class HuskyHooksCommand extends Command
{
+ use CommandHelpers;
+
protected $signature = 'husky-hooks';
protected $description = 'Publish Husky Hooks';
/**
* Execute the console command.
- *
- * @return mixed
*/
- public function handle()
+ public function handle(): int
{
$choices = [
'Lint only' => 'lint',
@@ -57,6 +56,8 @@ public function handle()
$this->runCommands(["npx husky add ./.husky/pre-commit 'npx --no-install lint-staged'"]);
$this->success('Husky Pre-Commit Git Hook added');
+
+ return Command::SUCCESS;
}
/**
@@ -80,16 +81,4 @@ protected function runCommands(array $commands): void
$this->output->write(' ' . $line);
});
}
-
- private function success(string $message): void
- {
- render(<<
- Success
-
- {$message}
-
-
- HTML);
- }
}
diff --git a/app/Commands/LintCommand.php b/app/Commands/LintCommand.php
index 64031fb..20eed34 100644
--- a/app/Commands/LintCommand.php
+++ b/app/Commands/LintCommand.php
@@ -30,7 +30,7 @@ public function handle(): int
} catch (Exception $exception) {
$this->error($exception->getMessage());
- return 1;
+ return Command::FAILURE;
}
}
}
diff --git a/app/Concerns/CommandHelpers.php b/app/Concerns/CommandHelpers.php
new file mode 100644
index 0000000..418ee4d
--- /dev/null
+++ b/app/Concerns/CommandHelpers.php
@@ -0,0 +1,13 @@
+>> success: ' . $message . '');
+ }
+}
diff --git a/app/Providers/DusterServiceProvider.php b/app/Providers/DusterServiceProvider.php
index 2eacd80..9132088 100644
--- a/app/Providers/DusterServiceProvider.php
+++ b/app/Providers/DusterServiceProvider.php
@@ -9,7 +9,7 @@
class DusterServiceProvider extends ServiceProvider
{
- public function register()
+ public function register(): void
{
$this->app->singleton(DusterConfig::class, function () {
$input = $this->app->get(InputInterface::class);
diff --git a/app/Providers/PintServiceProvider.php b/app/Providers/PintServiceProvider.php
index b97e18e..969f4b0 100644
--- a/app/Providers/PintServiceProvider.php
+++ b/app/Providers/PintServiceProvider.php
@@ -23,7 +23,7 @@
class PintServiceProvider extends ServiceProvider
{
- public function register()
+ public function register(): void
{
$this->app->singleton(ErrorsManager::class, fn () => new ErrorsManager);
diff --git a/app/Repositories/PintConfigurationJsonRepository.php b/app/Repositories/PintConfigurationJsonRepository.php
index f3acfc8..bc5f948 100644
--- a/app/Repositories/PintConfigurationJsonRepository.php
+++ b/app/Repositories/PintConfigurationJsonRepository.php
@@ -2,6 +2,8 @@
namespace App\Repositories;
+use JsonException;
+
class PintConfigurationJsonRepository extends ConfigurationJsonRepository
{
/**
@@ -10,10 +12,15 @@ class PintConfigurationJsonRepository extends ConfigurationJsonRepository
public function __construct(
protected $path,
protected $preset,
- protected array $exclude) {}
+ protected array $exclude)
+ {
+ parent::__construct($path, $preset);
+ }
/**
* @return array|string>
+ *
+ * @throws JsonException
*/
protected function get(): array
{
@@ -28,6 +35,8 @@ protected function get(): array
/**
* @return array|string>
+ *
+ * @throws JsonException
*/
protected function getPintConfig(): array
{
diff --git a/app/Support/ConfiguresForLintOrFix.php b/app/Support/ConfiguresForLintOrFix.php
index b2e48bf..96ca4e1 100644
--- a/app/Support/ConfiguresForLintOrFix.php
+++ b/app/Support/ConfiguresForLintOrFix.php
@@ -17,8 +17,8 @@ protected function configure(): void
new InputArgument(
name: 'path',
mode: InputArgument::IS_ARRAY,
- default: [(string) getcwd()],
description: 'The path to lint/fix',
+ default: [(string) getcwd()],
),
new InputOption(
name: 'using',
diff --git a/app/Support/DusterConfig.php b/app/Support/DusterConfig.php
index 6230db1..f4c3389 100644
--- a/app/Support/DusterConfig.php
+++ b/app/Support/DusterConfig.php
@@ -6,6 +6,7 @@
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
+use JsonException;
use Symfony\Component\Finder\Finder;
class DusterConfig
@@ -29,22 +30,6 @@ public function __construct(
$this->config = static::scopeConfigPaths($this->config);
}
- /**
- * @return array
- */
- public static function loadLocal(): array
- {
- if (file_exists(Project::path() . '/duster.json')) {
- return tap(json_decode(file_get_contents(Project::path() . '/duster.json'), true, 512, JSON_THROW_ON_ERROR), function ($configuration) {
- if (! is_array($configuration)) {
- abort(1, 'The configuration file duster.json is not valid JSON.');
- }
- });
- }
-
- return [];
- }
-
/**
* @param array|string> $config
* @return array|string>
@@ -125,6 +110,24 @@ public static function globPath(string $path): array
}
}
+ /**
+ * @return array
+ *
+ * @throws JsonException
+ */
+ public static function loadLocal(): array
+ {
+ if (file_exists(Project::path() . '/duster.json')) {
+ return tap(json_decode(file_get_contents(Project::path() . '/duster.json'), true, 512, JSON_THROW_ON_ERROR), function ($configuration) {
+ if (! is_array($configuration)) {
+ abort(1, 'The configuration file duster.json is not valid JSON.');
+ }
+ });
+ }
+
+ return [];
+ }
+
public function get(string $key, mixed $default = null): mixed
{
return Arr::get($this->config, $key, $default);
diff --git a/app/Support/TLint.php b/app/Support/TLint.php
index 2fda156..778a89a 100644
--- a/app/Support/TLint.php
+++ b/app/Support/TLint.php
@@ -3,9 +3,12 @@
namespace App\Support;
use Illuminate\Console\Command;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
+use Throwable;
use Tighten\TLint\Commands\BaseCommand;
use Tighten\TLint\Commands\FormatCommand;
use Tighten\TLint\Commands\LintCommand;
@@ -60,6 +63,11 @@ private function executeCommand(BaseCommand $tlintCommand): bool
->isEmpty();
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws Throwable
+ * @throws NotFoundExceptionInterface
+ */
private function executeCommandOnPath(string $path, Application $application): int
{
$path = '"' . str_replace('\\', '\\\\', $path) . '"';
diff --git a/app/Support/UserScript.php b/app/Support/UserScript.php
index 0e44fbb..602b7c0 100644
--- a/app/Support/UserScript.php
+++ b/app/Support/UserScript.php
@@ -2,6 +2,10 @@
namespace App\Support;
+use Illuminate\Console\Command;
+use JsonException;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;
@@ -15,7 +19,9 @@ public function __construct(
protected string $name,
protected array $command,
protected DusterConfig $dusterConfig,
- ) {}
+ ) {
+ parent::__construct($dusterConfig);
+ }
public function lint(): int
{
@@ -24,6 +30,11 @@ public function lint(): int
return $this->process();
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws JsonException
+ */
public function fix(): int
{
$this->heading('Fixing using ' . $this->name);
@@ -31,6 +42,11 @@ public function fix(): int
return $this->process();
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws JsonException
+ */
private function process(): int
{
$dusterConfig = DusterConfig::loadLocal();
@@ -46,7 +62,7 @@ private function process(): int
} catch (ProcessTimedOutException $e) {
$this->failure($e->getMessage() . '
You can overwrite this timeout with the processTimeout key in your duster.json file.');
- return 1;
+ return Command::FAILURE;
}
}
}