-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Helldar
committed
Feb 10, 2022
1 parent
fa56056
commit 12bc0b6
Showing
15 changed files
with
312 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
.idea/ | ||
vendor/ | ||
|
||
*.bak | ||
*.cache | ||
*.clover | ||
*.orig | ||
|
||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); | ||
|
||
use DragonCode\CodeStyler\Application; | ||
use DragonCode\CodeStyler\Services\Check; | ||
use DragonCode\CodeStyler\Services\Dependabot; | ||
use DragonCode\CodeStyler\Services\EditorConfig; | ||
use DragonCode\CodeStyler\Services\Fix; | ||
|
||
$possible_files = [ | ||
__DIR__ . '/../../../autoload.php', | ||
__DIR__ . '/../../autoload.php', | ||
__DIR__ . '/../vendor/autoload.php', | ||
]; | ||
|
||
$file = null; | ||
|
||
foreach ($possible_files as $possible_file) { | ||
if (file_exists($possible_file)) { | ||
$file = $possible_file; | ||
break; | ||
} | ||
} | ||
|
||
if (is_null($file)) { | ||
throw new RuntimeException('Unable to locate autoload.php file.'); | ||
} | ||
|
||
require_once $file; | ||
|
||
$script = $argv[1] ?? null; | ||
|
||
$processor = match ($script) { | ||
'check' => Check::class, | ||
'fix' => Fix::class, | ||
'dependabot' => Dependabot::class, | ||
'editorconfig' => EditorConfig::class, | ||
default => null | ||
}; | ||
|
||
if (empty($processor)) { | ||
$script = empty($script) ? '(empty)' : $script; | ||
|
||
echo 'ERROR: ⚠️Unknown script parameter: ' . $script; | ||
|
||
exit(1); | ||
} | ||
|
||
Application::make()->process($processor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "dragon-code/codestyler", | ||
"description": "A tool to automatically fix PHP Coding Standards issues by Dragon Code.", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Andrey Helldar", | ||
"email": "helldar@ai-rus.com" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"ext-yaml": "*", | ||
"dragon-code/support": "^5.7", | ||
"friendsofphp/php-cs-fixer": "^3.6" | ||
}, | ||
"minimum-stability": "stable", | ||
"autoload": { | ||
"psr-4": { | ||
"DragonCode\\CodeStyler\\": "src" | ||
} | ||
}, | ||
"bin": [ | ||
"bin/codestyler" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\CodeStyler; | ||
|
||
use DragonCode\CodeStyler\Contracts\Processor; | ||
use DragonCode\Support\Concerns\Makeable; | ||
|
||
class Application | ||
{ | ||
use Makeable; | ||
|
||
public function process(string $class): void | ||
{ | ||
$this->resolve($class)->run(); | ||
} | ||
|
||
protected function resolve(string $class): Processor | ||
{ | ||
return new $class(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\CodeStyler\Contracts; | ||
|
||
interface Processor | ||
{ | ||
public function run(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\CodeStyler\Services; | ||
|
||
class Check extends CodeStyler | ||
{ | ||
protected array $options_check = [ | ||
'--dry-run' => true, | ||
'--diff' => true, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\CodeStyler\Services; | ||
|
||
use Composer\XdebugHandler\XdebugHandler; | ||
use DragonCode\CodeStyler\Contracts\Processor; | ||
use DragonCode\Support\Facades\Helpers\Ables\Arrayable; | ||
use PhpCsFixer\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
|
||
abstract class CodeStyler implements Processor | ||
{ | ||
protected const ENV_PREFIX = 'PHP_CS_FIXER'; | ||
|
||
protected array $options = [ | ||
'path' => __DIR__, | ||
'fix' => true, | ||
'--config' => __DIR__ . '/../../config/rules.php', | ||
'--ansi' => true, | ||
]; | ||
|
||
protected array $options_check = []; | ||
|
||
public function run(): void | ||
{ | ||
$this->xdebug(); | ||
$this->styler(); | ||
} | ||
|
||
protected function xdebug(): void | ||
{ | ||
$xdebug = new XdebugHandler(self::ENV_PREFIX); | ||
$xdebug->check(); | ||
|
||
unset($xdebug); | ||
} | ||
|
||
protected function styler(): void | ||
{ | ||
$application = new Application(); | ||
$application->run($this->getArgv()); | ||
} | ||
|
||
protected function getArgv(): ArgvInput | ||
{ | ||
return new ArgvInput( | ||
$this->resolveOptions() | ||
); | ||
} | ||
|
||
protected function resolveOptions(): array | ||
{ | ||
return Arrayable::of($this->getOptions()) | ||
->map(static function (mixed $value, string $key) { | ||
if (is_bool($value)) { | ||
return $key; | ||
} | ||
|
||
return sprintf('%s=%s', $key, $value); | ||
}) | ||
->values() | ||
->get(); | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return array_merge($this->options, $this->options_check); | ||
} | ||
} |
Oops, something went wrong.