AbstractShare::verifyPath()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 6.7968

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 1
cts 4
cp 0.25
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 6.7968
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
	/** @var string[] */
14
	private $forbiddenCharacters;
15 982
16 982
	public function __construct() {
17 982
		$this->forbiddenCharacters = ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"];
18
	}
19 980
20 980
	/**
21 980
	 * @param string $path
22 342
	 * @throws InvalidPathException
23
	 */
24
	protected function verifyPath(string $path): void {
25 980
		foreach ($this->forbiddenCharacters as $char) {
26
			if (strpos($path, $char) !== false) {
27
				throw new InvalidPathException('Invalid path, "' . $char . '" is not allowed');
28
			}
29
		}
30
	}
31
32
	/**
33
	 * @param string[] $charList
34
	 */
35
	public function setForbiddenChars(array $charList): void {
36
		$this->forbiddenCharacters = $charList;
37
	}
38
}
39