Skip to content

Commit

Permalink
Moved tools to contracts, moved traits and Moved the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-chetan committed Oct 10, 2024
1 parent 28fc893 commit aad64ab
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
APP_NAME=Revive
APP_VERSION=3.0.2
APP_VERSION=3.0.3
2 changes: 1 addition & 1 deletion app/Actions/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Actions;

use App\Support\Tool;
use App\Contracts\Tool;
use Illuminate\Console\Command;

class Clean
Expand Down
6 changes: 3 additions & 3 deletions app/Commands/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Commands;

use App\Support\ConfiguresForLintOrFix;
use App\Support\GetsCleaner;
use App\Concerns\ConfiguresForLintOrFix;
use App\Concerns\GetsCleaner;
use Exception;
use LaravelZero\Framework\Commands\Command;
use LaravelZero\Framework\Exceptions\ConsoleException;
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions app/Commands/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Commands;

use App\Support\ConfiguresForLintOrFix;
use App\Support\GetsCleaner;
use App\Concerns\ConfiguresForLintOrFix;
use App\Concerns\GetsCleaner;
use Exception;
use LaravelZero\Framework\Commands\Command;
use LaravelZero\Framework\Exceptions\ConsoleException;
Expand All @@ -30,7 +30,7 @@ public function handle(): int
} catch (Exception $exception) {
$this->error($exception->getMessage());

return 1;
return Command::FAILURE;
}
}
}
20 changes: 6 additions & 14 deletions app/Support/Tool.php → app/Concerns/CommandHelpers.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
<?php

namespace App\Support;
namespace App\Concerns;

use function Termwind\render;

abstract class Tool
trait CommandHelpers
{
public function __construct(
protected ReviveConfig $reviveConfig,
) {}

abstract public function lint(): int;

abstract public function fix(): int;

public function heading(string $heading): void
public function success(string $message): void
{
render('<div class="font-bold bg-yellow-800 px-1">=> ' . $heading . '</div>');
render('<div class="text-green-900 bg-green-300 px-1 font-bold">>> success: ' . $message . '</div>');
}

public function success(string $message): void
public function heading(string $heading): void
{
render('<div class="text-green-900 bg-green-300 px-1 font-bold">>> success: ' . $message . '</div>');
render('<div class="font-bold bg-yellow-800 px-1">=> ' . $heading . '</div>');
}

public function failure(string $message): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Support;
namespace App\Concerns;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -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
9 changes: 8 additions & 1 deletion app/Support/GetsCleaner.php → app/Concerns/GetsCleaner.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?php

namespace App\Support;
namespace App\Concerns;

use App\Actions\Clean;
use App\Contracts\Tool;
use App\Support\ReviveConfig;
use App\Support\PhpCodeSniffer;
use App\Support\PhpCsFixer;
use App\Support\Pint;
use App\Support\TLint;
use App\Support\UserScript;

trait GetsCleaner
{
Expand Down
19 changes: 19 additions & 0 deletions app/Contracts/Tool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Contracts;

use App\Concerns\CommandHelpers;
use App\Support\ReviveConfig;

abstract class Tool
{
use CommandHelpers;

public function __construct(
protected ReviveConfig $reviveConfig,
) {}

abstract public function lint(): int;

abstract public function fix(): int;
}
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
2 changes: 1 addition & 1 deletion app/Providers/ReviveServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ReviveServiceProvider extends ServiceProvider
{
public function register()
public function register(): void
{
$this->app->singleton(ReviveConfig::class, function () {
$input = $this->app->get(InputInterface::class);
Expand Down
10 changes: 9 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 @@ -11,10 +13,14 @@ public function __construct(
protected $path,
protected $preset,
protected array $exclude
) {}
) {
parent::__construct($path, $preset);
}

/**
* @return array<string, array<int, string>|string>
*
* @throws JsonException
*/
protected function get(): array
{
Expand All @@ -29,6 +35,8 @@ protected function get(): array

/**
* @return array<string, array<int, string>|string>
*
* @throws JsonException
*/
protected function getPintConfig(): array
{
Expand Down
1 change: 1 addition & 0 deletions app/Support/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Support;

use App\Contracts\Tool;
use App\Project;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Runner;
Expand Down
2 changes: 1 addition & 1 deletion app/Support/PhpCsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Support;

use App\Actions\ElaborateSummary;
use App\Contracts\Tool;
use App\Project;
use ArrayIterator;
use PhpCsFixer\Config;
use PhpCsFixer\ConfigInterface;
use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
use PhpCsFixer\Console\ConfigurationResolver;
Expand Down
1 change: 1 addition & 0 deletions app/Support/Pint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Actions\ElaborateSummary;
use App\Actions\FixCode;
use App\Commands\DefaultCommand;
use App\Contracts\Tool;

class Pint extends Tool
{
Expand Down
Loading

0 comments on commit aad64ab

Please sign in to comment.