Skip to content
Merged

fix #113

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ patch.php
test.php
var
vendor
.codex
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ $payload = $signed->decode($token);

```bash
composer install
composer test
composer ic:tests
```


Expand Down
6 changes: 3 additions & 3 deletions docs/benchmark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Run via Composer:

.. code-block:: bash

composer benchmark
composer ic:benchmark

Other useful variants:

.. code-block:: bash

composer bench:quick
composer bench:chart
composer ic:bench:quick
composer ic:bench:chart

What it measures
----------------
Expand Down
8 changes: 1 addition & 7 deletions src/DI/Resolver/ParameterResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,7 @@ public function setClassResolverInstance(ClassResolver $classResolver): void
*/
private function alreadyExist(string $className, array $parameters): bool
{
foreach ($parameters as $value) {
if ($value instanceof $className) {
return true;
}
}

return false;
return array_any($parameters, fn($value) => $value instanceof $className);
}

private function applyEnvOverride(string $fqcn): string
Expand Down
8 changes: 1 addition & 7 deletions src/DI/Resolver/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,7 @@ private function isSafeCachedDefinitionValue(mixed $value): bool
return false;
}

foreach ($value as $item) {
if (!$this->isSafeCachedDefinitionValue($item)) {
return false;
}
}

return true;
return array_all($value, fn($item) => $this->isSafeCachedDefinitionValue($item));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Container/AttributeResolutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Infocyph\InterMix\Tests\Fixture\LogicOnlyAttr;
use Infocyph\InterMix\Tests\Fixture\LogicOnlyAttrResolver;
use Infocyph\InterMix\Tests\Fixture\LogicOnlyTarget;
use Infocyph\InterMix\Tests\Fixture\MethodAttr;
use Infocyph\InterMix\Tests\Fixture\MethodAttrResolver;
use Infocyph\InterMix\Tests\Fixture\MethodTarget;
use Infocyph\InterMix\Tests\Fixture\MixedAttributeExample;

Expand Down Expand Up @@ -53,6 +55,10 @@
ExampleAttr::class,
ExampleAttrResolver::class,
);
$c->attributeRegistry()->register(
MethodAttr::class,
MethodAttrResolver::class,
);

/* 3️⃣ Bind a container definition that Infuse will pick up */
$c->definitions()->bind('api_key', 'XYZ123');
Expand Down
9 changes: 7 additions & 2 deletions tests/Fixture/MethodAttrResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public function resolve(
Reflector $target,
Container $container
): null {
// Log, side-effect, or simply acknowledge
fwrite(
STDERR,
"[TEST] {$attributeInstance->message} on {$target->getName()} in {$container::class}\n"
'[TEST] '
. $attributeInstance->message
. ' on '
. $target->getName()
. ' in '
. $container::class
. "\n"
);

return null;
Expand Down
1 change: 1 addition & 0 deletions tests/Fixture/MethodTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class MethodTarget
{
public array $result;

#[MethodAttr('send')]
#[ExampleAttr]
public function send(
#[Inject('api_key')] string $override,
Expand Down