Completed
Pull Request — master (#210)
by Ryan
04:31 queued 01:32
created

create_pear_package.php ➔ replace_parameters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 51 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * PEAR package builder
4
 *
5
 * Inspired by Twig's create_pear_package.php.
6
 * @link https://raw.github.com/fabpot/Twig/master/bin/create_pear_package.php
7
 * @author Twig Team
8
 * @license BSD license
9
 */
10
11
if (!isset($argv[1]) || $argv[1] === '-h' || $argv[1] === '--help') {
12
	echo 'usage: php ' . $argv[0] . ' <version> <stability>' . PHP_EOL;
13
	echo PHP_EOL;
14
	echo '    version:' . PHP_EOL;
15
	echo '        Version of the package, in the form of major.minor.bug' . PHP_EOL;
16
	echo PHP_EOL;
17
	echo '    stability:' . PHP_EOL;
18
	echo '        One of alpha, beta, stable' . PHP_EOL;
19
	die();
20
}
21
22
if (!isset($argv[2])) {
23
	die('You must provide the stability (alpha, beta, or stable)');
24
}
25
26
$context = array(
27
	'date'          => gmdate('Y-m-d'),
28
	'time'          => gmdate('H:m:00'),
29
	'version'       => $argv[1],
30
	'api_version'   => $argv[1],
31
	'stability'     => $argv[2],
32
	'api_stability' => $argv[2],
33
);
34
35
$context['files'] = '';
36
$path = realpath(dirname(__FILE__).'/../library/Requests');
37
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38
	if (preg_match('/\.php$/', $file)) 	{
39
		$name = str_replace($path . DIRECTORY_SEPARATOR, '', $file);
40
		$name = str_replace(DIRECTORY_SEPARATOR, '/', $name);
41
		$context['files'][] = "\t\t\t\t\t" . '<file install-as="Requests/' . $name . '" name="' . $name . '" role="php" />';
42
	}
43
}
44
45
$context['files'] = implode("\n", $context['files']);
46
47
$template = file_get_contents(dirname(__FILE__).'/../package.xml.tpl');
48
$content = preg_replace_callback('/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/', 'replace_parameters', $template);
49
file_put_contents(dirname(__FILE__).'/../package.xml', $content);
50
51
function replace_parameters($matches) {
52
	global $context;
53
54
	return isset($context[$matches[1]]) ? $context[$matches[1]] : null;
55
}
56