Completed
Push — master ( 59ed89...26050b )
by Daniel
13:12 queued 13:12
created

AssetNotFoundException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 48
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 5
A getAsset() 0 3 1
A getSite() 0 3 1
1
<?php
2
/**
3
 * CMS Pico - Create websites using Pico CMS for Nextcloud.
4
 *
5
 * @copyright Copyright (c) 2017, Maxence Lange (<[email protected]>)
6
 * @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>)
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
declare(strict_types=1);
25
26
namespace OCA\CMSPico\Exceptions;
27
28
class AssetNotFoundException extends \Exception
29
{
30
	/** @var string|null */
31
	private $site;
32
33
	/** @var string|null */
34
	private $asset;
35
36
	/**
37
	 * AssetNotFoundException constructor.
38
	 *
39
	 * @param string|null     $site
40
	 * @param string|null     $asset
41
	 * @param \Exception|null $previous
42
	 */
43
	public function __construct(string $site = null, string $asset = null, \Exception $previous = null)
44
	{
45
		$this->site = $site;
46
		$this->asset = $asset;
47
48
		$message = '';
49
		if ($site && $asset) {
50
			$message = sprintf("Unable to access asset '%s' of website '%s': No such asset", $asset, $site);
51
		} elseif ($previous) {
52
			$message = $previous->getMessage();
53
		}
54
55
		if ($previous) {
56
			parent::__construct($message, $previous->getCode(), $previous);
57
		} else {
58
			parent::__construct($message);
59
		}
60
	}
61
62
	/**
63
	 * @return string|null
64
	 */
65
	public function getSite(): ?string
66
	{
67
		return $this->site;
68
	}
69
70
	/**
71
	 * @return string|null
72
	 */
73
	public function getAsset(): ?string
74
	{
75
		return $this->asset;
76
	}
77
}
78