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

WebsiteInvalidDataException::__construct()   B

Complexity

Conditions 9
Paths 10

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
ccs 0
cts 23
cp 0
rs 8.0555
c 0
b 0
f 0
cc 9
nc 10
nop 4
crap 90
1
<?php
2
/**
3
 * CMS Pico - Create websites using Pico CMS for Nextcloud.
4
 *
5
 * @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>)
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
declare(strict_types=1);
24
25
namespace OCA\CMSPico\Exceptions;
26
27
class WebsiteInvalidDataException extends \Exception
28
{
29
	/** @var string|null */
30
	private $site;
31
32
	/** @var string|null */
33
	private $field;
34
35
	/** @var string|null */
36
	private $error;
37
38
	/**
39
	 * WebsiteInvalidDataException constructor.
40
	 *
41
	 * @param string|null     $site
42
	 * @param string|null     $field
43
	 * @param string|null     $error
44
	 * @param \Throwable|null $previous
45
	 */
46
	public function __construct(
47
		string $site = null,
48
		string $field = null,
49
		string $error = null,
50
		\Throwable $previous = null
51
	) {
52
		$this->site = $site;
53
		$this->field = $field;
54
		$this->error = $error;
55
56
		$message = '';
57
		if ($site && $field && $error) {
58
			$message = sprintf("Unable to modify website '%s': Invalid data given for '%s': %s", $site, $field, $error);
59
		} elseif ($site && $field) {
60
			$message = sprintf("Unable to modify website '%s': Invalid data given for '%s'", $site, $field);
61
		} elseif ($site) {
62
			$message = sprintf("Unable to modify website '%s': Invalid data given", $site);
63
		} elseif ($previous) {
64
			$message = $previous->getMessage();
65
		}
66
67
		if ($previous) {
68
			parent::__construct($message, $previous->getCode(), $previous);
69
		} else {
70
			parent::__construct($message);
71
		}
72
	}
73
74
	/**
75
	 * @return string|null
76
	 */
77
	public function getSite(): ?string
78
	{
79
		return $this->site;
80
	}
81
82
	/**
83
	 * @return string|null
84
	 */
85
	public function getField(): ?string
86
	{
87
		return $this->field;
88
	}
89
90
	/**
91
	 * @return string|null
92
	 */
93
	public function getError(): ?string
94
	{
95
		return $this->error;
96
	}
97
}
98