1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
5
|
|
|
*/ |
6
|
|
|
namespace Vaimo\ComposerChangelogs\Resolvers; |
7
|
|
|
|
8
|
|
|
class ReleaseDetailsResolver |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \Vaimo\ComposerChangelogs\Utils\DataUtils |
12
|
|
|
*/ |
13
|
|
|
private $dataUtils; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string[] |
17
|
|
|
*/ |
18
|
|
|
private $reservedKeys = array( |
19
|
|
|
'overview', |
20
|
|
|
'version', |
21
|
|
|
'branch', |
22
|
|
|
'summary', |
23
|
|
|
'overview-reduced', |
24
|
|
|
'link', |
25
|
|
|
'diff', |
26
|
|
|
'date', |
27
|
|
|
'time' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->dataUtils = new \Vaimo\ComposerChangelogs\Utils\DataUtils(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function resolveOverview(array $release) |
36
|
|
|
{ |
37
|
|
|
$overviewLines = isset($release['overview']) |
38
|
|
|
? $this->dataUtils->assureArrayValue($release['overview']) |
39
|
|
|
: array(); |
40
|
|
|
|
41
|
|
|
$reducedLines = explode(PHP_EOL, implode( |
42
|
|
|
' ', |
43
|
|
|
array_map(function ($line) { |
44
|
|
|
return !trim($line) ? PHP_EOL . PHP_EOL : $line; |
45
|
|
|
}, $overviewLines) |
46
|
|
|
)); |
47
|
|
|
|
48
|
|
|
$reducedLines = array_map('trim', $reducedLines); |
49
|
|
|
|
50
|
|
|
return array( |
51
|
|
|
'version' => isset($release['version']) ? $release['version'] : '', |
52
|
|
|
'overview' => $overviewLines, |
53
|
|
|
'summary' => isset($release['summary']) ? $release['summary'] : '', |
54
|
|
|
'overview-reduced' => $reducedLines, |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function resolveChangeGroups(array $release) |
59
|
|
|
{ |
60
|
|
|
return array_diff_key( |
61
|
|
|
$release, |
62
|
|
|
array_fill_keys($this->reservedKeys, true) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function resolveBranch(array $release) |
67
|
|
|
{ |
68
|
|
|
if (!isset($release['branch'])) { |
69
|
|
|
return ''; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $release['branch']; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|