Aeliot-Tm/php-cs-fixer-baseline

View on GitHub
bin/pcsf-baseline

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php

declare(strict_types=1);

/*
 * This file is part of the PHP CS Fixer Baseline project.
 *
 * (c) Anatoliy Melnikov <5785276@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

use Aeliot\PhpCsFixerBaseline\Model\BuilderConfig;
use Aeliot\PhpCsFixerBaseline\Service\Builder;
use Aeliot\PhpCsFixerBaseline\Service\ConsoleOptionsReader;
use Aeliot\PhpCsFixerBaseline\Service\Saver;

$autoloaderPath = (static function (): string {
    if (Phar::running()) {
        return __DIR__ . '/../vendor/autoload.php';
    }

    if (isset($GLOBALS['_composer_autoload_path'])) {
        return $GLOBALS['_composer_autoload_path'];
    }

    $paths = [
        __DIR__ . '/../../../../vendor/autoload.php',
        __DIR__ . '/../vendor/autoload.php',
        __DIR__ . '/../../vendor/autoload.php',
        __DIR__ . '/../../../vendor/autoload.php',
    ];

    foreach ($paths as $path) {
        if (file_exists($path)) {
            return $path;
        }
    }

    throw new RuntimeException('Cannot find autoloader');
})();

require_once $autoloaderPath;

$baseline = (new Builder())->create(new BuilderConfig((new ConsoleOptionsReader())->getAsArray()));
(new Saver())->save($baseline);

echo sprintf("Ok, %s files added to baseline\n", $baseline->getLockedFilesCount());