Skip to content

Commit

Permalink
Merge pull request #160 from msamgan/minor-fixes
Browse files Browse the repository at this point in the history
Minor Fix and types.
  • Loading branch information
driftingly authored Sep 30, 2024
2 parents df3ebe1 + 9328a1b commit 519dbcc
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/Commands/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle(): int
} catch (Exception $exception) {
$this->error($exception->getMessage());

return 1;
return Command::FAILURE;
}
}
}
17 changes: 3 additions & 14 deletions app/Commands/GitHubActionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,16 +48,4 @@ public function handle(): int

return Command::SUCCESS;
}

private function success(string $message): void
{
render(<<<HTML
<div class="py-1 ml-2">
<div class="px-1 bg-green-300 text-black">Success</div>
<em class="ml-1">
{$message}
</em>
</div>
HTML);
}
}
23 changes: 6 additions & 17 deletions app/Commands/HuskyHooksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -80,16 +81,4 @@ protected function runCommands(array $commands): void
$this->output->write(' ' . $line);
});
}

private function success(string $message): void
{
render(<<<HTML
<div class="py-1 ml-2">
<div class="px-1 bg-green-300 text-black">Success</div>
<em class="ml-1">
{$message}
</em>
</div>
HTML);
}
}
2 changes: 1 addition & 1 deletion app/Commands/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle(): int
} catch (Exception $exception) {
$this->error($exception->getMessage());

return 1;
return Command::FAILURE;
}
}
}
13 changes: 13 additions & 0 deletions app/Concerns/CommandHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Concerns;

use function Termwind\render;

trait CommandHelpers
{
public function success(string $message): void
{
render('<div class="text-green-900 bg-green-300 px-1 font-bold">>> success: ' . $message . '</div>');
}
}
2 changes: 1 addition & 1 deletion app/Providers/DusterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/PintServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class PintServiceProvider extends ServiceProvider
{
public function register()
public function register(): void
{
$this->app->singleton(ErrorsManager::class, fn () => new ErrorsManager);

Expand Down
11 changes: 10 additions & 1 deletion app/Repositories/PintConfigurationJsonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Repositories;

use JsonException;

class PintConfigurationJsonRepository extends ConfigurationJsonRepository
{
/**
Expand All @@ -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, array<int, string>|string>
*
* @throws JsonException
*/
protected function get(): array
{
Expand All @@ -28,6 +35,8 @@ protected function get(): array

/**
* @return array<string, array<int, string>|string>
*
* @throws JsonException
*/
protected function getPintConfig(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Support/ConfiguresForLintOrFix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 19 additions & 16 deletions app/Support/DusterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use JsonException;
use Symfony\Component\Finder\Finder;

class DusterConfig
Expand All @@ -29,22 +30,6 @@ public function __construct(
$this->config = static::scopeConfigPaths($this->config);
}

/**
* @return array<string, mixed>
*/
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, array<int, string>|string> $config
* @return array<string, array<int, string>|string>
Expand Down Expand Up @@ -125,6 +110,24 @@ public static function globPath(string $path): array
}
}

/**
* @return array<string, mixed>
*
* @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);
Expand Down
8 changes: 8 additions & 0 deletions app/Support/TLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) . '"';
Expand Down
20 changes: 18 additions & 2 deletions app/Support/UserScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +19,9 @@ public function __construct(
protected string $name,
protected array $command,
protected DusterConfig $dusterConfig,
) {}
) {
parent::__construct($dusterConfig);
}

public function lint(): int
{
Expand All @@ -24,13 +30,23 @@ public function lint(): int
return $this->process();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws JsonException
*/
public function fix(): int
{
$this->heading('Fixing using ' . $this->name);

return $this->process();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws JsonException
*/
private function process(): int
{
$dusterConfig = DusterConfig::loadLocal();
Expand All @@ -46,7 +62,7 @@ private function process(): int
} catch (ProcessTimedOutException $e) {
$this->failure($e->getMessage() . '<br />You can overwrite this timeout with the processTimeout key in your duster.json file.');

return 1;
return Command::FAILURE;
}
}
}

0 comments on commit 519dbcc

Please sign in to comment.