Issues (5)

src/SingletonTrait.php (1 issue)

Labels
Severity
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * BEdita, API-first content management framework
6
 * Copyright 2018 ChannelWeb Srl, Chialab Srl
7
 *
8
 * This file is part of BEdita: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published
10
 * by the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
14
 */
15
namespace BEdita\WebTools;
16
17
/**
18
 * Singleton class.
19
 *
20
 * @see https://github.com/sebastianbergmann/phpunit/blob/8.5/tests/_files/Singleton.php
21
 */
22
trait SingletonTrait
23
{
24
    /**
25
     * Singleton instance.
26
     *
27
     * @var static|null
28
     */
29
    private static $uniqueInstance = null;
30
31
    /**
32
     * Singleton constructor.
33
     *
34
     * The constructor is declared private in order to
35
     * prevent new instances from being created.
36
     *
37
     * @codeCoverageIgnore
38
     */
39
    final protected function __construct()
40
    {
41
    }
42
43
    /**
44
     * Singleton clone method.
45
     *
46
     * This method is declared private in order to
47
     * prevent existing instances from being cloned.
48
     *
49
     * @return void
50
     * @codeCoverageIgnore
51
     */
52
    private function __clone()
53
    {
54
    }
55
56
    /**
57
     * Singleton getter.
58
     *
59
     * Use this method in order to get the singleton instance
60
     *
61
     * @return static|null
62
     */
63
    final public static function getInstance(): ?static
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STATIC on line 63 at column 49
Loading history...
64
    {
65
        if (self::$uniqueInstance === null) {
66
            self::$uniqueInstance = new static();
67
        }
68
69
        return self::$uniqueInstance;
70
    }
71
}
72