AbstractShare::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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