Skip to content

Commit

Permalink
no need to postfix the variable with specification
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Aug 21, 2024
1 parent 69fe40c commit a9ca138
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
14 changes: 5 additions & 9 deletions src/ClassScanner/AnnotatedInjectAttributeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@

final class AnnotatedInjectAttributeConfig implements AttributeConfigInterface
{
public static function define(
Container $di,
AttributeSpecification $attributeSpecification,
ClassSpecification $classSpecification
): void
public static function define(Container $di, AttributeSpecification $attribute, ClassSpecification $class): void
{
if ($attributeSpecification->isConstructorParameterAttribute()) {
/** @var AnnotatedInjectInterface $attribute */
$attribute = $attributeSpecification->getAttributeInstance();
$di->params[$attributeSpecification->getClassName()][$attributeSpecification->getTargetParameter()] = $attribute->inject();
if ($attribute->isConstructorParameterAttribute()) {
/** @var AnnotatedInjectInterface $annotatedInject */
$annotatedInject = $attribute->getAttributeInstance();
$di->params[$attribute->getClassName()][$attribute->getTargetParameter()] = $annotatedInject->inject();
}
}
}
6 changes: 1 addition & 5 deletions src/ClassScanner/AttributeConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@

interface AttributeConfigInterface
{
public static function define(
Container $di,
AttributeSpecification $attributeSpecification,
ClassSpecification $classSpecification
): void;
public static function define(Container $di, AttributeSpecification $attribute, ClassSpecification $class): void;
}
8 changes: 2 additions & 6 deletions src/ClassScanner/BlueprintAttributeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

final class BlueprintAttributeConfig implements AttributeConfigInterface
{
public static function define(
Container $di,
AttributeSpecification $attributeSpecification,
ClassSpecification $classSpecification
): void
public static function define(Container $di, AttributeSpecification $attribute, ClassSpecification $class): void
{
$di->params[$attributeSpecification->getClassName()] = $di->params[$attributeSpecification->getClassName()] ?? [];
$di->params[$attribute->getClassName()] = $di->params[$attribute->getClassName()] ?? [];
}
}
16 changes: 6 additions & 10 deletions tests/Fake/FakeWorkerAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ public function __construct(int $someSetting = 1)
$this->someSetting = $someSetting;
}

public static function define(
Container $di,
AttributeSpecification $attributeSpecification,
ClassSpecification $classSpecification
): void
public static function define(Container $di, AttributeSpecification $attribute, ClassSpecification $class): void
{
/** @var self $attribute */
$attribute = $attributeSpecification->getAttributeInstance();
if ($attributeSpecification->getAttributeTarget() === \Attribute::TARGET_CLASS) {
/** @var self $instance */
$instance = $attribute->getAttributeInstance();
if ($attribute->getAttributeTarget() === \Attribute::TARGET_CLASS) {
$di->values['worker'] = $di->values['worker'] ?? [];
$di->values['worker'][] = [
'someSetting' => $attribute->someSetting,
'className' => $attributeSpecification->getClassName(),
'someSetting' => $instance->someSetting,
'className' => $attribute->getClassName(),
];
}
}
Expand Down

0 comments on commit a9ca138

Please sign in to comment.