release.php ➔ exclaim()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env 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 9 and the first side effect is on line 1.

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
<?php
4
5
/**
6
 * Highlights important output
7
 * @param string $msg
8
 */
9
function exclaim($msg)
10
{
11
    echo "\n\033[1;36m" . $msg . "\033[0m\n";
12
}
13
14
date_default_timezone_set('America/New_York');
15
$date = date('Y-m-d');
16
17
/* Get version number of latest releases */
18
$products = file_get_contents('http://code.highcharts.com/products.js');
19
preg_match_all('/\d\.\d+\.\d+/', $products, $matches);
20
$ver = $matches[0][0];
21
$stockVer = $matches[0][1];
22
$mapsVer = $matches[0][2];
23
24
/* Prompt for version numbers */
25
echo "\nEnter the HIGHCHARTS version [$ver]: ";
26
$ver = trim(fgets(STDIN)) ?: $ver;
27
echo "\nEnter the HIGHSTOCK version [$stockVer]: ";
28
$stockVer = trim(fgets(STDIN)) ?: $stockVer;
29
echo "\nEnter the HIGHMAPS version [$mapsVer]: ";
30
$mapsVer = trim(fgets(STDIN)) ?: $mapsVer;
31
32
33
exclaim("Fetching archives");
34
$dir = dirname(dirname(__FILE__)) . '/highcharts/assets';
35
if (!is_dir($dir) || !chdir($dir)) {
36
    echo "Error: Directory '$dir' is inaccessible.\n";
37
    return false;
38
}
39
40
echo `
41
rm -rfv $dir/*
42
wget http://code.highcharts.com/zips/Highcharts-$ver.zip
43
wget http://code.highcharts.com/zips/Highstock-$stockVer.zip
44
wget http://code.highcharts.com/zips/Highmaps-$mapsVer.zip
45
unzip Highcharts-$ver.zip js/\*
46
unzip -n Highstock-$stockVer.zip js/\*
47
unzip -n Highmaps-$mapsVer.zip js/\*
48
mv js/* .
49
rmdir js
50
rm *.zip
51
`;
52
53
54
exclaim("Purging extraneous assets");
55
echo `rm -rfv parts* *debug* .htaccess`;
56
57
58
exclaim("Creating missing src files");
59
echo `
60
for file in $(find . -name '*.js' ! -name '*.src.js'); do 
61
     cp -nv "\$file" \${file%.js}.src.js
62
done
63
`;
64
65
exclaim("Updating Changelog");
66
$fileName = dirname(dirname(__FILE__)) . '/CHANGELOG.md';
67
$changelogLink = " See the Highcharts [changelog](http://highcharts.com/documentation/changelog) for more information about what's new in this version.";
68
$changelogEntry = "### [v$ver](https://github.com/miloschuman/yii-highcharts/releases/tag/v$ver) ($date) ###\n"
69
    . "* Upgraded Highcharts JS library to the latest release ($ver).$changelogLink";
70
$contents = file_get_contents($fileName);
71
$contents = str_replace($changelogLink, '', $contents);
72
$contents = str_replace("===\n", "===\n\n$changelogEntry\n", $contents);
73
file_put_contents($fileName, $contents);
74
75
76
exclaim("Done, bitch!");
77
exclaim("Don't forget to UPDATE README.md!");
78