Completed
Push — master ( f25894...228057 )
by Robin
03:02
created

Exception::unknown()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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