Completed
Push — master ( f2b88f...192e2c )
by Christophe
04:09
created

AbstractFileLoader::findAbsolutePath()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.0494

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
rs 8.8571
cc 6
eloc 9
nc 4
nop 1
crap 6.0494
1
<?php
2
3
/*
4
 * This file is part of the Behat Gherkin.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\Gherkin\Loader;
12
13
/**
14
 * Abstract filesystem loader.
15
 *
16
 * @author Konstantin Kudryashov <[email protected]>
17
 */
18
abstract class AbstractFileLoader implements FileLoaderInterface
19
{
20
    protected $basePath;
21
22
    /**
23
     * Sets base features path.
24
     *
25
     * @param string $path Base loader path
26
     */
27 2
    public function setBasePath($path)
28
    {
29 2
        $this->basePath = realpath($path);
30 2
    }
31
32
    /**
33
     * Finds relative path for provided absolute (relative to base features path).
34
     *
35
     * @param string $path Absolute path
36
     *
37
     * @return string
38
     */
39 34
    protected function findRelativePath($path)
40
    {
41 34
        if (null !== $this->basePath) {
42 1
            return strtr($path, array($this->basePath . DIRECTORY_SEPARATOR => ''));
43
        }
44
45 33
        return $path;
46
    }
47
48
    /**
49
     * Finds absolute path for provided relative (relative to base features path).
50
     *
51
     * @param string $path Relative path
52
     *
53
     * @return string
54
     */
55 39
    protected function findAbsolutePath($path)
56
    {
57 39
        if (is_file($path) || is_dir($path)) {
58 37
            return realpath($path);
59
        }
60
61 4
        if (null === $this->basePath) {
62 2
            return false;
63
        }
64
65 2
        if (is_file($this->basePath . DIRECTORY_SEPARATOR . $path)
66 2
               || is_dir($this->basePath . DIRECTORY_SEPARATOR . $path)) {
67 2
            return realpath($this->basePath . DIRECTORY_SEPARATOR . $path);
68
        }
69
70
        return false;
71
    }
72
}
73