Skip to content

Commit

Permalink
PhpStan fixes (#214)
Browse files Browse the repository at this point in the history
* Compiler: Add check type of defined extensions

* ContainerBuilder: Annotation hack for error: 'Call to function is_int() with string|null will always evaluate to false.'.

* addDefinition() can return base Definition

* FactoryDefinition::getResultDefinition() can return Definition

* ServiceDefinition::getEntity() can return Reference

* Nette\DI\Definitions\Definition::getFactory(): Fix undefined method

* Nette\DI\Definitions\Definition::getFactory(): Add check if ServiceDefinition.

* FactoryDefinition: completeParameters(): resultDefinition must be type of ServiceDefinition.

* Add given type

* ExtensionsExtension: Check CompilerExtension type

* Fix conflict

* ExtensionsExtension: Redundant empty line

* Compiler: Extension should be ParametersExtension.

* FactoryDefinition: Revert old implementation.

* ConBuilder: Remove Def. anotation + fix number detection.

* ConBuilder: Fix numeric string detection

* ConBuilder: Add support for starting with zero.

* ConBuilder: Add support for zero

* Compiler: Add assert() type check.

* Compiler: Revert isset DI index check.
  • Loading branch information
janbarasek authored and dg committed Aug 5, 2019
1 parent 47bf203 commit 0fe7d84
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/DI/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public function getConfig(): array
*/
public function setDynamicParameterNames(array $names)
{
$this->extensions[self::PARAMETERS]->dynamicParams = $names;
$extension = $this->extensions[self::PARAMETERS];
assert($extension instanceof Nette\DI\Extensions\ParametersExtension);
$extension->dynamicParams = $names;
return $this;
}

Expand Down Expand Up @@ -181,6 +183,7 @@ public function exportDependencies(): array
public function addExportedTag(string $tag)
{
if (isset($this->extensions[self::DI])) {
assert($this->extensions[self::DI] instanceof Nette\DI\Extensions\DIExtension);
$this->extensions[self::DI]->exportedTags[$tag] = true;
}
return $this;
Expand All @@ -193,6 +196,7 @@ public function addExportedTag(string $tag)
public function addExportedType(string $type)
{
if (isset($this->extensions[self::DI])) {
assert($this->extensions[self::DI] instanceof Nette\DI\Extensions\DIExtension);
$this->extensions[self::DI]->exportedTypes[$type] = true;
}
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function addDefinition(?string $name, Definition $definition = null): Def
for ($i = 1; isset($this->definitions['0' . $i]) || isset($this->aliases['0' . $i]); $i++);
$name = '0' . $i; // prevents converting to integer in array key

} elseif (is_int(key([$name => 1])) || !preg_match('#^\w+(\.\w+)*$#D', $name)) {
} elseif (preg_match('#^[+-]?([1-9]\d*|0)\z#', $name) || !preg_match('#^\w+(\.\w+)*$#D', $name)) {
throw new Nette\InvalidArgumentException(sprintf('Service name must be a alpha-numeric string and not a number, %s given.', gettype($name)));

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Definitions/ServiceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getFactory(): Statement


/**
* @return string|array|Definition|null
* @return string|array|Definition|Reference|null
*/
public function getEntity()
{
Expand Down

0 comments on commit 0fe7d84

Please sign in to comment.