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;
15

16
final class Construct
17
{
18
    /**
19
     * @var string
20
     */
21
    private $name;
22

23
    /**
24
     * @var string[]
25
     */
26
    private $fileNames = [];
27

28 1
    private function __construct(string $name)
29
    {
30 1
        $this->name = $name;
31
    }
32

33
    /**
34
     * Returns a string representation of the construct.
35
     *
36
     * @return string
37
     */
38 1
    public function __toString(): string
39
    {
40 1
        return $this->name;
41
    }
42

43
    /**
44
     * Creates a new construct from a construct name.
45
     *
46
     * @param string $name
47
     *
48
     * @return self
49
     */
50 1
    public static function fromName(string $name): self
51
    {
52 1
        return new self($name);
53
    }
54

55
    /**
56
     * Returns the name of the construct.
57
     *
58
     * @return string
59
     */
60 1
    public function name(): string
61
    {
62 1
        return $this->name;
63
    }
64

65
    /**
66
     * Returns an array of file names in which the construct is defined.
67
     *
68
     * @return string[]
69
     */
70 1
    public function fileNames(): array
71
    {
72 1
        return $this->fileNames;
73
    }
74

75
    /**
76
     * Clones the construct and adds the file name to the list of files the construct is defined in.
77
     *
78
     * @param string ...$fileNames
79
     *
80
     * @return self
81
     */
82 1
    public function definedIn(string ...$fileNames): self
83
    {
84 1
        $instance = clone $this;
85

86 1
        foreach ($fileNames as $fileName) {
87 1
            $instance->fileNames[] = $fileName;
88
        }
89

90 1
        return $instance;
91
    }
92
}

Read our documentation on viewing source code .

Loading