diff --git a/benchmarks/BenchAsset/AbstractFactoryFoo.php b/benchmarks/BenchAsset/AbstractFactoryFoo.php
index b7de6abf..6e5f9c50 100644
--- a/benchmarks/BenchAsset/AbstractFactoryFoo.php
+++ b/benchmarks/BenchAsset/AbstractFactoryFoo.php
@@ -7,7 +7,8 @@
class AbstractFactoryFoo implements AbstractFactoryInterface
{
- public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
+ /** {@inheritDoc} */
+ public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
if ($requestedName === 'foo') {
return new Foo($options);
@@ -15,8 +16,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
return false;
}
+ /** {@inheritDoc} */
public function canCreate(ContainerInterface $container, $requestedName)
{
- return ($requestedName === 'foo');
+ return $requestedName === 'foo';
}
}
diff --git a/benchmarks/BenchAsset/Bar.php b/benchmarks/BenchAsset/Bar.php
index dbefcd70..f7158fc3 100644
--- a/benchmarks/BenchAsset/Bar.php
+++ b/benchmarks/BenchAsset/Bar.php
@@ -4,8 +4,10 @@
class Bar
{
+ /** @var mixed */
protected $options;
+ /** @param mixed $options */
public function __construct($options = null)
{
$this->options = $options;
diff --git a/benchmarks/BenchAsset/FactoryFoo.php b/benchmarks/BenchAsset/FactoryFoo.php
index 4c76b3df..ff1bb6de 100644
--- a/benchmarks/BenchAsset/FactoryFoo.php
+++ b/benchmarks/BenchAsset/FactoryFoo.php
@@ -7,7 +7,8 @@
class FactoryFoo implements FactoryInterface
{
- public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
+ /** {@inheritDoc} */
+ public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
return new Foo($options);
}
diff --git a/benchmarks/BenchAsset/Foo.php b/benchmarks/BenchAsset/Foo.php
index 38604d49..8560282c 100644
--- a/benchmarks/BenchAsset/Foo.php
+++ b/benchmarks/BenchAsset/Foo.php
@@ -4,8 +4,10 @@
class Foo
{
+ /** @var mixed */
protected $options;
+ /** @param mixed $options */
public function __construct($options = null)
{
$this->options = $options;
diff --git a/benchmarks/BenchAsset/ServiceDependingOnConfig.php b/benchmarks/BenchAsset/ServiceDependingOnConfig.php
index 24df3c67..dcf7ae55 100644
--- a/benchmarks/BenchAsset/ServiceDependingOnConfig.php
+++ b/benchmarks/BenchAsset/ServiceDependingOnConfig.php
@@ -4,10 +4,8 @@
class ServiceDependingOnConfig
{
- /**
- * @var array
- */
- private $config;
+ /** @var array */
+ public $config;
public function __construct(array $config)
{
diff --git a/benchmarks/BenchAsset/ServiceWithDependency.php b/benchmarks/BenchAsset/ServiceWithDependency.php
index b02093cc..1c47ec7f 100644
--- a/benchmarks/BenchAsset/ServiceWithDependency.php
+++ b/benchmarks/BenchAsset/ServiceWithDependency.php
@@ -4,14 +4,9 @@
class ServiceWithDependency
{
- /**
- * @var Dependency
- */
- private $dependency;
+ /** @var Dependency */
+ protected $dependency;
- /**
- * @param Dependency $dependency
- */
public function __construct(Dependency $dependency)
{
$this->dependency = $dependency;
diff --git a/benchmarks/FetchCachedServicesBench.php b/benchmarks/FetchCachedServicesBench.php
index 5d572152..eff2c205 100644
--- a/benchmarks/FetchCachedServicesBench.php
+++ b/benchmarks/FetchCachedServicesBench.php
@@ -6,6 +6,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
+use stdClass;
/**
* @Revs(1000)
@@ -14,31 +15,29 @@
*/
class FetchCachedServicesBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'factories' => [
+ 'factories' => [
'factory1' => BenchAsset\FactoryFoo::class,
],
- 'invokables' => [
+ 'invokables' => [
'invokable1' => BenchAsset\Foo::class,
],
- 'services' => [
- 'service1' => new \stdClass(),
+ 'services' => [
+ 'service1' => new stdClass(),
],
- 'aliases' => [
+ 'aliases' => [
'alias1' => 'service1',
'recursiveAlias1' => 'alias1',
'recursiveAlias2' => 'recursiveAlias1',
],
'abstract_factories' => [
- BenchAsset\AbstractFactoryFoo::class
- ]
+ BenchAsset\AbstractFactoryFoo::class,
+ ],
]);
// forcing initialization of all the services
@@ -50,7 +49,7 @@ public function __construct()
$this->sm->get('recursiveAlias2');
}
- public function benchFetchFactory1()
+ public function benchFetchFactory1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -58,7 +57,7 @@ public function benchFetchFactory1()
$sm->get('factory1');
}
- public function benchFetchInvokable1()
+ public function benchFetchInvokable1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -66,7 +65,7 @@ public function benchFetchInvokable1()
$sm->get('invokable1');
}
- public function benchFetchService1()
+ public function benchFetchService1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -74,7 +73,7 @@ public function benchFetchService1()
$sm->get('service1');
}
- public function benchFetchAlias1()
+ public function benchFetchAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -82,7 +81,7 @@ public function benchFetchAlias1()
$sm->get('alias1');
}
- public function benchFetchRecursiveAlias1()
+ public function benchFetchRecursiveAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -90,7 +89,7 @@ public function benchFetchRecursiveAlias1()
$sm->get('recursiveAlias1');
}
- public function benchFetchRecursiveAlias2()
+ public function benchFetchRecursiveAlias2(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -98,7 +97,7 @@ public function benchFetchRecursiveAlias2()
$sm->get('recursiveAlias2');
}
- public function benchFetchAbstractFactoryService()
+ public function benchFetchAbstractFactoryService(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
diff --git a/benchmarks/FetchNewServiceManagerBench.php b/benchmarks/FetchNewServiceManagerBench.php
index cfbc893b..ef2d6d01 100644
--- a/benchmarks/FetchNewServiceManagerBench.php
+++ b/benchmarks/FetchNewServiceManagerBench.php
@@ -6,6 +6,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
+use stdClass;
/**
* @Revs(100)
@@ -14,11 +15,9 @@
*/
class FetchNewServiceManagerBench
{
- const NUM_SERVICES = 1000;
+ private const NUM_SERVICES = 1000;
- /**
- * @var array
- */
+ /** @var array */
private $config = [];
public function __construct()
@@ -33,7 +32,7 @@ public function __construct()
],
];
- $service = new \stdClass();
+ $service = new stdClass();
for ($i = 0; $i <= self::NUM_SERVICES; $i++) {
$config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class;
@@ -44,7 +43,7 @@ public function __construct()
$this->config = $config;
}
- public function benchFetchServiceManagerCreation()
+ public function benchFetchServiceManagerCreation(): void
{
new ServiceManager($this->config);
}
diff --git a/benchmarks/FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench.php b/benchmarks/FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench.php
index 94b889f3..b2d14c5c 100644
--- a/benchmarks/FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench.php
+++ b/benchmarks/FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench.php
@@ -15,19 +15,17 @@
*/
class FetchNewServiceUsingConfigAbstractFactoryAsFactoryBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'services' => [
+ 'services' => [
'config' => [
ConfigAbstractFactory::class => [
- BenchAsset\Dependency::class => [],
- BenchAsset\ServiceWithDependency::class => [
+ BenchAsset\Dependency::class => [],
+ BenchAsset\ServiceWithDependency::class => [
BenchAsset\Dependency::class,
],
BenchAsset\ServiceDependingOnConfig::class => [
@@ -37,49 +35,49 @@ public function __construct()
],
],
'factories' => [
- BenchAsset\Dependency::class => ConfigAbstractFactory::class,
- BenchAsset\ServiceWithDependency::class => ConfigAbstractFactory::class,
+ BenchAsset\Dependency::class => ConfigAbstractFactory::class,
+ BenchAsset\ServiceWithDependency::class => ConfigAbstractFactory::class,
BenchAsset\ServiceDependingOnConfig::class => ConfigAbstractFactory::class,
],
]);
}
- public function benchFetchServiceWithNoDependencies()
+ public function benchFetchServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\Dependency::class);
}
- public function benchBuildServiceWithNoDependencies()
+ public function benchBuildServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\Dependency::class);
}
- public function benchFetchServiceDependingOnConfig()
+ public function benchFetchServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchBuildServiceDependingOnConfig()
+ public function benchBuildServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchFetchServiceWithDependency()
+ public function benchFetchServiceWithDependency(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceWithDependency::class);
}
- public function benchBuildServiceWithDependency()
+ public function benchBuildServiceWithDependency(): void
{
$sm = clone $this->sm;
diff --git a/benchmarks/FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench.php b/benchmarks/FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench.php
index 113f1671..8f4e6aeb 100644
--- a/benchmarks/FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench.php
+++ b/benchmarks/FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench.php
@@ -15,61 +15,59 @@
*/
class FetchNewServiceUsingReflectionAbstractFactoryAsFactoryBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'services' => [
+ 'services' => [
'config' => [],
],
'factories' => [
- BenchAsset\Dependency::class => ReflectionBasedAbstractFactory::class,
- BenchAsset\ServiceWithDependency::class => ReflectionBasedAbstractFactory::class,
+ BenchAsset\Dependency::class => ReflectionBasedAbstractFactory::class,
+ BenchAsset\ServiceWithDependency::class => ReflectionBasedAbstractFactory::class,
BenchAsset\ServiceDependingOnConfig::class => ReflectionBasedAbstractFactory::class,
],
]);
}
- public function benchFetchServiceWithNoDependencies()
+ public function benchFetchServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\Dependency::class);
}
- public function benchBuildServiceWithNoDependencies()
+ public function benchBuildServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\Dependency::class);
}
- public function benchFetchServiceDependingOnConfig()
+ public function benchFetchServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchBuildServiceDependingOnConfig()
+ public function benchBuildServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchFetchServiceWithDependency()
+ public function benchFetchServiceWithDependency(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceWithDependency::class);
}
- public function benchBuildServiceWithDependency()
+ public function benchBuildServiceWithDependency(): void
{
$sm = clone $this->sm;
diff --git a/benchmarks/FetchNewServiceViaConfigAbstractFactoryBench.php b/benchmarks/FetchNewServiceViaConfigAbstractFactoryBench.php
index bec04431..b16fff36 100644
--- a/benchmarks/FetchNewServiceViaConfigAbstractFactoryBench.php
+++ b/benchmarks/FetchNewServiceViaConfigAbstractFactoryBench.php
@@ -15,19 +15,17 @@
*/
class FetchNewServiceViaConfigAbstractFactoryBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'services' => [
+ 'services' => [
'config' => [
ConfigAbstractFactory::class => [
- BenchAsset\Dependency::class => [],
- BenchAsset\ServiceWithDependency::class => [
+ BenchAsset\Dependency::class => [],
+ BenchAsset\ServiceWithDependency::class => [
BenchAsset\Dependency::class,
],
BenchAsset\ServiceDependingOnConfig::class => [
@@ -42,42 +40,42 @@ public function __construct()
]);
}
- public function benchFetchServiceWithNoDependencies()
+ public function benchFetchServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\Dependency::class);
}
- public function benchBuildServiceWithNoDependencies()
+ public function benchBuildServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\Dependency::class);
}
- public function benchFetchServiceDependingOnConfig()
+ public function benchFetchServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchBuildServiceDependingOnConfig()
+ public function benchBuildServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchFetchServiceWithDependency()
+ public function benchFetchServiceWithDependency(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceWithDependency::class);
}
- public function benchBuildServiceWithDependency()
+ public function benchBuildServiceWithDependency(): void
{
$sm = clone $this->sm;
diff --git a/benchmarks/FetchNewServiceViaReflectionAbstractFactoryBench.php b/benchmarks/FetchNewServiceViaReflectionAbstractFactoryBench.php
index dc4159eb..22014368 100644
--- a/benchmarks/FetchNewServiceViaReflectionAbstractFactoryBench.php
+++ b/benchmarks/FetchNewServiceViaReflectionAbstractFactoryBench.php
@@ -15,15 +15,13 @@
*/
class FetchNewServiceViaReflectionAbstractFactoryBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'services' => [
+ 'services' => [
'config' => [],
],
'abstract_factories' => [
@@ -32,42 +30,42 @@ public function __construct()
]);
}
- public function benchFetchServiceWithNoDependencies()
+ public function benchFetchServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\Dependency::class);
}
- public function benchBuildServiceWithNoDependencies()
+ public function benchBuildServiceWithNoDependencies(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\Dependency::class);
}
- public function benchFetchServiceDependingOnConfig()
+ public function benchFetchServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchBuildServiceDependingOnConfig()
+ public function benchBuildServiceDependingOnConfig(): void
{
$sm = clone $this->sm;
$sm->build(BenchAsset\ServiceDependingOnConfig::class);
}
- public function benchFetchServiceWithDependency()
+ public function benchFetchServiceWithDependency(): void
{
$sm = clone $this->sm;
$sm->get(BenchAsset\ServiceWithDependency::class);
}
- public function benchBuildServiceWithDependency()
+ public function benchBuildServiceWithDependency(): void
{
$sm = clone $this->sm;
diff --git a/benchmarks/FetchNewServicesBench.php b/benchmarks/FetchNewServicesBench.php
index 6f56e2db..8dc87f12 100644
--- a/benchmarks/FetchNewServicesBench.php
+++ b/benchmarks/FetchNewServicesBench.php
@@ -6,6 +6,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
+use stdClass;
/**
* @Revs(1000)
@@ -14,25 +15,23 @@
*/
class FetchNewServicesBench
{
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
{
$this->sm = new ServiceManager([
- 'factories' => [
+ 'factories' => [
'factory1' => BenchAsset\FactoryFoo::class,
],
- 'invokables' => [
+ 'invokables' => [
'invokable1' => BenchAsset\Foo::class,
],
- 'services' => [
- 'service1' => new \stdClass(),
- 'config' => [],
+ 'services' => [
+ 'service1' => new stdClass(),
+ 'config' => [],
],
- 'aliases' => [
+ 'aliases' => [
'factoryAlias1' => 'factory1',
'recursiveFactoryAlias1' => 'factoryAlias1',
'recursiveFactoryAlias2' => 'recursiveFactoryAlias1',
@@ -43,7 +42,7 @@ public function __construct()
]);
}
- public function benchFetchFactory1()
+ public function benchFetchFactory1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -51,7 +50,7 @@ public function benchFetchFactory1()
$sm->get('factory1');
}
- public function benchBuildFactory1()
+ public function benchBuildFactory1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -59,7 +58,7 @@ public function benchBuildFactory1()
$sm->build('factory1');
}
- public function benchFetchInvokable1()
+ public function benchFetchInvokable1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -67,7 +66,7 @@ public function benchFetchInvokable1()
$sm->get('invokable1');
}
- public function benchBuildInvokable1()
+ public function benchBuildInvokable1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -75,7 +74,7 @@ public function benchBuildInvokable1()
$sm->build('invokable1');
}
- public function benchFetchService1()
+ public function benchFetchService1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -83,7 +82,7 @@ public function benchFetchService1()
$sm->get('service1');
}
- public function benchFetchFactoryAlias1()
+ public function benchFetchFactoryAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -91,7 +90,7 @@ public function benchFetchFactoryAlias1()
$sm->build('factoryAlias1');
}
- public function benchBuildFactoryAlias1()
+ public function benchBuildFactoryAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -99,7 +98,7 @@ public function benchBuildFactoryAlias1()
$sm->build('factoryAlias1');
}
- public function benchFetchRecursiveFactoryAlias1()
+ public function benchFetchRecursiveFactoryAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -107,7 +106,7 @@ public function benchFetchRecursiveFactoryAlias1()
$sm->build('recursiveFactoryAlias1');
}
- public function benchBuildRecursiveFactoryAlias1()
+ public function benchBuildRecursiveFactoryAlias1(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -115,7 +114,7 @@ public function benchBuildRecursiveFactoryAlias1()
$sm->build('recursiveFactoryAlias1');
}
- public function benchFetchRecursiveFactoryAlias2()
+ public function benchFetchRecursiveFactoryAlias2(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -123,7 +122,7 @@ public function benchFetchRecursiveFactoryAlias2()
$sm->build('recursiveFactoryAlias2');
}
- public function benchBuildRecursiveFactoryAlias2()
+ public function benchBuildRecursiveFactoryAlias2(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -131,7 +130,7 @@ public function benchBuildRecursiveFactoryAlias2()
$sm->build('recursiveFactoryAlias2');
}
- public function benchFetchAbstractFactoryFoo()
+ public function benchFetchAbstractFactoryFoo(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -139,7 +138,7 @@ public function benchFetchAbstractFactoryFoo()
$sm->get('foo');
}
- public function benchBuildAbstractFactoryFoo()
+ public function benchBuildAbstractFactoryFoo(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
diff --git a/benchmarks/HasCachedServicesBench.php b/benchmarks/HasCachedServicesBench.php
new file mode 100644
index 00000000..dab35718
--- /dev/null
+++ b/benchmarks/HasCachedServicesBench.php
@@ -0,0 +1,117 @@
+sm = new ServiceManager([
+ 'factories' => [
+ 'factory1' => BenchAsset\FactoryFoo::class,
+ ],
+ 'invokables' => [
+ 'invokable1' => BenchAsset\Foo::class,
+ ],
+ 'services' => [
+ 'service1' => new stdClass(),
+ ],
+ 'aliases' => [
+ 'alias1' => 'service1',
+ 'recursiveAlias1' => 'alias1',
+ 'recursiveAlias2' => 'recursiveAlias1',
+ ],
+ 'abstract_factories' => [
+ BenchAsset\AbstractFactoryFoo::class,
+ ],
+ ]);
+
+ // forcing initialization of all the services
+ $this->sm->get('factory1');
+ $this->sm->get('invokable1');
+ $this->sm->get('service1');
+ $this->sm->get('alias1');
+ $this->sm->get('recursiveAlias1');
+ $this->sm->get('recursiveAlias2');
+ }
+
+ public function benchHasFactory1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('factory1');
+ }
+
+ public function benchHasInvokable1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('invokable1');
+ }
+
+ public function benchHasService1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('service1');
+ }
+
+ public function benchHasAlias1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('alias1');
+ }
+
+ public function benchHasRecursiveAlias1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('recursiveAlias1');
+ }
+
+ public function benchHasRecursiveAlias2(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('recursiveAlias2');
+ }
+
+ public function benchHasAbstractFactoryService(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('foo');
+ }
+
+ public function benchNonExistingService(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('non-existing');
+ }
+}
diff --git a/benchmarks/HasNewServicesBench.php b/benchmarks/HasNewServicesBench.php
new file mode 100644
index 00000000..bf80418c
--- /dev/null
+++ b/benchmarks/HasNewServicesBench.php
@@ -0,0 +1,110 @@
+sm = new ServiceManager([
+ 'factories' => [
+ 'factory1' => BenchAsset\FactoryFoo::class,
+ ],
+ 'invokables' => [
+ 'invokable1' => BenchAsset\Foo::class,
+ ],
+ 'services' => [
+ 'service1' => new stdClass(),
+ 'config' => [],
+ ],
+ 'aliases' => [
+ 'factoryAlias1' => 'factory1',
+ 'recursiveFactoryAlias1' => 'factoryAlias1',
+ 'recursiveFactoryAlias2' => 'recursiveFactoryAlias1',
+ ],
+ 'abstract_factories' => [
+ BenchAsset\AbstractFactoryFoo::class,
+ ],
+ ]);
+ }
+
+ public function benchHasFactory1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('factory1');
+ }
+
+ public function benchHasInvokable1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('invokable1');
+ }
+
+ public function benchHasService1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('service1');
+ }
+
+ public function benchFetchFactoryAlias1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('factoryAlias1');
+ }
+
+ public function benchHasRecursiveFactoryAlias1(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('recursiveFactoryAlias1');
+ }
+
+ public function benchFetchRecursiveFactoryAlias2(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('recursiveFactoryAlias2');
+ }
+
+ public function benchFetchAbstractFactoryFoo(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('foo');
+ }
+
+ public function benchNonExistingService(): void
+ {
+ // @todo @link https://github.com/phpbench/phpbench/issues/304
+ $sm = clone $this->sm;
+
+ $sm->has('non-existing');
+ }
+}
diff --git a/benchmarks/SetNewServicesBench.php b/benchmarks/SetNewServicesBench.php
index c6c60d9d..431598c6 100644
--- a/benchmarks/SetNewServicesBench.php
+++ b/benchmarks/SetNewServicesBench.php
@@ -6,6 +6,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
+use stdClass;
/**
* @Revs(1000)
@@ -14,11 +15,9 @@
*/
class SetNewServicesBench
{
- const NUM_SERVICES = 100;
+ private const NUM_SERVICES = 100;
- /**
- * @var ServiceManager
- */
+ /** @var ServiceManager */
private $sm;
public function __construct()
@@ -31,7 +30,7 @@ public function __construct()
'invokable1' => BenchAsset\Foo::class,
],
'services' => [
- 'service1' => new \stdClass(),
+ 'service1' => new stdClass(),
],
'aliases' => [
'factoryAlias1' => 'factory1',
@@ -39,7 +38,7 @@ public function __construct()
'recursiveFactoryAlias2' => 'recursiveFactoryAlias1',
],
'abstract_factories' => [
- BenchAsset\AbstractFactoryFoo::class
+ BenchAsset\AbstractFactoryFoo::class,
],
];
@@ -51,15 +50,15 @@ public function __construct()
$this->sm = new ServiceManager($config);
}
- public function benchSetService()
+ public function benchSetService(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
- $sm->setService('service2', new \stdClass());
+ $sm->setService('service2', new stdClass());
}
- public function benchSetFactory()
+ public function benchSetFactory(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -67,7 +66,7 @@ public function benchSetFactory()
$sm->setFactory('factory2', BenchAsset\FactoryFoo::class);
}
- public function benchSetAlias()
+ public function benchSetAlias(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
@@ -75,7 +74,7 @@ public function benchSetAlias()
$sm->setAlias('factoryAlias2', 'factory1');
}
- public function benchSetAliasOverrided()
+ public function benchSetAliasOverrided(): void
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 9823321e..4f817882 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -12,6 +12,7 @@
+ benchmarks
bin
src
test