Represents a single code snippet

CloneableInstantiable
ImplementsJsonSerializable
Methods
public __construct( $identifier, array $config = [])
 

Create a snippet

    public addLocal( $name, $value)
     

    Add a local variable to make available in the snippet execution scope.

    • return void
    public addUse( $name)
     

    Add a use statement for a class.

    • return void
    public content()
     

    The snippet content.

    • return string
    public file()
     

    The file in which the snippet is found.

    • return string
    public fqn()
     

    The Snippet fully-qualified name.

    • return string
    public identifier()
     

    A unique identifier for the snippet.

    This identifier is deterministic and will remain constant unless the
    snippet is modified or moved.

    • return string
    public index()
     

    The Snippet Index

    • return int
    public insertAfterLine( $line, $content)
     

    Inject new code after a given line.

    Hopefully this is obvious, but be careful using this, and only use it
    when no other feasible options present themselves. It's pretty easy to
    make your test useless when you're modifying the thing you are trying
    to test.

    This is provided for cases when a snippet relies on a global, or on
    something else which can not be overridden or mocked.

    • return void
    public invoke( $returnVar = NULL)
     

    Eval the snippet and return the result.

    • return mixed
    public jsonSerialize()
     

    Serialize to json

    • return array
    public line()
     

    The line number where the snippet's method or class is declared.

    Note that this is NOT the line number where the snippet is declared. It
    indicates the method or class which the snippet annotates.

    • return int
    public name()
     

    The snippet name

    • return string
    public regexReplace( $pattern, $new)
     

    Find something with a regex and replace it.

    Hopefully this is obvious, but be careful using this, and only use it
    when no other feasible options present themselves. It's pretty easy to
    make your test useless when you're modifying the thing you are trying
    to test.

    This is provided for cases when a snippet relies on a global, or on
    something else which can not be overridden or mocked.

    • return void
    public replace( $old, $new)
     

    Replace a string in the snippet with a new one.

    Hopefully this is obvious, but be careful using this, and only use it
    when no other feasible options present themselves. It's pretty easy to
    make your test useless when you're modifying the thing you are trying
    to test.

    This is provided for cases when a snippet relies on a global, or on
    something else which can not be overridden or mocked.

    • return void
    public setLine( $line, $content)
     

    Replace a line with new code.

    Hopefully this is obvious, but be careful using this, and only use it
    when no other feasible options present themselves. It's pretty easy to
    make your test useless when you're overwriting the thing you are trying
    to test.

    This is provided for cases when a snippet relies on a global, or on
    something else which can not be overridden or mocked.

    • return void
    Properties
    private $config
     
    • var array
    private $identifier
     
    • var string
    private $locals
     
    • var array
    private $use
     
    • var array
    Methods
    private createReturnVar( $returnVar)
    © 2020 Bruce Wells
    Search Namespaces \ Classes
    ConfigurationNumbers (0-9.) only