        <?php

        function customize_php_scoper_config(array $config): array {
            // List of helper function names to target.
            $helpers = [
                'value',
                'collect',
                'data_fill',
                'data_get',
                'data_set',
                'head',
                'last',
                'append_config',
                'blank',
                'class_basename',
                'class_uses_recursive',
                'e',
                'env',
                'filled',
                'object_get',
                'optional',
                'preg_replace_array',
                'retry',
                'tap',
                'throw_if',
                'throw_unless',
                'trait_uses_recursive',
                'transform',
                'windows_os',
                'with',
                'head',
                'base_path',

            ];

            $config['patchers'][] = function(string $filePath, string $prefix, string $content) use($helpers): string {
                // don’t touch your own helper definitions
                if (stripos($filePath, 'helpers.php') !== false) {
                    return $content;
                }

                $tokens = token_get_all($content);
                $n      = count($tokens);
                $out    = '';

                // helper to find the previous non-WS/comment token
                $prevNonWs = function($i) use($tokens) {
                    for ($k = $i - 1; $k >= 0; $k--) {
                        if (is_array($tokens[$k]) && in_array($tokens[$k][0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
                            continue;
                        }
                        return $tokens[$k];
                    }
                    return null;
                };

                // helper to find the next non-WS/comment token
                $nextNonWs = function($i) use($tokens, $n) {
                    for ($k = $i + 1; $k < $n; $k++) {
                        if (is_array($tokens[$k]) && in_array($tokens[$k][0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
                            continue;
                        }
                        return $tokens[$k];
                    }
                    return null;
                };

                for ($i = 0; $i < $n; $i++) {
                    $t = $tokens[$i];

                    // Only consider T_STRING that’s in our helper list
                    if (is_array($t) && $t[0] === T_STRING && in_array($t[1], $helpers, true)) {
                        $name = $t[1];
                        $prev = $prevNonWs($i);
                        $next = $nextNonWs($i);

                        $isDeclarationOrMethod = false;
                        if (is_array($prev)) {
                            $pid = $prev[0];
                            if (in_array($pid, [
                                T_FUNCTION,            // function foo
                                T_NS_SEPARATOR,        // \something
                                T_OBJECT_OPERATOR,     // ->something
                                T_PAAMAYIM_NEKUDOTAYIM // ::something
                            ], true)) {
                                $isDeclarationOrMethod = true;
                            }
                        }

                        // Must be a real call: next token is "("
                        $isCall = ($next === '(');

                        if (! $isDeclarationOrMethod && $isCall) {
                            // prefix it
                            $out .= '\\' . $prefix . '\\' . $name;
                            continue;
                        }

                        // otherwise fall-through and just copy the name
                        $out .= $name;
                    } else {
                        // any other token (whitespace, comments, punctuation, etc.)
                        // just copy verbatim
                        $out .= is_array($t) ? $t[1] : $t;
                    }
                }

                return $out;
            };

            return $config;
        }
