@@ -656,36 +656,42 @@ public function onPostUpdate(Event $event, array $operations = []): void
656656 */
657657 public function executeAutoScripts (Event $ event ): void
658658 {
659- $ event ->stopPropagation ();
660-
661659 // force reloading scripts as we might have added and removed during this run
662660 $ json = new JsonFile (Factory::getComposerFile ());
663661 $ jsonContents = $ json ->read ();
664662
665- if (isset ($ jsonContents ['scripts ' ][ScriptEvents::AUTO_SCRIPTS ])) {
666- /** @var \Narrowspark\Automatic\ScriptExecutor $scriptExecutor */
667- $ scriptExecutor = $ this ->container ->get (ScriptExecutor::class);
663+ if (! isset ($ jsonContents ['scripts ' ][ScriptEvents::AUTO_SCRIPTS ])) {
664+ $ this ->container ->get (IOInterface::class)->write ('No auto-scripts section was found under scripts ' , true , IOInterface::VERBOSE );
668665
669- foreach ((array ) $ this ->container ->get (Lock::class)->get (ScriptExecutor::TYPE ) as $ extenders ) {
670- foreach ($ extenders as $ class => $ path ) {
671- if (! \class_exists ($ class )) {
672- require_once $ path ;
673- }
666+ return ;
667+ }
674668
675- /** @var \Narrowspark\Automatic\Common\Contract\ScriptExtender $class */
676- $ reflectionClass = new ReflectionClass ($ class );
669+ if (\in_array (true , \array_map ('\is_numeric ' , \array_keys ($ jsonContents ['scripts ' ][ScriptEvents::AUTO_SCRIPTS ])), true )) {
670+ return ;
671+ }
677672
678- if ($ reflectionClass ->isInstantiable () && $ reflectionClass ->hasMethod ('getType ' )) {
679- $ scriptExecutor ->add ($ class ::getType (), $ class );
680- }
673+ $ event ->stopPropagation ();
674+
675+ /** @var \Narrowspark\Automatic\ScriptExecutor $scriptExecutor */
676+ $ scriptExecutor = $ this ->container ->get (ScriptExecutor::class);
677+
678+ foreach ((array ) $ this ->container ->get (Lock::class)->get (ScriptExecutor::TYPE ) as $ extenders ) {
679+ foreach ($ extenders as $ class => $ path ) {
680+ if (! \class_exists ($ class )) {
681+ require_once $ path ;
681682 }
682- }
683683
684- foreach ($ jsonContents ['scripts ' ][ScriptEvents::AUTO_SCRIPTS ] as $ cmd => $ type ) {
685- $ scriptExecutor ->execute ($ type , $ cmd );
684+ /** @var \Narrowspark\Automatic\Common\Contract\ScriptExtender $class */
685+ $ reflectionClass = new ReflectionClass ($ class );
686+
687+ if ($ reflectionClass ->isInstantiable () && $ reflectionClass ->hasMethod ('getType ' )) {
688+ $ scriptExecutor ->add ($ class ::getType (), $ class );
689+ }
686690 }
687- } else {
688- $ this ->container ->get (IOInterface::class)->write ('No auto-scripts section was found under scripts ' , true , IOInterface::VERBOSE );
691+ }
692+
693+ foreach ($ jsonContents ['scripts ' ][ScriptEvents::AUTO_SCRIPTS ] as $ cmd => $ type ) {
694+ $ scriptExecutor ->execute ($ type , $ cmd );
689695 }
690696 }
691697
0 commit comments