Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 2aada28

Browse files
committed
phpstan fixes
1 parent 0aea76f commit 2aada28

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

src/AbstractFactory/ReflectionBasedAbstractFactory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
110110
{
111111
$reflectionClass = new ReflectionClass($requestedName);
112112

113-
if (null === ($constructor = $reflectionClass->getConstructor())) {
113+
$constructor = $reflectionClass->getConstructor();
114+
115+
if (null === $constructor) {
114116
return new $requestedName();
115117
}
116118

@@ -202,7 +204,9 @@ private function resolveParameter(ReflectionParameter $parameter, ContainerInter
202204
return [];
203205
}
204206

205-
if (! $parameter->getClass()) {
207+
$parameterClass = $parameter->getClass();
208+
209+
if (! $parameterClass) {
206210
if (! $parameter->isDefaultValueAvailable()) {
207211
throw new ServiceNotFoundException(sprintf(
208212
'Unable to create service "%s"; unable to resolve parameter "%s" '
@@ -215,7 +219,7 @@ private function resolveParameter(ReflectionParameter $parameter, ContainerInter
215219
return $parameter->getDefaultValue();
216220
}
217221

218-
$type = $parameter->getClass()->getName();
222+
$type = $parameterClass->getName();
219223
$type = isset($this->aliases[$type]) ? $this->aliases[$type] : $type;
220224

221225
if ($container->has($type)) {

src/AbstractFactoryInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ interface AbstractFactoryInterface extends Factory\AbstractFactoryInterface
4040
* Determine if we can create a service with name
4141
*
4242
* @param ServiceLocatorInterface $serviceLocator
43-
* @param $name
44-
* @param $requestedName
43+
* @param string $name
44+
* @param string $requestedName
4545
* @return bool
4646
*/
4747
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName);
@@ -50,8 +50,8 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
5050
* Create service with name
5151
*
5252
* @param ServiceLocatorInterface $serviceLocator
53-
* @param $name
54-
* @param $requestedName
53+
* @param string $name
54+
* @param string $requestedName
5555
* @return mixed
5656
*/
5757
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName);

src/InitializerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface InitializerInterface extends Initializer\InitializerInterface
3232
/**
3333
* Initialize
3434
*
35-
* @param $instance
35+
* @param mixed $instance
3636
* @param ServiceLocatorInterface $serviceLocator
3737
* @return mixed
3838
*/

src/ServiceManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ServiceManager implements ServiceLocatorInterface
5555
/**
5656
* Whether or not changes may be made to this instance.
5757
*
58-
* @param bool
58+
* @var bool
5959
*/
6060
protected $allowOverride = false;
6161

@@ -672,6 +672,7 @@ private function getFactory($name)
672672
if (PHP_MAJOR_VERSION < 7
673673
&& is_string($factory) && strpos($factory, '::') !== false
674674
) {
675+
/** @var callable $factory */
675676
$factory = explode('::', $factory);
676677
}
677678
return $factory;
@@ -739,7 +740,7 @@ private function createDelegatorFromName($name, array $options = null)
739740
};
740741
}
741742

742-
return $creationCallback($this->creationContext, $name, $creationCallback, $options);
743+
return $creationCallback();
743744
}
744745

745746
/**
@@ -933,7 +934,7 @@ private function validateOverrides(array $config)
933934
* service instances; if not, it returns, but otherwise, it raises an
934935
* exception indicating modification is not allowed.
935936
*
936-
* @param string[] $services
937+
* @param array $services
937938
* @param string $type Type of service being checked.
938939
* @throws ContainerModificationsNotAllowedException if any services
939940
* provided already have instances available.

src/Tool/ConfigDumper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConfigDumper
2727
EOC;
2828

2929
/**
30-
* @var ContainerInterface
30+
* @var ContainerInterface|null
3131
*/
3232
private $container;
3333

@@ -58,11 +58,12 @@ public function createDependencyConfig(array $config, $className, $ignoreUnresol
5858
}
5959

6060
// class has no constructor, treat it as an invokable
61-
if (! $reflectionClass->getConstructor()) {
61+
$constructor = $reflectionClass->getConstructor();
62+
if (! $constructor) {
6263
return $this->createInvokable($config, $className);
6364
}
6465

65-
$constructorArguments = $reflectionClass->getConstructor()->getParameters();
66+
$constructorArguments = $constructor->getParameters();
6667
$constructorArguments = array_filter(
6768
$constructorArguments,
6869
function (ReflectionParameter $argument) {
@@ -105,7 +106,7 @@ function (ReflectionParameter $argument) {
105106
}
106107

107108
/**
108-
* @param $className
109+
* @param string $className
109110
* @throws InvalidArgumentException if class name is not a string or does
110111
* not exist.
111112
*/

src/Tool/FactoryCreator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function createFactory($className)
5858
}
5959

6060
/**
61-
* @param $className
61+
* @param string $className
6262
* @return string
6363
*/
6464
private function getClassName($className)
@@ -75,11 +75,12 @@ private function getConstructorParameters($className)
7575
{
7676
$reflectionClass = new ReflectionClass($className);
7777

78-
if (! $reflectionClass || ! $reflectionClass->getConstructor()) {
78+
$reflectionConstructor = $reflectionClass->getConstructor();
79+
if (! $reflectionConstructor) {
7980
return [];
8081
}
8182

82-
$constructorParameters = $reflectionClass->getConstructor()->getParameters();
83+
$constructorParameters = $reflectionConstructor->getParameters();
8384

8485
if (empty($constructorParameters)) {
8586
return [];
@@ -109,7 +110,9 @@ function (ReflectionParameter $argument) {
109110
}
110111

111112
return array_map(function (ReflectionParameter $parameter) {
112-
return $parameter->getClass()->getName();
113+
/** @var ReflectionClass $class */
114+
$class = $parameter->getClass();
115+
return $class->getName();
113116
}, $constructorParameters);
114117
}
115118

0 commit comments

Comments
 (0)