1111use Symfony \Component \Console \Input \InputInterface ;
1212use Symfony \Component \Console \Input \InputOption ;
1313use Symfony \Component \Console \Output \OutputInterface ;
14+ use Symfony \Component \Process \Exception \ProcessStartFailedException ;
1415use Symfony \Component \Process \PhpExecutableFinder ;
1516use Symfony \Component \Process \Process ;
1617
@@ -760,17 +761,7 @@ protected function generateAppUrl($name)
760761 */
761762 protected function getTld ()
762763 {
763- foreach (['herd ' , 'valet ' ] as $ tool ) {
764- $ process = new Process ([$ tool , 'tld ' , '-v ' ]);
765-
766- $ process ->run ();
767-
768- if ($ process ->isSuccessful ()) {
769- return trim ($ process ->getOutput ());
770- }
771- }
772-
773- return 'test ' ;
764+ return $ this ->runOnValetOrHerd ('tld ' ) ?? 'test ' ;
774765 }
775766
776767 /**
@@ -792,19 +783,9 @@ protected function canResolveHostname($hostname)
792783 */
793784 protected function isParked (string $ directory )
794785 {
795- foreach (['herd ' , 'valet ' ] as $ tool ) {
796- $ process = new Process ([$ tool , 'paths ' , '-v ' ]);
786+ $ output = $ this ->runOnValetOrHerd ('paths ' );
797787
798- $ process ->run ();
799-
800- if ($ process ->isSuccessful ()) {
801- $ output = json_decode (trim ($ process ->getOutput ()));
802-
803- return in_array (dirname ($ directory ), $ output );
804- }
805- }
806-
807- return false ;
788+ return $ output !== false ? in_array (dirname ($ directory ), json_decode ($ output )) : false ;
808789 }
809790
810791 /**
@@ -846,6 +827,30 @@ protected function phpBinary()
846827 : 'php ' ;
847828 }
848829
830+ /**
831+ * Runs the given command on the "herd" or "valet" CLI.
832+ *
833+ * @param string $command
834+ * @return string|bool
835+ */
836+ protected function runOnValetOrHerd (string $ command )
837+ {
838+ foreach (['herd ' , 'valet ' ] as $ tool ) {
839+ $ process = new Process ([$ tool , $ command , '-v ' ]);
840+
841+ try {
842+ $ process ->run ();
843+
844+ if ($ process ->isSuccessful ()) {
845+ return trim ($ process ->getOutput ());
846+ }
847+ } catch (ProcessStartFailedException ) {
848+ }
849+ }
850+
851+ return false ;
852+ }
853+
849854 /**
850855 * Run the given commands.
851856 *
0 commit comments