@@ -46,9 +46,8 @@ public function addComponent(IComponent $component, ?string $name, ?string $inse
4646
4747 if (!preg_match (self ::NameRegexp, $ name )) {
4848 throw new Nette \InvalidArgumentException ("Component name must be non-empty alphanumeric string, ' $ name' given. " );
49- }
5049
51- if (isset ($ this ->components [$ name ])) {
50+ } elseif (isset ($ this ->components [$ name ])) {
5251 throw new Nette \InvalidStateException ("Component with name ' $ name' already exists. " );
5352 }
5453
@@ -58,9 +57,7 @@ public function addComponent(IComponent $component, ?string $name, ?string $inse
5857 if ($ obj === $ component ) {
5958 throw new Nette \InvalidStateException ("Circular reference detected while adding component ' $ name'. " );
6059 }
61-
62- $ obj = $ obj ->getParent ();
63- } while ($ obj !== null );
60+ } while (($ obj = $ obj ->getParent ()) !== null );
6461
6562 // user checking
6663 $ this ->validateChildComponent ($ component );
@@ -117,11 +114,9 @@ final public function getComponent(string $name, bool $throw = true): ?IComponen
117114
118115 if (!isset ($ this ->components [$ name ])) {
119116 if (!preg_match (self ::NameRegexp, $ name )) {
120- if ($ throw ) {
121- throw new Nette \InvalidArgumentException ("Component name must be non-empty alphanumeric string, ' $ name' given. " );
122- }
123-
124- return null ;
117+ return $ throw
118+ ? throw new Nette \InvalidArgumentException ("Component name must be non-empty alphanumeric string, ' $ name' given. " )
119+ : null ;
125120 }
126121
127122 $ component = $ this ->createComponent ($ name );
0 commit comments