1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * Copyright (c) 2017-2020 Andreas Möller
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE.md file that was distributed with this source code.
10
 *
11
 * @see https://github.com/ergebnis/classy
12
 */
13

14
namespace Ergebnis\Classy\Exception;
15

16
use Ergebnis\Classy\Construct;
17

18
final class MultipleDefinitionsFound extends \RuntimeException implements ExceptionInterface
19
{
20
    /**
21
     * @var Construct[]
22
     */
23
    private $constructs;
24

25
    /**
26
     * Returns a new exception from constructs.
27
     *
28
     * @param Construct[] $constructs
29
     */
30 1
    public static function fromConstructs(array $constructs): self
31
    {
32 1
        $exception = new self(\sprintf(
33
            "Multiple definitions have been found for the following constructs:\n\n%s",
34
            \implode("\n", \array_map(static function (Construct $construct): string {
35 1
                return \sprintf(
36
                    ' - "%s" defined in "%s"',
37 1
                    $construct->name(),
38 1
                    \implode('", "', $construct->fileNames())
39
                );
40 1
            }, $constructs))
41
        ));
42

43 1
        $exception->constructs = $constructs;
44

45 1
        return $exception;
46
    }
47

48
    /**
49
     * Returns an array of constructs.
50
     *
51
     * @return Construct[]
52
     */
53 1
    public function constructs(): array
54
    {
55 1
        return $this->constructs;
56
    }
57
}

Read our documentation on viewing source code .

Loading