CodeCleaner
in package
A service to clean up user input, detect parse errors before they happen, and generally work around issues with the PHP code evaluation experience.
Table of Contents
- $namespace : mixed
- $parser : mixed
- $printer : mixed
- $traverser : mixed
- __construct() : mixed
- CodeCleaner constructor.
- clean() : string|false
- Clean the given array of code.
- getNamespace() : null|array<string|int, mixed>
- Get the current local namespace.
- setNamespace() : null|array<string|int, mixed>
- Set the current local namespace.
- parse() : array<string|int, mixed>|false
- Lex and parse a block of code.
- addImplicitDebugContext() : mixed
- "Warm up" code cleaner passes when we're coming from a debug call.
- getDebugFile() : string|null
- Search the stack trace for a file in which the user called Psy\debug.
- getDefaultPasses() : array<string|int, mixed>
- Get default CodeCleaner passes.
- isDebugCall() : bool
- Check whether a given backtrace frame is a call to Psy\debug.
- parseErrorIsEOF() : mixed
- parseErrorIsTrailingComma() : mixed
- parseErrorIsUnclosedString() : bool
- A special test for unclosed single-quoted strings.
- parseErrorIsUnterminatedComment() : mixed
Properties
$namespace
private
mixed
$namespace
$parser
private
mixed
$parser
$printer
private
mixed
$printer
$traverser
private
mixed
$traverser
Methods
__construct()
CodeCleaner constructor.
public
__construct([Parser $parser = null ][, Standard $printer = null ][, NodeTraverser $traverser = null ]) : mixed
Parameters
- $parser : Parser = null
-
A PhpParser Parser instance. One will be created if not explicitly supplied
- $printer : Standard = null
-
A PhpParser Printer instance. One will be created if not explicitly supplied
- $traverser : NodeTraverser = null
-
A PhpParser NodeTraverser instance. One will be created if not explicitly supplied
Return values
mixed —clean()
Clean the given array of code.
public
clean(array<string|int, mixed> $codeLines[, bool $requireSemicolons = false ]) : string|false
Parameters
- $codeLines : array<string|int, mixed>
- $requireSemicolons : bool = false
Tags
Return values
string|false —Cleaned PHP code, False if the input is incomplete
getNamespace()
Get the current local namespace.
public
getNamespace() : null|array<string|int, mixed>
Return values
null|array<string|int, mixed> —setNamespace()
Set the current local namespace.
public
setNamespace([null|array<string|int, mixed> $namespace = null ]) : null|array<string|int, mixed>
Parameters
- $namespace : null|array<string|int, mixed> = null
-
(default: null)
Return values
null|array<string|int, mixed> —parse()
Lex and parse a block of code.
protected
parse(string $code[, bool $requireSemicolons = false ]) : array<string|int, mixed>|false
Parameters
- $code : string
- $requireSemicolons : bool = false
Tags
Return values
array<string|int, mixed>|false —A set of statements, or false if incomplete
addImplicitDebugContext()
"Warm up" code cleaner passes when we're coming from a debug call.
private
addImplicitDebugContext(array<string|int, mixed> $passes) : mixed
This is useful, for example, for UseStatementPass and NamespacePass
which keep track of state between calls, to maintain the current
namespace and a map of use statements.
Parameters
- $passes : array<string|int, mixed>
Return values
mixed —getDebugFile()
Search the stack trace for a file in which the user called Psy\debug.
private
static getDebugFile() : string|null
Return values
string|null —getDefaultPasses()
Get default CodeCleaner passes.
private
getDefaultPasses() : array<string|int, mixed>
Return values
array<string|int, mixed> —isDebugCall()
Check whether a given backtrace frame is a call to Psy\debug.
private
static isDebugCall(array<string|int, mixed> $stackFrame) : bool
Parameters
- $stackFrame : array<string|int, mixed>
Return values
bool —parseErrorIsEOF()
private
parseErrorIsEOF(Error $e) : mixed
Parameters
- $e : Error
Return values
mixed —parseErrorIsTrailingComma()
private
parseErrorIsTrailingComma(Error $e, mixed $code) : mixed
Parameters
- $e : Error
- $code : mixed
Return values
mixed —parseErrorIsUnclosedString()
A special test for unclosed single-quoted strings.
private
parseErrorIsUnclosedString(Error $e, string $code) : bool
Unlike (all?) other unclosed statements, single quoted strings have their own special beautiful snowflake syntax error just for themselves.
Parameters
- $e : Error
- $code : string
Return values
bool —parseErrorIsUnterminatedComment()
private
parseErrorIsUnterminatedComment(Error $e, mixed $code) : mixed
Parameters
- $e : Error
- $code : mixed