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

Api   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateApi() 0 18 3
A downloadSami() 0 20 2
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