-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolymorphine-csfixer
More file actions
86 lines (72 loc) · 2.65 KB
/
Copy pathpolymorphine-csfixer
File metadata and controls
86 lines (72 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env php
<?php declare(strict_types=1);
/*
* This file is part of Polymorphine/Dev package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
$argv or exit('CLI script executable');
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
set_error_handler(static function (int $severity, string $message, string $file, int $line): bool {
if ($severity & error_reporting()) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
return true;
});
if (PHP_VERSION_ID === 80000) {
fwrite(STDERR, 'PHP CS Fixer is not able run on PHP 8.0.0 due to bug in PHP tokenizer');
exit(1);
}
require_once (getcwd() === __DIR__ ? __DIR__ : dirname(__DIR__, 3)) . '/vendor/autoload.php';
// Restart if xdebug is loaded, unless the environment variable PHP_CS_FIXER_ALLOW_XDEBUG is set.
(new Composer\XdebugHandler\XdebugHandler('PHP_CS_FIXER'))->check();
$fixer = new CSFixerScript();
switch ($argv[1] ?? '') {
case '--version':
case 'list-sets':
$exitCode = $fixer->runScript($argv);
break;
case 'fix':
$exitCode = $fixer->fileInspection($argv);
break;
case '--fix':
$exitCode = $fixer->fixFiles($argv);
break;
default:
$exitCode = $fixer->checkFiles($argv);
}
exit($exitCode);
class CSFixerScript
{
private const CONFIG = '--config=' . __DIR__ . DIRECTORY_SEPARATOR . 'cs-fixer.php';
private const CLI_ARGS = [self::CONFIG, '--path-mode=intersection', '--show-progress=none', 'fix'];
public function fileInspection(array $args): int
{
$args[2] = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $args[2]);
$args[3] = self::CONFIG;
Polymorphine\Dev\FixerSetup::init(getcwd(), $args[2]);
return $this->runScript([...$args, '--path-mode=intersection']);
}
public function checkFiles(array $args): int
{
$files = count($args) > 1 ? [$args[1]] : ['src', 'tests'];
Polymorphine\Dev\FixerSetup::init(getcwd(), $files[0]);
return $this->runScript([$args[0], '--dry-run', '-v', ...self::CLI_ARGS, ...$files]);
}
public function fixFiles(array $args): int
{
$files = count($args) > 2 ? [$args[2]] : ['src', 'tests'];
Polymorphine\Dev\FixerSetup::init(getcwd(), $files[0]);
return $this->runScript([$args[0], ...self::CLI_ARGS, ...$files]);
}
public function runScript(array $args): int
{
$_SERVER['argv'] = $args;
$fixer = new PhpCsFixer\Console\Application();
$fixer->setAutoExit(false);
return $fixer->run();
}
}