Completed
Push — stable3.0 ( 04db6f )
by Robin
03:38
created

Exception   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 29
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromMap() 0 12 3
A unknown() 0 8 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 3
	static public function unknown($path, $error) {
12 3
		$message = 'Unknown error (' . $error . ')';
13 3
		if ($path) {
14 3
			$message .= ' for ' . $path;
15
		}
16
17 3
		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 79
	static public function fromMap(array $exceptionMap, $error, $path) {
27 79
		if (isset($exceptionMap[$error])) {
28 79
			$exceptionClass = $exceptionMap[$error];
29 79
			if (is_numeric($error)) {
30 19
				return new $exceptionClass($path, $error);
31
			} else {
32 60
				return new $exceptionClass($path);
33
			}
34
		} else {
35 3
			return Exception::unknown($path, $error);
36
		}
37
	}
38
}
39