Ocramius /
ProxyManager
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace ProxyManagerBench; |
||
| 6 | |||
| 7 | use Closure; |
||
| 8 | use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
||
| 9 | use ProxyManager\Factory\LazyLoadingGhostFactory; |
||
| 10 | use ProxyManager\Proxy\GhostObjectInterface; |
||
| 11 | use ProxyManager\Proxy\LazyLoadingInterface; |
||
| 12 | use ProxyManagerTestAsset\ClassWithMixedProperties; |
||
| 13 | use ProxyManagerTestAsset\ClassWithPrivateProperties; |
||
| 14 | use ProxyManagerTestAsset\ClassWithProtectedProperties; |
||
| 15 | use ProxyManagerTestAsset\ClassWithPublicProperties; |
||
| 16 | use ProxyManagerTestAsset\EmptyClass; |
||
| 17 | use ReflectionProperty; |
||
| 18 | use function assert; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Benchmark that provides results for simple initialization/state access for lazy loading ghost proxies |
||
| 22 | * |
||
| 23 | * @BeforeMethods({"setUp"}) |
||
| 24 | */ |
||
| 25 | final class LazyLoadingGhostPropertyAccessBench |
||
| 26 | { |
||
| 27 | /** @var EmptyClass&LazyLoadingInterface */ |
||
| 28 | private EmptyClass $emptyClassProxy; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | |||
| 30 | /** @var EmptyClass&LazyLoadingInterface */ |
||
| 31 | private EmptyClass $initializedEmptyClassProxy; |
||
| 32 | |||
| 33 | /** @var ClassWithPrivateProperties&LazyLoadingInterface */ |
||
| 34 | private ClassWithPrivateProperties $privatePropertiesProxy; |
||
| 35 | |||
| 36 | /** @var ClassWithPrivateProperties&LazyLoadingInterface */ |
||
| 37 | private ClassWithPrivateProperties $initializedPrivatePropertiesProxy; |
||
| 38 | private ReflectionProperty $accessPrivateProperty; |
||
| 39 | |||
| 40 | /** @var ClassWithProtectedProperties&LazyLoadingInterface */ |
||
| 41 | private ClassWithProtectedProperties $protectedPropertiesProxy; |
||
| 42 | |||
| 43 | /** @var ClassWithProtectedProperties&LazyLoadingInterface */ |
||
| 44 | private ClassWithProtectedProperties $initializedProtectedPropertiesProxy; |
||
| 45 | private ReflectionProperty $accessProtectedProperty; |
||
| 46 | |||
| 47 | /** @var ClassWithPublicProperties&LazyLoadingInterface */ |
||
| 48 | private ClassWithPublicProperties $publicPropertiesProxy; |
||
| 49 | |||
| 50 | /** @var ClassWithPublicProperties&LazyLoadingInterface */ |
||
| 51 | private ClassWithPublicProperties $initializedPublicPropertiesProxy; |
||
| 52 | |||
| 53 | /** @var ClassWithMixedProperties&LazyLoadingInterface */ |
||
| 54 | private ClassWithMixedProperties $mixedPropertiesProxy; |
||
| 55 | |||
| 56 | /** @var ClassWithMixedProperties&LazyLoadingInterface */ |
||
| 57 | private ClassWithMixedProperties $initializedMixedPropertiesProxy; |
||
| 58 | |||
| 59 | public function setUp() : void |
||
| 60 | { |
||
| 61 | $emptyClassProxy = $this->buildProxy(EmptyClass::class); |
||
| 62 | $privatePropertiesProxy = $this->buildProxy(ClassWithPrivateProperties::class); |
||
| 63 | $protectedPropertiesProxy = $this->buildProxy(ClassWithProtectedProperties::class); |
||
| 64 | $publicPropertiesProxy = $this->buildProxy(ClassWithPublicProperties::class); |
||
| 65 | $mixedPropertiesProxy = $this->buildProxy(ClassWithMixedProperties::class); |
||
| 66 | $initializedEmptyClassProxy = $this->buildProxy(EmptyClass::class); |
||
| 67 | $initializedPrivatePropertiesProxy = $this->buildProxy(ClassWithPrivateProperties::class); |
||
| 68 | $initializedProtectedPropertiesProxy = $this->buildProxy(ClassWithProtectedProperties::class); |
||
| 69 | $initializedPublicPropertiesProxy = $this->buildProxy(ClassWithPublicProperties::class); |
||
| 70 | $initializedMixedPropertiesProxy = $this->buildProxy(ClassWithMixedProperties::class); |
||
| 71 | |||
| 72 | assert($emptyClassProxy instanceof LazyLoadingInterface); |
||
| 73 | assert($privatePropertiesProxy instanceof LazyLoadingInterface); |
||
| 74 | assert($protectedPropertiesProxy instanceof LazyLoadingInterface); |
||
| 75 | assert($publicPropertiesProxy instanceof LazyLoadingInterface); |
||
| 76 | assert($mixedPropertiesProxy instanceof LazyLoadingInterface); |
||
| 77 | assert($initializedEmptyClassProxy instanceof LazyLoadingInterface); |
||
| 78 | assert($initializedPrivatePropertiesProxy instanceof LazyLoadingInterface); |
||
| 79 | assert($initializedProtectedPropertiesProxy instanceof LazyLoadingInterface); |
||
| 80 | assert($initializedPublicPropertiesProxy instanceof LazyLoadingInterface); |
||
| 81 | assert($initializedMixedPropertiesProxy instanceof LazyLoadingInterface); |
||
| 82 | |||
| 83 | assert($emptyClassProxy instanceof EmptyClass); |
||
| 84 | assert($privatePropertiesProxy instanceof ClassWithPrivateProperties); |
||
| 85 | assert($protectedPropertiesProxy instanceof ClassWithProtectedProperties); |
||
| 86 | assert($publicPropertiesProxy instanceof ClassWithPublicProperties); |
||
| 87 | assert($mixedPropertiesProxy instanceof ClassWithMixedProperties); |
||
| 88 | assert($initializedEmptyClassProxy instanceof EmptyClass); |
||
| 89 | assert($initializedPrivatePropertiesProxy instanceof ClassWithPrivateProperties); |
||
| 90 | assert($initializedProtectedPropertiesProxy instanceof ClassWithProtectedProperties); |
||
| 91 | assert($initializedPublicPropertiesProxy instanceof ClassWithPublicProperties); |
||
| 92 | assert($initializedMixedPropertiesProxy instanceof ClassWithMixedProperties); |
||
| 93 | |||
| 94 | $this->emptyClassProxy = $emptyClassProxy; |
||
| 95 | $this->privatePropertiesProxy = $privatePropertiesProxy; |
||
| 96 | $this->protectedPropertiesProxy = $protectedPropertiesProxy; |
||
| 97 | $this->publicPropertiesProxy = $publicPropertiesProxy; |
||
| 98 | $this->mixedPropertiesProxy = $mixedPropertiesProxy; |
||
| 99 | |||
| 100 | $this->initializedEmptyClassProxy = $initializedEmptyClassProxy; |
||
| 101 | $this->initializedPrivatePropertiesProxy = $initializedPrivatePropertiesProxy; |
||
| 102 | $this->initializedProtectedPropertiesProxy = $initializedProtectedPropertiesProxy; |
||
| 103 | $this->initializedPublicPropertiesProxy = $initializedPublicPropertiesProxy; |
||
| 104 | $this->initializedMixedPropertiesProxy = $initializedMixedPropertiesProxy; |
||
| 105 | |||
| 106 | $this->initializedEmptyClassProxy->initializeProxy(); |
||
| 107 | $this->initializedPrivatePropertiesProxy->initializeProxy(); |
||
| 108 | $this->initializedProtectedPropertiesProxy->initializeProxy(); |
||
| 109 | $this->initializedPublicPropertiesProxy->initializeProxy(); |
||
| 110 | $this->initializedMixedPropertiesProxy->initializeProxy(); |
||
| 111 | |||
| 112 | $this->accessPrivateProperty = new ReflectionProperty(ClassWithPrivateProperties::class, 'property0'); |
||
| 113 | $this->accessPrivateProperty->setAccessible(true); |
||
| 114 | |||
| 115 | $this->accessProtectedProperty = new ReflectionProperty(ClassWithProtectedProperties::class, 'property0'); |
||
| 116 | $this->accessProtectedProperty->setAccessible(true); |
||
| 117 | } |
||
| 118 | |||
| 119 | public function benchEmptyClassInitialization() : void |
||
| 120 | { |
||
| 121 | $this->emptyClassProxy->initializeProxy(); |
||
| 122 | } |
||
| 123 | |||
| 124 | public function benchInitializedEmptyClassInitialization() : void |
||
| 125 | { |
||
| 126 | $this->initializedEmptyClassProxy->initializeProxy(); |
||
| 127 | } |
||
| 128 | |||
| 129 | public function benchObjectWithPrivatePropertiesInitialization() : void |
||
| 130 | { |
||
| 131 | $this->privatePropertiesProxy->initializeProxy(); |
||
| 132 | } |
||
| 133 | |||
| 134 | public function benchInitializedObjectWithPrivatePropertiesInitialization() : void |
||
| 135 | { |
||
| 136 | $this->initializedPrivatePropertiesProxy->initializeProxy(); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function benchObjectWithPrivatePropertiesPropertyRead() : void |
||
| 140 | { |
||
| 141 | $this->accessPrivateProperty->getValue($this->privatePropertiesProxy); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function benchInitializedObjectWithPrivatePropertiesPropertyRead() : void |
||
| 145 | { |
||
| 146 | $this->accessPrivateProperty->getValue($this->initializedPrivatePropertiesProxy); |
||
| 147 | } |
||
| 148 | |||
| 149 | public function benchObjectWithPrivatePropertiesPropertyWrite() : void |
||
| 150 | { |
||
| 151 | $this->accessPrivateProperty->setValue($this->privatePropertiesProxy, 'foo'); |
||
| 152 | } |
||
| 153 | |||
| 154 | public function benchInitializedObjectWithPrivatePropertiesPropertyWrite() : void |
||
| 155 | { |
||
| 156 | $this->accessPrivateProperty->setValue($this->initializedPrivatePropertiesProxy, 'foo'); |
||
| 157 | } |
||
| 158 | |||
| 159 | public function benchObjectWithProtectedPropertiesInitialization() : void |
||
| 160 | { |
||
| 161 | $this->protectedPropertiesProxy->initializeProxy(); |
||
| 162 | } |
||
| 163 | |||
| 164 | public function benchInitializedObjectWithProtectedPropertiesInitialization() : void |
||
| 165 | { |
||
| 166 | $this->initializedProtectedPropertiesProxy->initializeProxy(); |
||
| 167 | } |
||
| 168 | |||
| 169 | public function benchObjectWithProtectedPropertiesPropertyRead() : void |
||
| 170 | { |
||
| 171 | $this->accessProtectedProperty->getValue($this->protectedPropertiesProxy); |
||
| 172 | } |
||
| 173 | |||
| 174 | public function benchInitializedObjectWithProtectedPropertiesPropertyRead() : void |
||
| 175 | { |
||
| 176 | $this->accessProtectedProperty->getValue($this->initializedProtectedPropertiesProxy); |
||
| 177 | } |
||
| 178 | |||
| 179 | public function benchObjectWithProtectedPropertiesPropertyWrite() : void |
||
| 180 | { |
||
| 181 | $this->accessProtectedProperty->setValue($this->protectedPropertiesProxy, 'foo'); |
||
| 182 | } |
||
| 183 | |||
| 184 | public function benchInitializedObjectWithProtectedPropertiesPropertyWrite() : void |
||
| 185 | { |
||
| 186 | $this->accessProtectedProperty->setValue($this->initializedProtectedPropertiesProxy, 'foo'); |
||
| 187 | } |
||
| 188 | |||
| 189 | public function benchObjectWithPublicPropertiesInitialization() : void |
||
| 190 | { |
||
| 191 | $this->publicPropertiesProxy->initializeProxy(); |
||
| 192 | } |
||
| 193 | |||
| 194 | public function benchInitializedObjectWithPublicPropertiesInitialization() : void |
||
| 195 | { |
||
| 196 | $this->initializedPublicPropertiesProxy->initializeProxy(); |
||
| 197 | } |
||
| 198 | |||
| 199 | public function benchObjectWithPublicPropertiesPropertyRead() : void |
||
| 200 | { |
||
| 201 | $this->publicPropertiesProxy->property0; |
||
| 202 | } |
||
| 203 | |||
| 204 | public function benchInitializedObjectWithPublicPropertiesPropertyRead() : void |
||
| 205 | { |
||
| 206 | $this->initializedPublicPropertiesProxy->property0; |
||
| 207 | } |
||
| 208 | |||
| 209 | public function benchObjectWithPublicPropertiesPropertyWrite() : void |
||
| 210 | { |
||
| 211 | $this->publicPropertiesProxy->property0 = 'foo'; |
||
| 212 | } |
||
| 213 | |||
| 214 | public function benchInitializedObjectWithPublicPropertiesPropertyWrite() : void |
||
| 215 | { |
||
| 216 | $this->initializedPublicPropertiesProxy->property0 = 'foo'; |
||
| 217 | } |
||
| 218 | |||
| 219 | public function benchObjectWithPublicPropertiesPropertyIsset() : void |
||
| 220 | { |
||
| 221 | /* @noinspection PhpExpressionResultUnusedInspection */ |
||
| 222 | /* @noinspection UnSafeIsSetOverArrayInspection */ |
||
| 223 | isset($this->publicPropertiesProxy->property0); |
||
| 224 | } |
||
| 225 | |||
| 226 | public function benchInitializedObjectWithPublicPropertiesPropertyIsset() : void |
||
| 227 | { |
||
| 228 | /* @noinspection PhpExpressionResultUnusedInspection */ |
||
| 229 | /* @noinspection UnSafeIsSetOverArrayInspection */ |
||
| 230 | isset($this->initializedPublicPropertiesProxy->property0); |
||
| 231 | } |
||
| 232 | |||
| 233 | public function benchObjectWithPublicPropertiesPropertyUnset() : void |
||
| 234 | { |
||
| 235 | unset($this->publicPropertiesProxy->property0); |
||
| 236 | } |
||
| 237 | |||
| 238 | public function benchInitializedObjectWithPublicPropertiesPropertyUnset() : void |
||
| 239 | { |
||
| 240 | unset($this->initializedPublicPropertiesProxy->property0); |
||
| 241 | } |
||
| 242 | |||
| 243 | public function benchObjectWithMixedPropertiesInitialization() : void |
||
| 244 | { |
||
| 245 | $this->mixedPropertiesProxy->initializeProxy(); |
||
| 246 | } |
||
| 247 | |||
| 248 | public function benchInitializedObjectWithMixedPropertiesInitialization() : void |
||
| 249 | { |
||
| 250 | $this->initializedMixedPropertiesProxy->initializeProxy(); |
||
| 251 | } |
||
| 252 | |||
| 253 | public function benchObjectWithMixedPropertiesPropertyRead() : void |
||
| 254 | { |
||
| 255 | $this->mixedPropertiesProxy->publicProperty0; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function benchInitializedObjectWithMixedPropertiesPropertyRead() : void |
||
| 259 | { |
||
| 260 | $this->initializedMixedPropertiesProxy->publicProperty0; |
||
| 261 | } |
||
| 262 | |||
| 263 | public function benchObjectWithMixedPropertiesPropertyWrite() : void |
||
| 264 | { |
||
| 265 | $this->mixedPropertiesProxy->publicProperty0 = 'foo'; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function benchInitializedObjectWithMixedPropertiesPropertyWrite() : void |
||
| 269 | { |
||
| 270 | $this->initializedMixedPropertiesProxy->publicProperty0 = 'foo'; |
||
| 271 | } |
||
| 272 | |||
| 273 | public function benchObjectWithMixedPropertiesPropertyIsset() : void |
||
| 274 | { |
||
| 275 | /* @noinspection PhpExpressionResultUnusedInspection */ |
||
| 276 | /* @noinspection UnSafeIsSetOverArrayInspection */ |
||
| 277 | isset($this->mixedPropertiesProxy->publicProperty0); |
||
| 278 | } |
||
| 279 | |||
| 280 | public function benchInitializedObjectWithMixedPropertiesPropertyIsset() : void |
||
| 281 | { |
||
| 282 | /* @noinspection PhpExpressionResultUnusedInspection */ |
||
| 283 | /* @noinspection UnSafeIsSetOverArrayInspection */ |
||
| 284 | isset($this->initializedMixedPropertiesProxy->publicProperty0); |
||
| 285 | } |
||
| 286 | |||
| 287 | public function benchObjectWithMixedPropertiesPropertyUnset() : void |
||
| 288 | { |
||
| 289 | unset($this->mixedPropertiesProxy->publicProperty0); |
||
| 290 | } |
||
| 291 | |||
| 292 | public function benchInitializedObjectWithMixedPropertiesPropertyUnset() : void |
||
| 293 | { |
||
| 294 | unset($this->initializedMixedPropertiesProxy->publicProperty0); |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @psalm-template OriginalClass |
||
| 299 | * @psalm-param class-string<OriginalClass> $originalClass |
||
| 300 | * @psalm-return OriginalClass&GhostObjectInterface<OriginalClass> |
||
| 301 | * @psalm-suppress MixedInferredReturnType |
||
| 302 | */ |
||
| 303 | private function buildProxy(string $originalClass) : GhostObjectInterface |
||
| 304 | { |
||
| 305 | return (new LazyLoadingGhostFactory()) |
||
| 306 | ->createProxy( |
||
| 307 | $originalClass, |
||
| 308 | static function (object $proxy, string $method, array $params, ?Closure & $initializer) : bool { |
||
| 309 | $initializer = null; |
||
| 310 | |||
| 311 | return true; |
||
| 312 | } |
||
| 313 | ); |
||
| 314 | } |
||
| 315 | } |
||
| 316 |