PhpFile
final class PhpFile
Represents a complete PHP file with namespaces, classes, and functions.
Methods
Parses PHP source code and returns the resulting PhpFile representation.
Adds a class to the file. Accepts the fully qualified name including namespace.
Adds an interface to the file. Accepts the fully qualified name including namespace.
Adds a trait to the file. Accepts the fully qualified name including namespace.
Adds an enum to the file. Accepts the fully qualified name including namespace.
Adds a function to the file. Accepts the fully qualified name including namespace.
Adds a namespace to the file, or returns the existing one if it already exists.
Removes a namespace from the file.
No description
No description
No description
Adds a use statement to the root (unnamed) namespace.
Enables or disables the declare(strict_types=1) statement.
No description
No description
Details
at line 29
static PhpFile
fromCode(string $code)
Parses PHP source code and returns the resulting PhpFile representation.
at line 39
PhpFile
add(PhpNamespace $item)
Adds a namespace, class-like type, or function to the file.
Class-like types and functions are placed into their respective namespace (created if needed).
at line 63
ClassType
addClass(string $name)
Adds a class to the file. Accepts the fully qualified name including namespace.
at line 75
InterfaceType
addInterface(string $name)
Adds an interface to the file. Accepts the fully qualified name including namespace.
at line 87
TraitType
addTrait(string $name)
Adds a trait to the file. Accepts the fully qualified name including namespace.
at line 99
EnumType
addEnum(string $name)
Adds an enum to the file. Accepts the fully qualified name including namespace.
at line 111
GlobalFunction
addFunction(string $name)
Adds a function to the file. Accepts the fully qualified name including namespace.
at line 122
PhpNamespace
addNamespace(PhpNamespace $namespace)
Adds a namespace to the file, or returns the existing one if it already exists.
at line 136
PhpFile
removeNamespace(PhpNamespace $namespace)
Removes a namespace from the file.
at line 145
array
getNamespaces()
No description
at line 152
array
getClasses()
No description
at line 167
array
getFunctions()
No description
at line 185
PhpFile
addUse(string $name, string|null $alias = null, string $of = PhpNamespace::NameNormal)
Adds a use statement to the root (unnamed) namespace.
at line 195
PhpFile
setStrictTypes(bool $state = true)
Enables or disables the declare(strict_types=1) statement.
at line 202
bool
hasStrictTypes()
No description
at line 208
string
__toString()
No description