ergebnis / classy
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 1
    public function __toString(): string
37
    {
38 1
        return $this->name;
39
    }
40

41
    /**
42
     * Creates a new construct from a construct name.
43
     */
44 1
    public static function fromName(string $name): self
45
    {
46 1
        return new self($name);
47
    }
48

49
    /**
50
     * Returns the name of the construct.
51
     */
52 1
    public function name(): string
53
    {
54 1
        return $this->name;
55
    }
56

57
    /**
58
     * Returns an array of file names in which the construct is defined.
59
     *
60
     * @return string[]
61
     */
62 1
    public function fileNames(): array
63
    {
64 1
        return $this->fileNames;
65
    }
66

67
    /**
68
     * Clones the construct and adds the file name to the list of files the construct is defined in.
69
     *
70
     * @param string ...$fileNames
71
     */
72 1
    public function definedIn(string ...$fileNames): self
73
    {
74 1
        $instance = clone $this;
75

76 1
        foreach ($fileNames as $fileName) {
77 1
            $instance->fileNames[] = $fileName;
78
        }
79

80 1
        return $instance;
81
    }
82
}

Read our documentation on viewing source code .

Loading