Completed
Push — master ( 7ba91b...68752b )
by Tom
03:00
created

FilePath::loadFromPaths()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 3
eloc 3
nc 3
nop 1
1
<?php
2
namespace Transphporm;
3
class FilePath {
4
	private $paths = ['.'];
5
	private $baseDir;
6
7
	public function addPath($path) {
8
		$this->paths[] = rtrim($path, DIRECTORY_SEPARATOR);
9
	}
10
11
	public function setBaseDir($baseDir) {
12
		$this->baseDir = $baseDir;
13
	}
14
15
	public function getFilePath($filePath) {
16
		if (is_file($filePath)) return $filePath;
17
		else if (is_file($this->baseDir . DIRECTORY_SEPARATOR . $filePath)) return $this->baseDir . DIRECTORY_SEPARATOR . $filePath;
18
		else return $this->loadFromPaths($filePath); 
19
20
		throw new \Exception($filePath . ' not found in include path: ' . implode(';', $this->paths));
0 ignored issues
show
Unused Code introduced by
throw new \Exception($fi...de(';', $this->paths)); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
21
	}
22
23
	private function loadFromPaths($filePath) {
24
		foreach ($this->paths as $path) {
25
			if (is_file($path . DIRECTORY_SEPARATOR . $filePath)) return $path . DIRECTORY_SEPARATOR . $filePath;
26
		}
27
	}
28
}
29