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

Commit df820d0

Browse files
committed
phpstan fixes
1 parent 16817e1 commit df820d0

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

src/AbstractFactory/ReflectionBasedAbstractFactory.php

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

117-
if (null === ($constructor = $reflectionClass->getConstructor())) {
117+
$constructor = $reflectionClass->getConstructor();
118+
119+
if (null === $constructor) {
118120
return new $requestedName();
119121
}
120122

@@ -213,7 +215,9 @@ private function resolveParameter(ReflectionParameter $parameter, ContainerInter
213215
return [];
214216
}
215217

216-
if (! $parameter->getClass()) {
218+
$parameterClass = $parameter->getClass();
219+
220+
if (! $parameterClass) {
217221
if (! $parameter->isDefaultValueAvailable()) {
218222
throw new ServiceNotFoundException(sprintf(
219223
'Unable to create service "%s"; unable to resolve parameter "%s" '
@@ -226,7 +230,7 @@ private function resolveParameter(ReflectionParameter $parameter, ContainerInter
226230
return $parameter->getDefaultValue();
227231
}
228232

229-
$type = $parameter->getClass()->getName();
233+
$type = $parameterClass->getName();
230234
$type = $this->aliases[$type] ?? $type;
231235

232236
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ServiceManager implements ServiceLocatorInterface
6969
/**
7070
* Whether or not changes may be made to this instance.
7171
*
72-
* @param bool
72+
* @var bool
7373
*/
7474
protected $allowOverride = false;
7575

@@ -645,7 +645,7 @@ private function createDelegatorFromName($name, array $options = null)
645645
};
646646
}
647647

648-
return $creationCallback($this->creationContext, $name, $creationCallback, $options);
648+
return $creationCallback();
649649
}
650650

651651
/**

src/Tool/ConfigDumper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ConfigDumper
4343
EOC;
4444

4545
/**
46-
* @var ContainerInterface
46+
* @var ContainerInterface|null
4747
*/
4848
private $container;
4949

@@ -74,11 +74,12 @@ public function createDependencyConfig(array $config, $className, $ignoreUnresol
7474
}
7575

7676
// class has no constructor, treat it as an invokable
77-
if (! $reflectionClass->getConstructor()) {
77+
$constructor = $reflectionClass->getConstructor();
78+
if (! $constructor) {
7879
return $this->createInvokable($config, $className);
7980
}
8081

81-
$constructorArguments = $reflectionClass->getConstructor()->getParameters();
82+
$constructorArguments = $constructor->getParameters();
8283
$constructorArguments = array_filter(
8384
$constructorArguments,
8485
function (ReflectionParameter $argument) {
@@ -121,7 +122,7 @@ function (ReflectionParameter $argument) {
121122
}
122123

123124
/**
124-
* @param $className
125+
* @param string $className
125126
* @throws InvalidArgumentException if class name is not a string or does
126127
* not exist.
127128
*/

src/Tool/FactoryCreator.php

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

7171
/**
72-
* @param $className
72+
* @param string $className
7373
* @return string
7474
*/
7575
private function getClassName($className)
@@ -86,11 +86,12 @@ private function getConstructorParameters($className)
8686
{
8787
$reflectionClass = new ReflectionClass($className);
8888

89-
if (! $reflectionClass || ! $reflectionClass->getConstructor()) {
89+
$reflectionConstructor = $reflectionClass->getConstructor();
90+
if (! $reflectionConstructor) {
9091
return [];
9192
}
9293

93-
$constructorParameters = $reflectionClass->getConstructor()->getParameters();
94+
$constructorParameters = $reflectionConstructor->getParameters();
9495

9596
if (empty($constructorParameters)) {
9697
return [];
@@ -120,7 +121,9 @@ function (ReflectionParameter $argument) {
120121
}
121122

122123
return array_map(function (ReflectionParameter $parameter) {
123-
return $parameter->getClass()->getName();
124+
/** @var ReflectionClass $class */
125+
$class = $parameter->getClass();
126+
return $class->getName();
124127
}, $constructorParameters);
125128
}
126129

0 commit comments

Comments
 (0)