Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

BaselinePropertyAccessBench   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 112
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerBench;
6
7
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
8
use ProxyManagerTestAsset\ClassWithMixedProperties;
9
use ProxyManagerTestAsset\ClassWithPrivateProperties;
10
use ProxyManagerTestAsset\ClassWithProtectedProperties;
11
use ProxyManagerTestAsset\ClassWithPublicProperties;
12
use ReflectionProperty;
13
14
/**
15
 * Benchmark that provides baseline results for simple object state interactions
16
 *
17
 * @BeforeMethods({"setUp"})
18
 */
19
final class BaselinePropertyAccessBench
20
{
21
    private ClassWithPrivateProperties $privateProperties;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
22
    private ReflectionProperty $accessPrivateProperty;
23
    private ClassWithProtectedProperties $protectedProperties;
24
    private ReflectionProperty $accessProtectedProperty;
25
    private ClassWithPublicProperties $publicProperties;
26
    private ClassWithMixedProperties $mixedProperties;
27
    private ReflectionProperty $accessMixedPropertiesPrivate;
28
    private ReflectionProperty $accessMixedPropertiesProtected;
29
30
    public function setUp() : void
31
    {
32
        $this->privateProperties   = new ClassWithPrivateProperties();
33
        $this->protectedProperties = new ClassWithProtectedProperties();
34
        $this->publicProperties    = new ClassWithPublicProperties();
35
        $this->mixedProperties     = new ClassWithMixedProperties();
36
37
        $this->accessPrivateProperty = new ReflectionProperty(ClassWithPrivateProperties::class, 'property0');
38
        $this->accessPrivateProperty->setAccessible(true);
39
40
        $this->accessProtectedProperty = new ReflectionProperty(ClassWithProtectedProperties::class, 'property0');
41
        $this->accessProtectedProperty->setAccessible(true);
42
43
        $this->accessMixedPropertiesPrivate = new ReflectionProperty(
44
            ClassWithMixedProperties::class,
45
            'privateProperty0'
46
        );
47
        $this->accessMixedPropertiesPrivate->setAccessible(true);
48
49
        $this->accessMixedPropertiesProtected = new ReflectionProperty(
50
            ClassWithMixedProperties::class,
51
            'protectedProperty0'
52
        );
53
        $this->accessMixedPropertiesProtected->setAccessible(true);
54
    }
55
56
    public function benchPrivatePropertyRead() : void
57
    {
58
        $this->accessPrivateProperty->getValue($this->privateProperties);
59
    }
60
61
    public function benchPrivatePropertyWrite() : void
62
    {
63
        $this->accessPrivateProperty->setValue($this->privateProperties, 'foo');
64
    }
65
66
    public function benchProtectedPropertyRead() : void
67
    {
68
        $this->accessProtectedProperty->getValue($this->protectedProperties);
69
    }
70
71
    public function benchProtectedPropertyWrite() : void
72
    {
73
        $this->accessProtectedProperty->setValue($this->protectedProperties, 'foo');
74
    }
75
76
    public function benchPublicPropertyRead() : void
77
    {
78
        $this->publicProperties->property0;
79
    }
80
81
    public function benchPublicPropertyWrite() : void
82
    {
83
        $this->publicProperties->property0 = 'foo';
84
    }
85
86
    public function benchMixedPropertiesPrivatePropertyRead() : void
87
    {
88
        $this->accessMixedPropertiesPrivate->getValue($this->mixedProperties);
89
    }
90
91
    public function benchMixedPropertiesPrivatePropertyWrite() : void
92
    {
93
        $this->accessMixedPropertiesPrivate->setValue($this->mixedProperties, 'foo');
94
    }
95
96
    public function benchMixedPropertiesProtectedPropertyRead() : void
97
    {
98
        $this->accessMixedPropertiesProtected->getValue($this->mixedProperties);
99
    }
100
101
    public function benchMixedPropertiesProtectedPropertyWrite() : void
102
    {
103
        $this->accessMixedPropertiesProtected->setValue($this->mixedProperties, 'foo');
104
    }
105
106
    public function benchMixedPropertiesPublicPropertyRead() : void
107
    {
108
        $this->mixedProperties->publicProperty0;
109
    }
110
111
    public function benchMixedPropertiesPublicPropertyWrite() : void
112
    {
113
        $this->mixedProperties->publicProperty0 = 'foo';
114
    }
115
}
116