Skip to content

Commit 172a585

Browse files
committed
refactor: remove the unused SUDO_USER from the user helper function
- Remove the unused `SUDO_USER` from the `user` helper function since Windows doesn't set `SUDO_USER` environment variable at all, so this is redundant code. - Refactored the `user` helper function to have the `USERNAME` variable return by default, and only return the `USER` if it's set. I'm not convinced `USER` is ever used on Windows either, but for now we'll keep it. - Add URLs to the Laravel docs for `resolve`, `retry`, and `tap` helper functions where their functionality was based off.
1 parent 0f277ed commit 172a585

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cli/includes/helpers.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ function addTableSeparator($rows) {
245245
/**
246246
* Resolve the given class from the container.
247247
*
248+
* https://laravel.com/docs/12.x/helpers#method-resolve
249+
*
248250
* @param string $class
249251
* @return mixed
250252
*/
@@ -268,6 +270,8 @@ function swap($class, $instance) {
268270
/**
269271
* Retry the given function N times.
270272
*
273+
* https://laravel.com/docs/12.x/helpers#method-retry
274+
*
271275
* @param int $retries
272276
* @param callable $fn
273277
* @param int $sleep
@@ -298,6 +302,8 @@ function retry($retries, $fn, $sleep = 0) {
298302
/**
299303
* Tap the given value.
300304
*
305+
* https://laravel.com/docs/12.x/helpers#method-tap
306+
*
301307
* @param mixed $value
302308
* @param callable $callback
303309
* @return mixed
@@ -315,15 +321,11 @@ function tap($value, callable $callback) {
315321
* @return string
316322
*/
317323
function user() {
318-
if (!isset($_SERVER['SUDO_USER'])) {
319-
if (!isset($_SERVER['USER'])) {
320-
return $_SERVER['USERNAME'];
321-
}
322-
324+
if (isset($_SERVER['USER'])) {
323325
return $_SERVER['USER'];
324326
}
325327

326-
return $_SERVER['SUDO_USER'];
328+
return $_SERVER['USERNAME'];
327329
}
328330

329331
/**

0 commit comments

Comments
 (0)