Issues (6)

src/Utils/Accessor.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Blixit\EventSourcing\Utils;
6
7
abstract class Accessor
8
{
9
    private function __construct()
10
    {
11
    }
12
13
    public static function getInstance() : self
14
    {
15
        $lsbClass = static::class;
16
        if (empty($lsbClass::$instance)) {
0 ignored issues
show
The property instance does not exist on string.
Loading history...
17
            $lsbClass::$instance = new $lsbClass();
18
        }
19
        return $lsbClass::$instance;
20
    }
21
    /**
22
     * @param mixed $object
23
     *
24
     * @return mixed
25
     */
26
    protected function readProperty($object, string $property)
27
    {
28
        return (function ($property) {
29
            return $this->$property;
30
        })->bindTo($object)->call($object, $property);
31
    }
32
33
    /**
34
     * @param mixed $object
35
     * @param mixed $value
36
     */
37
    protected function writeProperty(&$object, string $property, $value) : void
38
    {
39
        (function ($property, $value) : void {
40
            $this->$property = $value;
41
        })->bindTo($object)->call($object, $property, $value);
42
    }
43
}
44