Skip to content

Commit

Permalink
update psr/container >=2.0 (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
smpl authored Oct 5, 2023
2 parents 1ec15be + 5175ed7 commit 86f1ebf
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
composer.lock
composer.lock
vendor
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
install:
composer install
test: phpcs phpstan phpunit infection clean
clean:
rm -f tests/ExampleCompiled.php
test: phpcs phpstan phpunit infection
update:
composer update
phpcs:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"container"
],
"require": {
"psr/container": "^1.0",
"psr/container": ">=2.0",
"php": ">=8.0"
},
"require-dev": {
Expand All @@ -25,7 +25,7 @@
}
},
"provide": {
"psr/container-implementation": "^1.0"
"psr/container-implementation": "^2.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public function __construct(ContainerInterface $container)
$this->container = $container;
}

public function get($id)
public function get(string $id)
{
if (!array_key_exists($id, $this->values)) {
$this->values[$id] = $this->container->get($id);
}
return $this->values[$id];
}

public function has($id): bool
public function has(string $id): bool
{
return array_key_exists($id, $this->values) || $this->container->has($id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function __construct(array $params = [], array $alias = [], array $defini
)));
}

public function get($id)
public function get(string $id)
{
return $this->container->get($id);
}

public function has($id): bool
public function has(string $id): bool
{
return $this->container->has($id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/InfiniteRecursionDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(ContainerInterface $container)
$this->container = $container;
}

public function get($id)
public function get(string $id)
{
if (in_array($id, $this->calls)) {
throw new InfiniteRecursion($id, $this->calls);
Expand All @@ -31,7 +31,7 @@ public function get($id)
return $result;
}

public function has($id): bool
public function has(string $id): bool
{
return $this->container->has($id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function get($id)
return $provider->get($id);
}

public function has($id): bool
public function has(string $id): bool
{
return $this->findProvider($id) !== null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(array $values, ContainerInterface $container)
$this->container = $container;
}

public function get($id)
public function get(string $id)
{
$result = parent::get($id);
if (is_string($result)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Strategy/Autowiring.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(Reflection $reflection, ContainerInterface $containe
$this->alias = $alias;
}

public function get($id)
public function get(string $id)
{
$args = [];
foreach ($this->reflection->getDependencies($id) as $dependency) {
Expand All @@ -49,7 +49,7 @@ public function get($id)
return new $id(...$args);
}

public function has($id): bool
public function has(string $id): bool
{
return $this->reflection->isInstantiable($id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(array $values, ContainerInterface $container)
$this->container = $container;
}

public function get($id)
public function get(string $id)
{
$result = parent::get($id);
if (is_callable($result)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Strategy/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function __construct(array $values)
$this->values = $values;
}

public function get($id)
public function get(string $id)
{
return $this->values[$id];
}

public function has($id): bool
public function has(string $id): bool
{
return array_key_exists($id, $this->values);
}
Expand Down
4 changes: 2 additions & 2 deletions template/container.compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $params, array $alias, array $definitions)
$this->containers = <?= var_export(array_unique(array_merge(array_keys($containers), array_keys($alias)))) ?>;
}

public function get($name)
public function get(string $name)
{
if (!array_key_exists($name, $this->params)) {
$this->params[$name] = match($name) {
Expand All @@ -66,7 +66,7 @@ public function get($name)
return $this->params[$name];
}

public function has($name)
public function has(string $name): bool
{
return array_key_exists($name, $this->params)
<?php if ($alias_overridable) { ?>
Expand Down
3 changes: 3 additions & 0 deletions tests/ContainerCompiledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static function tearDownAfterClass(): void
if (file_exists(__DIR__ . '/ExampleCompiled.php')) {
unlink(__DIR__ . '/ExampleCompiled.php');
}
if (file_exists(__DIR__ . '/TestReflectionEnabled.php')) {
unlink(__DIR__ . '/TestReflectionEnabled.php');
}
}

/**
Expand Down

0 comments on commit 86f1ebf

Please sign in to comment.