1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Roave\ApiCompare\Command; |
5
|
|
|
|
6
|
|
|
use Roave\ApiCompare\Comparator; |
7
|
|
|
use Roave\ApiCompare\Factory\DirectoryReflectorFactory; |
8
|
|
|
use Roave\ApiCompare\Formatter\SymfonyConsoleTextFormatter; |
9
|
|
|
use Roave\ApiCompare\Git\CheckedOutRepository; |
10
|
|
|
use Roave\ApiCompare\Git\PerformCheckoutOfRevision; |
11
|
|
|
use Roave\ApiCompare\Git\Revision; |
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
final class ApiCompare extends Command |
18
|
|
|
{ |
19
|
|
|
/** @var PerformCheckoutOfRevision */ |
20
|
|
|
private $git; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var DirectoryReflectorFactory |
24
|
|
|
*/ |
25
|
|
|
private $reflectorFactory; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param PerformCheckoutOfRevision $git |
29
|
|
|
* @param DirectoryReflectorFactory $reflectorFactory |
30
|
|
|
* @throws \Symfony\Component\Console\Exception\LogicException |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
PerformCheckoutOfRevision $git, |
34
|
|
|
DirectoryReflectorFactory $reflectorFactory |
35
|
|
|
) { |
36
|
|
|
parent::__construct(); |
37
|
|
|
$this->git = $git; |
38
|
|
|
$this->reflectorFactory = $reflectorFactory; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
43
|
|
|
*/ |
44
|
|
|
protected function configure() : void |
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->setName('api-compare:compare') |
48
|
|
|
->setDescription('List comparisons between class APIs') |
49
|
|
|
->addArgument('from', InputArgument::REQUIRED) |
50
|
|
|
->addArgument('to', InputArgument::REQUIRED) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param InputInterface $input |
56
|
|
|
* @param OutputInterface $output |
57
|
|
|
* @throws \Symfony\Component\Process\Exception\RuntimeException |
58
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
59
|
|
|
* @throws \Roave\BetterReflection\SourceLocator\Exception\InvalidFileInfo |
60
|
|
|
* @throws \Roave\BetterReflection\SourceLocator\Exception\InvalidDirectory |
61
|
|
|
*/ |
62
|
|
|
public function execute(InputInterface $input, OutputInterface $output) : void |
63
|
|
|
{ |
64
|
|
|
// @todo fix flaky assumption about the path of the source repo... |
65
|
|
|
$sourceRepo = CheckedOutRepository::fromPath(getcwd()); |
66
|
|
|
|
67
|
|
|
$fromPath = $this->git->checkout($sourceRepo, Revision::fromSha1($input->getArgument('from'))); |
68
|
|
|
$toPath = $this->git->checkout($sourceRepo, Revision::fromSha1($input->getArgument('to'))); |
69
|
|
|
|
70
|
|
|
// @todo fix hard-coded /src/ addition... |
71
|
|
|
try { |
72
|
|
|
(new SymfonyConsoleTextFormatter($output))->write( |
73
|
|
|
(new Comparator())->compare( |
74
|
|
|
$this->reflectorFactory->__invoke((string)$fromPath . '/src/'), |
75
|
|
|
$this->reflectorFactory->__invoke((string)$toPath . '/src/') |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} finally { |
79
|
|
|
$this->git->remove($fromPath); |
80
|
|
|
$this->git->remove($toPath); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|