|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Roave\ApiCompare\Formatter; |
|
5
|
|
|
|
|
6
|
|
|
use Roave\ApiCompare\Change; |
|
7
|
|
|
use Roave\ApiCompare\Changes; |
|
8
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class MarkdownPipedToSymfonyConsoleFormatter implements OutputFormatter |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var ConsoleOutputInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
private $output; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(OutputInterface $output) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->output = $output; |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function write(Changes $changes) : void |
|
24
|
|
|
{ |
|
25
|
|
|
$arrayOfChanges = $changes->getIterator()->getArrayCopy(); |
|
26
|
|
|
|
|
27
|
|
|
$this->output->writeln( |
|
28
|
|
|
"# Added\n" |
|
29
|
|
|
. implode('', $this->convertFilteredChangesToMarkdownBulletList( |
|
30
|
|
|
function (Change $change) : bool { |
|
31
|
|
|
return $change->isAdded(); |
|
32
|
|
|
}, |
|
33
|
|
|
...$arrayOfChanges |
|
34
|
|
|
)) |
|
35
|
|
|
. "\n# Changed\n" |
|
36
|
|
|
. implode('', $this->convertFilteredChangesToMarkdownBulletList( |
|
37
|
|
|
function (Change $change) : bool { |
|
38
|
|
|
return $change->isChanged(); |
|
39
|
|
|
}, |
|
40
|
|
|
...$arrayOfChanges |
|
41
|
|
|
)) |
|
42
|
|
|
. "\n# Removed\n" |
|
43
|
|
|
. implode('', $this->convertFilteredChangesToMarkdownBulletList( |
|
44
|
|
|
function (Change $change) : bool { |
|
45
|
|
|
return $change->isRemoved(); |
|
46
|
|
|
}, |
|
47
|
|
|
...$arrayOfChanges |
|
48
|
|
|
)) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function convertFilteredChangesToMarkdownBulletList(callable $filterFunction, Change ...$changes) : array |
|
53
|
|
|
{ |
|
54
|
|
|
return array_map( |
|
55
|
|
|
function (Change $change) : string { |
|
56
|
|
|
return ' - ' . str_replace(['ADDED: ', 'CHANGED: ', 'REMOVED: '], '', trim((string)$change)) . "\n"; |
|
57
|
|
|
}, |
|
58
|
|
|
array_filter($changes, $filterFunction) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.