99use JeroenG \Autowire \Attribute \Configure as ConfigureAttribute ;
1010use JeroenG \Autowire \Attribute \ConfigureInterface as ConfigureAttributeInterface ;
1111use JeroenG \Autowire \Exception \FaultyWiringException ;
12- use Webmozart \ Assert \ Assert ;
12+ use JeroenG \ Autowire \ Exception \ InvalidAttributeException ;
1313
1414final class Electrician
1515{
@@ -22,8 +22,8 @@ public function __construct(
2222 private string $ autowireAttribute = AutowireAttribute::class,
2323 private string $ configureAttribute = ConfigureAttribute::class
2424 ) {
25- self ::assertValidAttributeImplementation ($ this ->autowireAttribute , AutowireAttributeInterface::class);
26- self ::assertValidAttributeImplementation ($ this ->configureAttribute , ConfigureAttributeInterface::class);
25+ self ::checkValidAttributeImplementation ($ this ->autowireAttribute , AutowireAttributeInterface::class);
26+ self ::checkValidAttributeImplementation ($ this ->configureAttribute , ConfigureAttributeInterface::class);
2727 }
2828
2929 public function connect (string $ interface ): Wire
@@ -62,13 +62,6 @@ public function configure(string $implementation): Configuration
6262
6363 return new Configuration ($ implementation , $ configurations );
6464 }
65-
66- private static function assertValidAttributeImplementation (string $ className , string $ attributeInterface ): void
67- {
68- Assert::classExists ($ className );
69- Assert::notEmpty ((new \ReflectionClass ($ className ))->getAttributes (\Attribute::class));
70- Assert::isAOf ($ className , $ attributeInterface , "{$ className } : {$ attributeInterface }" );
71- }
7265
7366 public function canAutowire (string $ name ): bool
7467 {
@@ -79,6 +72,24 @@ public function canConfigure(string $name): bool
7972 {
8073 return $ this ->classHasAttribute ($ name , $ this ->configureAttribute );
8174 }
75+
76+ /**
77+ * @throws InvalidAttributeException
78+ */
79+ private static function checkValidAttributeImplementation (string $ className , string $ attributeInterface ): void
80+ {
81+ if (!class_exists ($ className )) {
82+ throw InvalidAttributeException::doesNotExist ($ className );
83+ }
84+
85+ if (empty ((new \ReflectionClass ($ className ))->getAttributes (\Attribute::class))) {
86+ throw InvalidAttributeException::isNotAnAttribute ($ className );
87+ }
88+
89+ if (!is_a ($ className , $ attributeInterface , true )) {
90+ throw InvalidAttributeException::doesNotImplementInterface ($ className , $ attributeInterface );
91+ }
92+ }
8293
8394 private function classHasAttribute (string $ className , string $ attributeName ): bool
8495 {
0 commit comments