Accessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A readProperty() 0 5 1
A __construct() 0 2 1
A writeProperty() 0 5 1
A getInstance() 0 7 2
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
Bug introduced by
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