Passed
Push — master ( 77c83a...e9db12 )
by Arnaud
05:10
created

includeIfExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use Composer\Autoload\ClassLoader;
15
16
function includeIfExists(string $file): ?ClassLoader
17
{
18
    return file_exists($file) ? include $file : null;
19
}
20
21
// includes then returns autoloader
22
switch (true) {
23
    case ($loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')): // standalone
24
        break;
25
    case ($loader = includeIfExists(__DIR__ . '/../../../autoload.php')): // as a Composer dependency
26
        break;
27
    case ($loader = includeIfExists('vendor/autoload.php')): // as a Composer dependency, relative to CWD
28
        break;
29
    default:
30
        printf('You must set up the project dependencies using `composer install`%sSee https://getcomposer.org/download/ for instructions on installing Composer%s', PHP_EOL, PHP_EOL);
31
        exit(1);
32
}
33
34
return $loader;
35