Completed
Push — master ( 2ec9f0...d428ee )
by Andrii
30:10 queued 22:08
created

PackageUtil::sort()   C

Complexity

Conditions 7
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 6.7272
cc 7
eloc 13
nc 1
nop 1
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