Passed
Push — master ( af331f...aba9bd )
by Sander
01:58
created

PathHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAbsolutePath() 0 10 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the composer-link plugin.
7
 *
8
 * Copyright (c) 2021-2022 Sander Visser <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE.md
11
 * file that was distributed with this source code.
12
 *
13
 * @link https://github.com/SanderSander/composer-link
14
 */
15
16
namespace ComposerLink;
17
18
use InvalidArgumentException;
19
20
class PathHelper
21
{
22
    protected string $path;
23
24
    protected string $absolutePath;
25
26
    public function __construct(string $path)
27
    {
28
        $this->path = $path;
29
    }
30
31
    public function getAbsolutePath(string $workingDirectory): string
32
    {
33
        $real = realpath($workingDirectory . DIRECTORY_SEPARATOR . $this->path);
34
        if ($real === false) {
35
            throw new InvalidArgumentException(
36
                sprintf('Cannot resolve absolute path to %s.', $this->path)
37
            );
38
        }
39
40
        return $real;
41
    }
42
}
43