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
     * @return self
31
     */
32 1
    public static function fromConstructs(array $constructs): self
33
    {
34 1
        $exception = new self(\sprintf(
35 1
            "Multiple definitions have been found for the following constructs:\n\n%s",
36
            \implode("\n", \array_map(static function (Construct $construct): string {
37 1
                return \sprintf(
38 1
                    ' - "%s" defined in "%s"',
39 1
                    $construct->name(),
40 1
                    \implode('", "', $construct->fileNames())
41
                );
42 1
            }, $constructs))
43
        ));
44

45 1
        $exception->constructs = $constructs;
46

47 1
        return $exception;
48
    }
49

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

Read our documentation on viewing source code .

Loading