Passed
Push — develop ( 398536...a1b7f9 )
by Remco
05:03
created

render_changes()   D

Complexity

Conditions 9
Paths 10

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 17
nc 10
nop 2
dl 0
loc 25
rs 4.909
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
3
header( 'Content-Type: text/plain' );
4
5
$data      = file_get_contents( __DIR__ . '/../changelog.json' );
6
$changelog = json_decode( $data );
7
8
function render_changes( $changes, $level = 0 ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
9
	$indent = $level * 2;
10
11
	if ( is_string( $changes ) ) {
12
		echo str_repeat( ' ', $indent ), '- ', $changes, "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'str_repeat'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$changes'.
Loading history...
13
	} elseif ( is_array( $changes ) ) {
14
		foreach ( $changes as $change ) {
15
			render_changes( $change, $level );
16
		}
17
	} elseif ( is_object( $changes ) ) {
18
		if ( isset( $changes->name ) ) {
19
			// Changes group.
20
			echo "\r\n";
21
			echo '### ', $changes->name, "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$changes'.
Loading history...
22
23
			if ( isset( $changes->changes ) ) {
24
				render_changes( $changes->changes, $level );
25
			}
26
		} else {
27
			if ( isset( $changes->description ) ) {
28
				render_changes( $changes->description, $level );
29
			}
30
31
			if ( isset( $changes->changes ) ) {
32
				render_changes( $changes->changes, $level + 1 );
33
			}
34
		}
35
	}
36
}
37
38
?>
39
# Change Log
40
41
All notable changes to this project will be documented in this file.
42
43
This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com/).
44
45
<?php
46
47
foreach ( $changelog as $log ) {
48
	if ( 'Unreleased' === $log->version ) {
49
		echo '## [', $log->version, '][unreleased]', "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$log'.
Loading history...
50
	} else {
51
		echo '## [', $log->version, '] - ', $log->date, "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$log'.
Loading history...
52
	}
53
54
	render_changes( $log->changes );
55
56
	echo "\r\n";
57
}
58
59
$collection = new CachingIterator( new ArrayIterator( $changelog ), CachingIterator::TOSTRING_USE_CURRENT );
60
61
foreach ( $collection as $log ) {
62
	if ( $collection->hasNext() ) {
63
		$prev = $collection->getInnerIterator()->current();
64
65
		if ( 'Unreleased' === $log->version ) {
66
			echo '[unreleased]: https://github.com/pronamic/wp-pronamic-ideal/compare/', $prev->version, '...', 'HEAD', "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$prev'.
Loading history...
67
		} else {
68
			echo '[', $log->version, ']: https://github.com/pronamic/wp-pronamic-ideal/compare/', $prev->version, '...', $log->version, "\r\n";
0 ignored issues
show
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$log'.
Loading history...
introduced by
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$prev'.
Loading history...
69
		}
70
	}
71
}
72