Completed
Push — notifyhandler ( 1e7809...ebc1c0 )
by Robin
03:34
created

Exception::fromMap()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 3
crap 3
1
<?php
2
/**
3
 * Copyright (c) 2014 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\Exception;
9
10
class Exception extends \Exception {
11 510
	static public function unknown($path, $error) {
12 510
		$message = 'Unknown error (' . $error . ')';
13 510
		if ($path) {
14 2
			$message .= ' for ' . $path;
15 2
		}
16
17 510
		return new Exception($message, $error);
18
	}
19
20
	/**
21
	 * @param array $exceptionMap
22
	 * @param mixed $error
23
	 * @param string $path
24
	 * @return Exception
25
	 */
26 546
	static public function fromMap(array $exceptionMap, $error, $path) {
27 546
		if (isset($exceptionMap[$error])) {
28 74
			$exceptionClass = $exceptionMap[$error];
29 74
			if (is_numeric($error)) {
30 36
				return new $exceptionClass($path, $error);
31
			} else {
32 38
				return new $exceptionClass($path);
33
			}
34
		} else {
35 510
			return Exception::unknown($path, $error);
36
		}
37
	}
38
}
39