/
Composer.php
42 lines (37 loc) · 1.13 KB
/
Composer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Psalm\Internal;
use function basename;
use function getenv;
use function pathinfo;
use function substr;
use function trim;
use const PATHINFO_EXTENSION;
/**
* @internal
*/
final class Composer
{
/**
* Retrieve the path to composer.json file.
*
* @see https://github.com/composer/composer/blob/5df1797d20c6ab1eb606dc0f0d76a16ba57ddb7f/src/Composer/Factory.php#L233
*/
public static function getJsonFilePath(string $root): string
{
$file_name = getenv('COMPOSER') ?: 'composer.json';
$file_name = basename(trim($file_name));
return $root . '/' . $file_name;
}
/**
* Retrieve the path to composer.lock file.
*
* @see https://github.com/composer/composer/blob/5df1797d20c6ab1eb606dc0f0d76a16ba57ddb7f/src/Composer/Factory.php#L238
*/
public static function getLockFilePath(string $root): string
{
$composer_json_path = static::getJsonFilePath($root);
return "json" === pathinfo($composer_json_path, PATHINFO_EXTENSION)
? substr($composer_json_path, 0, -4).'lock'
: $composer_json_path . '.lock';
}
}