yavictor/php-project-lvl2

View on GitHub
bin/gendiff

Summary

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

<?php

$autoloadPath1 = __DIR__ . '/../../../autoload.php';
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';

if (file_exists($autoloadPath1)) {
    require_once $autoloadPath1;
} else {
    require_once $autoloadPath2;
}

use function Differ\Differ\genDiff;

$doc = <<<'DOCOPT'
Generate diff

Usage:
  gendiff (-h|--help)
  gendiff (-v|--version)
  gendiff [--format <fmt>] <firstFile> <secondFile>
  
Options:
  -h --help                     Show this screen
  -v --version                  Show version
  -f --format <fmt>                Report format [default: stylish]

Report formats:
  <fmt>
      stylish                Show changes in files marked with symbols "+/-" 
      plain                  Show changes in files explained by the text
      json                   Show changes in files as a JSON string
DOCOPT;

$config = Docopt::handle($doc, ['version' => 'gendiff 1.0.0']);
[
  '<firstFile>' => $firstFile,
  '<secondFile>' => $secondFile,
  '--format' => $format
] = $config;
$result = gendiff($firstFile, $secondFile, $format);
print_r(($result));