Completed
Push — master ( d7e2f2...f8494a )
by Cristiano
01:25
created

Api::generateApi()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php declare(strict_types=1);
2
3
namespace gossi\docblock\scripts;
4
5
/**
6
 * Class to generate api. Useful for composer script.
7
 */
8
class Api {
9
	public static function generateApi(): void {
10
		if (!file_exists('sami.phar')) {
11
			self::downloadSami();
12
		}
13
14
		if (strpos(phpversion(), '7.4') !== false) {
15
			die("
16
Sami cannot run on PHP 7.4 due to some deprecations.
17
If you have installed some other php versions, you could manually run it:
18
19
 php7.3 sami.phar update sami.php
20
21
"
22
			);
23
		}
24
25
		exec("php sami.phar update sami.php");
26
	}
27
28
	private static function downloadSami(): void {
29
		if (!extension_loaded('curl')) {
30
			die("
31
You should enable `curl` extensions in your php.ini, to download sami.
32
Alternatively, you can download it manually from http://get.sensiolabs.org/sami.phar
33
");
34
		}
35
36
		$fp = fopen('./sami.phar', 'wb');
37
38
		echo "Donload sami...";
39
		$ch = curl_init('http://get.sensiolabs.org/sami.phar');
40
		curl_setopt($ch, CURLOPT_FILE, $fp);
41
		curl_setopt($ch, CURLOPT_HEADER, 0);
42
		curl_exec($ch);
43
		curl_close($ch);
44
		echo "done!\n";
45
46
		fclose($fp);
47
	}
48
}
49