Skip to content

PHP AST Code Generation Helper - Early Access v1.0

Choose a tag to compare

@quintenmbusiness quintenmbusiness released this 06 Dec 18:45
· 6 commits to master since this release
197e682

Method Summary for Release 1.0

ClassGenerationHelper

  • addClassProperty: Adds a property to a class with type, visibility, and default value.
  • setNamespace: Assigns a namespace to a class or interface and adds imports.
  • createClass: Creates a new class with the given name.
  • addClassMethod: Adds a method to a class with visibility, return type, parameters, and body.
  • extendClass: Sets a parent class for inheritance.
  • implementInterfaces: Adds one or more interfaces to a class.
  • addTraitsToClass: Adds traits to a class.
  • addConstructorToClass: Adds a constructor to a class with parameters.
  • createFullClass: Combines properties, methods, traits, and interfaces into a complete class.

BasicGenerationHelper

  • return: Creates a return statement using the given expression.
  • addVisibility: Sets the visibility of a method or property.
  • createDocComment: Generates PHPDoc comments for a method or property.
  • createArguments: Converts an array into AST-compatible arguments for method calls.
  • createArray: Converts a PHP array into an AST array node.
  • convertToAstNode: Converts a PHP value to an AST node (e.g., int, string, bool).
  • isValidDefault: Validates default values based on type.
  • generateFile: Generates a PHP file for a class, interface, or namespace.

MethodGenerationHelper

  • createMethod: Creates a method with the specified name, visibility, and return type.

TestGenerationHelper

  • createSetUpMethod: Generates a setUp method for initializing test dependencies.
  • createTestMethod: Creates a test method with a specific name and body.
  • createAssertion: Creates a PHPUnit assertion statement.
  • addTestImports: Adds PHPUnit and other imports to a test class.
  • createTestClass: Builds a complete test class with methods and optional setUp.

VariableGenerationHelper

  • assignThisVarToVar: Assigns a class property to a variable.
  • assignThisVarToThisVar: Assigns one class property to another.
  • new: Creates a new object instance.
  • assignVarToVar: Assigns one variable to another.
  • assign: Assigns one expression to another.
  • var: Creates a variable node.
  • thisVar: Fetches a property from the current instance.