protected function forceNamespace($code)
    {
        if (0 === preg_match('/\nnamespace/', $code)) {

            $use = array_filter(explode(PHP_EOL, $code), function($string) {
                return substr($string, 0, 5) === 'use \\';
            });

            $code = str_replace($use, '', $code);
            return "\nnamespace\n{\n" . $code . "\n}\n";
        }

        return $code;
    }
protected function forceNamespace($code)
    {
        if (0 === preg_match('/\nnamespace/', $code)) {

            $use = array_filter(explode(PHP_EOL, $code), function($string) {
                return substr($string, 0, 5) === 'use \\';
            });

            $code = str_replace($use, '', $code);
            return "\nnamespace\n{\n" . $code . "\n}\n";
        }

        return $code;
    }
protected function forceNamespace ( $ code ) { if ( 0 === preg_match ( '/\nnamespace/' , $ code ) ) { $ use = array_filter ( explode ( PHP_EOL , $ code ) , function ( $ string ) { return substr ( $ string , 0 , 5 ) === 'use \\' ; } ) ; $ code = str_replace ( $ use , '' , $ code ) ; return "\nnamespace\n{\n" . $ code . "\n}\n" ; } return $ code ; }
Prevent generated class without namespace to fail.

@param  string $code
@return string
Prevent generated class without namespace to fail .