NodeJsVersionsLister   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getList() 0 16 2
1
<?php
2
namespace Mouf\NodeJsInstaller;
3
4
use Composer\Composer;
5
use Composer\IO\IOInterface;
6
use Composer\Util\RemoteFilesystem;
7
8
/**
9
 * A class in charge of retrieving all the available versions of NodeJS.
10
 */
11
class NodeJsVersionsLister
12
{
13
    /**
14
     * @var IOInterface
15
     */
16
    private $io;
17
18
    protected $rfs;
19
20
    const NODEJS_DIST_URL = "https://nodejs.org/dist/";
21
22
    public function __construct(IOInterface $io, Composer $composer)
23
    {
24
        $this->io = $io;
25
        $this->rfs = new RemoteFilesystem($io, $composer->getConfig());
26
    }
27
28
    public function getList()
29
    {
30
        // Let's download the content of HTML page https://nodejs.org/dist/
31
        $html = $this->rfs->getContents(parse_url(self::NODEJS_DIST_URL, PHP_URL_HOST), self::NODEJS_DIST_URL, false);
0 ignored issues
show
Security Bug introduced by
It seems like parse_url(self::NODEJS_DIST_URL, PHP_URL_HOST) targeting parse_url() can also be of type false; however, Composer\Util\RemoteFilesystem::getContents() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
32
33
        // Now, let's parse it!
34
        $matches = array();
35
        preg_match_all("$>v([0-9]*\\.[0-9]*\\.[0-9]*)/<$", $html, $matches);
36
37
        if (!isset($matches[1])) {
38
            throw new NodeJsInstallerException("Error while querying ".self::NODEJS_DIST_URL.". Unable to find NodeJS
39
            versions on this page.");
40
        }
41
42
        return $matches[1];
43
    }
44
}
45