InvalidSettingValueException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * Settings Manager
5
 *
6
 * @license http://opensource.org/licenses/MIT
7
 * @link https://github.com/caseyamcl/settings-manager
8
 * @package caseyamcl/settings-manager
9
 * @author Casey McLaughlin <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 *
14
 *  ------------------------------------------------------------------
15
 */
16
17
declare(strict_types=1);
18
19
namespace SettingsManager\Exception;
20
21
use RuntimeException;
22
use Throwable;
23
24
/**
25
 * Invalid Setting value exception
26
 *
27
 * Thrown when the user attempts to set an invalid values (e.g. a value that doesn't pass validation checks)
28
 *
29
 * @author Casey McLaughlin <[email protected]>
30
 */
31
class InvalidSettingValueException extends RuntimeException implements SettingException
32
{
33
    /**
34
     * @var array|string[]
35
     */
36
    private $errors;
37
38
    /**
39
     * InvalidSettingValueException constructor.
40
     *
41
     * @param string|array|string[] $messages  One ore more validation error messages
42
     * @param int $code
43
     * @param Throwable|null $previous
44
     */
45 6
    public function __construct($messages = "", int $code = 0, Throwable $previous = null)
46
    {
47 6
        $this->errors = (array) $messages;
48 6
        parent::__construct(implode(PHP_EOL, $this->errors), $code, $previous);
49 6
    }
50
51
    /**
52
     * @return array|string[]
53
     */
54 6
    public function getErrors(): array
55
    {
56 6
        return $this->errors;
57
    }
58
}
59