@@ -740,15 +740,36 @@ function helper($filenames)
740740if (! function_exists ('is_cli ' ))
741741{
742742 /**
743- * Is CLI?
744- *
745- * Test to see if a request was made from the command line.
743+ * Check if PHP was invoked from the command line.
746744 *
747745 * @return boolean
746+ *
747+ * @codeCoverageIgnore Cannot be tested fully as PHPUnit always run in CLI
748748 */
749749 function is_cli (): bool
750750 {
751- return (PHP_SAPI === 'cli ' || defined ('STDIN ' ));
751+ if (PHP_SAPI === 'cli ' )
752+ {
753+ return true ;
754+ }
755+
756+ if (defined ('STDIN ' ))
757+ {
758+ return true ;
759+ }
760+
761+ if (stristr (PHP_SAPI , 'cgi ' ) && getenv ('TERM ' ))
762+ {
763+ return true ;
764+ }
765+
766+ if (! isset ($ _SERVER ['REMOTE_ADDR ' ], $ _SERVER ['HTTP_USER_AGENT ' ]))
767+ {
768+ return true ;
769+ }
770+
771+ // if source of request is from CLI, the `$_SERVER` array will not populate this key
772+ return ! isset ($ _SERVER ['REQUEST_METHOD ' ]);
752773 }
753774}
754775
@@ -1278,14 +1299,16 @@ function view_cell(string $library, $params = null, int $ttl = 0, string $cacheN
12781299 *
12791300 * @see https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/helpers.php
12801301 */
1281- // @codeCoverageIgnoreStart
12821302if (! function_exists ('class_basename ' ))
12831303{
12841304 /**
12851305 * Get the class "basename" of the given object / class.
12861306 *
1287- * @param string|object $class
1307+ * @param string|object $class
1308+ *
12881309 * @return string
1310+ *
1311+ * @codeCoverageIgnore
12891312 */
12901313 function class_basename ($ class )
12911314 {
@@ -1300,8 +1323,11 @@ function class_basename($class)
13001323 /**
13011324 * Returns all traits used by a class, its parent classes and trait of their traits.
13021325 *
1303- * @param object|string $class
1326+ * @param object|string $class
1327+ *
13041328 * @return array
1329+ *
1330+ * @codeCoverageIgnore
13051331 */
13061332 function class_uses_recursive ($ class )
13071333 {
@@ -1327,8 +1353,11 @@ function class_uses_recursive($class)
13271353 /**
13281354 * Returns all traits used by a trait and its traits.
13291355 *
1330- * @param string $trait
1356+ * @param string $trait
1357+ *
13311358 * @return array
1359+ *
1360+ * @codeCoverageIgnore
13321361 */
13331362 function trait_uses_recursive ($ trait )
13341363 {
@@ -1342,4 +1371,3 @@ function trait_uses_recursive($trait)
13421371 return $ traits ;
13431372 }
13441373}
1345- // @codeCoverageIgnoreEnd
0 commit comments