Skip to content

Commit a70d1d2

Browse files
committed
Use the new mechanism instead of ReflectorAwareAttributeInterface.
1 parent c338eb2 commit a70d1d2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/Attribute/Parameter/OckAdaptee.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
use Ock\Ock\Plugin\PluginDeclaration;
1515
use Ock\Ock\Text\Text;
1616
use Ock\Ock\Text\TextInterface;
17-
use Ock\ReflectorAwareAttributes\ReflectorAwareAttributeInterface;
17+
use Ock\ReflectorAwareAttributes\AttributeConstructor;
1818

1919
#[\Attribute(\Attribute::TARGET_PARAMETER|\Attribute::TARGET_PROPERTY)]
20-
class OckAdaptee implements NameHavingInterface, LabelHavingInterface, FormulaHavingInterface, ReflectorAwareAttributeInterface, PluginModifierAttributeInterface {
20+
class OckAdaptee implements NameHavingInterface, LabelHavingInterface, FormulaHavingInterface, PluginModifierAttributeInterface {
2121

2222
/**
23-
* @var class-string|null
23+
* @var class-string
2424
*/
25-
private ?string $type;
25+
private string $type;
26+
27+
public function __construct() {
28+
$this->type = self::guessType();
29+
}
2630

2731
/**
2832
* {@inheritdoc}
@@ -46,9 +50,10 @@ public function getFormula(): FormulaInterface {
4650
}
4751

4852
/**
49-
* {@inheritdoc}
53+
* @return class-string
5054
*/
51-
public function setReflector(\Reflector $reflector): void {
55+
private static function guessType(): string {
56+
$reflector = AttributeConstructor::getReflector();
5257
if (!$reflector instanceof \ReflectionParameter) {
5358
throw new MalformedDeclarationException('This attribute must be on a parameter.');
5459
}
@@ -64,16 +69,13 @@ public function setReflector(\Reflector $reflector): void {
6469
$t = $declaring_class->getName();
6570
}
6671
/** @var class-string $t */
67-
$this->type = $t;
72+
return $t;
6873
}
6974

7075
/**
7176
* {@inheritdoc}
7277
*/
7378
public function modifyPlugin(PluginDeclaration $declaration): PluginDeclaration {
74-
if ($this->type === NULL) {
75-
throw new \RuntimeException('This attribute is incomplete. Please call ->setReflector().');
76-
}
7779
return $declaration->withSetting('adaptee_type', $this->type);
7880
}
7981

0 commit comments

Comments
 (0)