functions.php ➔ package_configs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace Composed;
3
4
define(__NAMESPACE__ . '\VENDOR_DIR', Internal\findVendorDir());
5
define(__NAMESPACE__ . '\BASE_DIR', Internal\findBaseDir(VENDOR_DIR));
6
7
function packages($includeRoot = true) : PackageCollection
8
{
9
    return $includeRoot ? project()->getPackages() : project()->getLockFile()->getPackages();
10
}
11
12
/**
13
 * @return null|AbstractPackage
14
 */
15
function package($name, $graceful = false)
16
{
17
    $package = packages()->getPackage($name);
18
19
    if (!$graceful && !$package) {
20
        throw new \OutOfBoundsException('The specified package does not appear to be installed.');
21
    }
22
23
    return $package;
24
}
25
26
function package_configs($keys = [], $default = null) : array
0 ignored issues
show
Unused Code introduced by
The parameter $keys is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $default is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
{
28
    /**
29
     * If $default is not explicitly provided, it should not be passed to Package::getConfig(),
30
     * hence not simply calling getConfig($keys, $default), as explicitly passing $default = null
31
     * to getConfig() is different to omitting it
32
     */
33
    return packages()->getConfig(...func_get_args());
34
}
35
36
/**
37
 * @return mixed
38
 */
39
function package_config(string $packageName, $keys = [], $default = null)
40
{
41
    return package($packageName)->getConfig($keys, $default);
42
}
43
44
/**
45
 * @return mixed
46
 */
47
function project_config($keys = [], $default = null)
48
{
49
    return project()->getConfig($keys, $default);
50
}
51
52
function project(RootPackage $assign = null) : RootPackage
53
{
54
    static $project;
55
56
    if ($assign) {
57
        $project = $assign;
58
    } elseif (!$project) {
59
        $project = RootPackage::createFromPath(BASE_DIR);
60
    }
61
62
    return $project;
63
}
64