Completed
Pull Request — master (#88)
by Julius
02:39
created

AbstractShare::verifyPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * Copyright (c) 2015 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB;
9
10
use Icewind\SMB\Exception\InvalidPathException;
11
12
abstract class AbstractShare implements IShare {
13
	private $forbiddenCharacters;
14
15 1028
	public function __construct() {
16 1028
		$this->forbiddenCharacters = ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"];
17 1028
	}
18
19 1024
	protected function verifyPath($path) {
20 1024
		foreach ($this->forbiddenCharacters as $char) {
21 1024
			if (strpos($path, $char) !== false) {
22 692
				throw new InvalidPathException('Invalid path, "' . $char . '" is not allowed');
23
			}
24
		}
25 1024
	}
26
27
	public function setForbiddenChars(array $charList) {
28
		$this->forbiddenCharacters = $charList;
29
	}
30
}
31