Skip to content

Commit 2cafec0

Browse files
committed
Added NestedObjectException
1 parent 02e347a commit 2cafec0

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace PHPModelGenerator\Exception\Object;
6+
7+
use Exception;
8+
use PHPModelGenerator\Exception\ValidationException;
9+
10+
/**
11+
* Class NotAllowedAdditionalPropertiesException
12+
*
13+
* @package PHPModelGenerator\Exception\Object
14+
*/
15+
class NestedObjectException extends ValidationException
16+
{
17+
/** @var Exception */
18+
private $nestedException;
19+
20+
/**
21+
* NotAllowedAdditionalPropertiesException constructor.
22+
*
23+
* @param $providedValue
24+
* @param string $propertyName
25+
* @param Exception $nestedException
26+
*/
27+
public function __construct($providedValue, string $propertyName, Exception $nestedException)
28+
{
29+
$this->nestedException = $nestedException;
30+
31+
parent::__construct(
32+
"Invalid nested object for property $propertyName:\n - " .
33+
preg_replace(
34+
"/\n([^\s])/m",
35+
"\n - $1",
36+
preg_replace("/\n\s/m", "\n ", $nestedException->getMessage())
37+
),
38+
$propertyName,
39+
$providedValue
40+
);
41+
}
42+
43+
/**
44+
* @return Exception
45+
*/
46+
public function getNestedException(): Exception
47+
{
48+
return $this->nestedException;
49+
}
50+
}

0 commit comments

Comments
 (0)