AbstractFileLoader   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 55
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBasePath() 0 4 1
A findAbsolutePath() 0 17 6
A findRelativePath() 0 8 2
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 3
    public function setBasePath($path)
28
    {
29 3
        $this->basePath = realpath($path);
30 3
    }
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
    protected function findRelativePath($path)
40
    {
41
        if (null !== $this->basePath) {
42
            return strtr($path, array($this->basePath . DIRECTORY_SEPARATOR => ''));
43
        }
44
45
        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 45
    protected function findAbsolutePath($path)
56
    {
57 45
        if (is_file($path) || is_dir($path)) {
58 42
            return realpath($path);
59
        }
60
61 6
        if (null === $this->basePath) {
62 4
            return false;
63
        }
64
65 3
        if (is_file($this->basePath . DIRECTORY_SEPARATOR . $path)
66 3
               || is_dir($this->basePath . DIRECTORY_SEPARATOR . $path)) {
67 3
            return realpath($this->basePath . DIRECTORY_SEPARATOR . $path);
68
        }
69
70 1
        return false;
71
    }
72
}
73