| Total Complexity | 6 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | class JailedPath |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var bool |
||
| 25 | */ |
||
| 26 | private $hasJailbreakAttempt = false; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $jailPath; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $relativePath; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $jail Trusted path, e.g. on a local or remote file system. |
||
| 40 | * @param mixed $path Untrusted user input which gets normalised. |
||
| 41 | */ |
||
| 42 | 38 | public function __construct($jail, $path) |
|
| 43 | { |
||
| 44 | 38 | $virtualPath = new VirtualPath($path); |
|
| 45 | |||
| 46 | 38 | $this->jailPath = (string)$jail; |
|
| 47 | 38 | $this->relativePath = ltrim($virtualPath, '/'); |
|
| 48 | 38 | $this->hasJailbreakAttempt = !$virtualPath->isTrusted(); |
|
| 49 | 38 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | 38 | public function getAbsolutePath() |
|
| 55 | { |
||
| 56 | 38 | return $this->relativePath === '' |
|
| 57 | 38 | ? $this->jailPath |
|
| 58 | 38 | : rtrim($this->jailPath, '/') . '/' . $this->relativePath; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | 38 | public function getJailPath() |
|
| 65 | { |
||
| 66 | 38 | return $this->jailPath; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | 38 | public function getRelativePath() |
|
| 73 | { |
||
| 74 | 38 | return $this->relativePath; |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return bool |
||
| 79 | */ |
||
| 80 | 38 | public function hasJailbreakAttempt() |
|
| 83 | } |
||
| 84 | } |
||
| 85 |