InvalidSettingValueException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getErrors() 0 3 1
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