PackageUtil   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 27
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B sort() 0 24 7
1
<?php
2
/**
3
 * Asset Packagist.
4
 *
5
 * @link      https://github.com/hiqdev/asset-packagist
6
 * @package   asset-packagist
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\assetpackagist\components;
12
13
use Composer\Semver\Comparator;
14
use Composer\Semver\VersionParser;
15
16
class PackageUtil
17
{
18
    public static function sort(&$releases)
19
    {
20
        uasort($releases, function ($a, $b) {
21
            if ($a['version'] === $b['version']) {
22
                return 0;
23
            }
24
25
            $stability_a = VersionParser::parseStability($a['version_normalized']);
26
            $stability_b = VersionParser::parseStability($b['version_normalized']);
27
28
            // DEV versions to LAST
29
            if ($stability_a === 'dev' && $stability_b !== 'dev') {
30
                return 1;
31
            } elseif ($stability_a !== 'dev' && $stability_b === 'dev') {
32
                return -1;
33
            }
34
35
            if (Comparator::lessThan($a['version_normalized'], $b['version_normalized'])) {
36
                return 1;
37
            }
38
39
            return -1;
40
        });
41
    }
42
}
43