muyassarov/php-project-lvl2

View on GitHub
bin/gendiff

Summary

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

<?php

use function Differ\Differ\genDiff;

$autoloadPaths = [
    __DIR__ . '/../../../autoload.php',
    __DIR__ . '/../vendor/autoload.php'
];
foreach ($autoloadPaths as $autoloadPath) {
    if (file_exists($autoloadPath)) {
        require_once $autoloadPath;
        break;
    }
}

$doc = <<<DOC
Generate diff

Usage:
  gendiff (-h|--help)
  gendiff (-v|--version)
  gendiff [--format <fmt>] <firstFile> <secondFile>

Options:
  -h --help                     Show this screen
  -v --version                  Show version
  --format <fmt>                Report format [default: pretty]
DOC;

$args = Docopt::handle($doc, ['version' => '1.0']);
['<firstFile>' => $filepath1, '<secondFile>' => $filepath2, '--format' => $format] = $args;

$diff = genDiff($filepath1, $filepath2, $format);
print_r($diff);