| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace TypistTech\Imposter\Plugin; |
| 6 |
|
| 7 |
use Composer\IO\IOInterface; |
| 8 |
use TypistTech\Imposter\ImposterFactory; |
| 9 |
|
| 10 |
class Transformer |
| 11 |
{ |
| 12 |
public static function run(IOInterface $io): void |
| 13 |
{ |
| 14 |
// Print an empty line to separate imposter outputs. |
| 15 |
$io->write('', true); |
| 16 |
$io->write('', true); |
| 17 |
$io->write('<info>Running Imposter...</info>', true); |
| 18 |
$io->write('<info>======================</info>', true); |
| 19 |
$io->write('Loading package information from <comment>' . getcwd() . '/composer.json</comment>', true); |
| 20 |
|
| 21 |
$imposter = ImposterFactory::forProject(getcwd(), ['typisttech/imposter-plugin']); |
| 22 |
|
| 23 |
$autoloads = $imposter->getAutoloads(); |
| 24 |
$count = count($autoloads); |
| 25 |
$index = 1; |
| 26 |
foreach ($autoloads as $autoload) { |
| 27 |
$io->write(" - <comment>$index/$count</comment>: Transforming $autoload", true); |
| 28 |
$imposter->transform($autoload); |
| 29 |
$index++; |
| 30 |
} |
| 31 |
|
| 32 |
$io->write('<info>Success: Imposter transformed vendor files.</info>', true); |
| 33 |
|
| 34 |
$invalidAutoloads = $imposter->getInvalidAutoloads(); |
| 35 |
if (! empty($invalidAutoloads)) { |
| 36 |
$invalidAutoloadsCount = count($invalidAutoloads); |
| 37 |
$io->writeError('', true); |
| 38 |
$io->writeError( |
| 39 |
// phpcs:ignore Generic.Files.LineLength.TooLong |
| 40 |
"<warning>Warning: Imposter failed to transformed $invalidAutoloadsCount of the autoload path(s).</warning>", |
| 41 |
true |
| 42 |
); |
| 43 |
|
| 44 |
foreach ($invalidAutoloads as $invalidAutoload) { |
| 45 |
$io->writeError(" - $invalidAutoload", true); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// Print empty lines to separate imposter outputs. |
| 50 |
$io->write('', true); |
| 51 |
$io->write('', true); |
| 52 |
} |
| 53 |
} |
| 54 |
|