Passed
Branch testing (4170e1)
by Stephan
09:32
created

write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
# Usage: php extensions/SimpleBatchUpload/tests/setup/fix-composer.php mediawiki/simple-batch-upload dev-master g/s7eph4n/SimpleBatchUpload < composer.local.json-sample > composer.local.json
3
#
4
# * Reads composer.json-like from stdin
5
# * Adds requirement for the specified composer package ($argv[1] and $argv[2]) and a repo ($argv[3])
6
# * Writes the result to stdout
7
#
8
# @copyright (C) 2016 - 2019, Stephan Gambke
9
# @license   GNU General Public License, version 2 (or any later version)
10
11
error_reporting( E_ALL | E_STRICT );
12
13
/**
14
 * @return string
15
 */
16
function read(): string {
17
	$in = '';
18
19
	while ( $f = fgets( STDIN ) ) {
20
		$in .= $f;
21
	}
22
23
	return $in;
24
}
25
26
/**
27
 * @param string $in
28
 * @param string[] $params
29
 *
30
 * @return array
31
 */
32
function process( string $in, array $params ) {
33
	$json = json_decode( $in, true );
34
35
	$json[ 'require' ][ $params[ 1 ] ] = $params[ 2 ];
36
37
	$json[ 'repositories' ] = [
38
		[
39
			'type' => 'vcs',
40
			'url'  => 'https://github.com' . substr( $params[ 3 ], 1 ) . '.git',
41
		],
42
	];
43
44
	return $json;
45
}
46
47
48
/**
49
 * @param $json
50
 */
51
function write( $json ) {
52
	print json_encode( $json, JSON_PRETTY_PRINT );
53
}
54
55
$in = read();
56
$out = process( $in, $argv );
57
write( $out );