Completed
Push — master ( 192e2c...b945f9 )
by Christophe
02:46
created

AbstractFileLoader   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBasePath() 0 4 1
A findRelativePath() 0 8 2
B findAbsolutePath() 0 17 6
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 37
    protected function findRelativePath($path)
40
    {
41 37
        if (null !== $this->basePath) {
42 2
            return strtr($path, array($this->basePath . DIRECTORY_SEPARATOR => ''));
43
        }
44
45 35
        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 44
    protected function findAbsolutePath($path)
56
    {
57 44
        if (is_file($path) || is_dir($path)) {
58 41
            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