public function testSomething() { $class = new PhpClass('Spanner', 'Fish', false); $class->addUses('Goat', ['Monkey', 'Bananna']); $class->addExtends('Wibble'); $class->addImplements('FunTime'); $class->classComponents[] = new FunctionDeclaration('hello', 'public function hello(){ return "hello"; }'); $class->classComponents[] = new FunctionDeclaration('goodbye', 'public function goodbye(){ return "goodbye"; }'); $class->classComponents[] = new FunctionDeclaration('__construct', 'public function __construct(){}'); $class->classComponents[] = new FunctionDeclaration('multiLineDeclaration', <<<'PHP' /** * Some multiline comment */ public function multiLineDeclaration () { return array( 'monkey' => 'goat', ); } PHP ); $class->classComponents[] = new VariableDeclaration('size', 'public $size = "big";'); $class->classComponents[] = new VariableDeclaration('age', 'public $age;'); $class->classComponents[] = new ClassConstant('t-rex', 'const T_REX = 100;'); $php = $class->render(); $php = new Php($class->render()); $isValid = $php->isValid($error); // echo $class->render()->addLineNumbers(); }
public function __construct(\SplFileInfo $file) { if (!$file->isFile()) { throw new \LogicException("Please pass a file not a directory."); } $this->originalPhp = file_get_contents($this->file->getPathname()); $php = new Php($this->originalPhp); if (!$php->isValid($errors, true)) { throw new BadPhpException($this->originalPhp, $errors); } $this->file = $file; $this->analyse(); }