LibraryPackage::version()   D
last analyzed

Complexity

Conditions 9
Paths 19

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 17
c 0
b 0
f 0
nc 19
nop 0
dl 0
loc 26
rs 4.909
1
<?php
2
/**
3
 * Licensed under The GPL-3.0 License
4
 * For full copyright and license information, please see the LICENSE.txt
5
 * Redistributions of files must retain the above copyright notice.
6
 *
7
 * @since    2.0.0
8
 * @author   Christopher Castro <[email protected]>
9
 * @link     http://www.quickappscms.org
10
 * @license  http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License
11
 */
12
namespace CMS\Core\Package;
13
14
/**
15
 * Represents a PHP library.
16
 *
17
 */
18
class LibraryPackage extends BasePackage
19
{
20
21
    /**
22
     * {@inheritdoc}
23
     *
24
     * Gets library version using `phpversion()` function if possible, an empty
25
     * string will be returned if no version could be found (library not installed).
26
     *
27
     * @return string Package's version, for instance `1.2.x-dev`
28
     */
29
    public function version()
30
    {
31
        if (parent::version() !== null) {
32
            return parent::version();
33
        }
34
35
        $this->_version = '';
36
        $lib = strtolower($this->_packageName);
37
38
        if ($lib === 'lib-icu') {
39
            $lib = 'intl';
40
        } elseif (stripos($lib, 'ext-') === 0) {
41
            $lib = substr($lib, 4);
42
        }
43
44
        if ($lib === 'php') {
45
            $this->_version = PHP_VERSION;
46
        } elseif (function_exists('phpversion')) {
47
            $version = phpversion($lib);
48
            $this->_version = $version === false ? '' : $version;
49
        } elseif (function_exists('extension_loaded')) {
50
            $this->_version = extension_loaded($lib) ? '99999' : '';
51
        }
52
53
        return $this->_version;
54
    }
55
}
56