public function testBuildInterface() { $interfaceNode = InterfaceNode::create('MyInterface'); $this->assertEquals('interface MyInterface {}', $interfaceNode->getText()); $interfaceNode->setExtends(['BaseInterface', 'AnotherInterface']); $this->assertEquals('interface MyInterface extends BaseInterface, AnotherInterface {}', $interfaceNode->getText()); $interfaceNode->setExtends(NULL); $this->assertEquals('interface MyInterface {}', $interfaceNode->getText()); $interfaceNode->appendMethod('someMethod'); $expected = <<<'EOF' interface MyInterface { public function someMethod(); } EOF; $this->assertEquals($expected, $interfaceNode->getText()); }
/** * @param SingleInheritanceNode|InterfaceNode $node */ protected function endClassTraitOrInterface($node) { $nl = $this->config['nl']; $indent = str_repeat(' ', $this->config['indent']); $indent = str_repeat($indent, $this->indentLevel + 1); /** @var WhitespaceNode $ws_node */ $whitespace = $node->getBody()->children(Filter::isInstanceOf('\\Pharborist\\WhitespaceNode')); foreach ($whitespace->slice(1, -1) as $ws_node) { // Blank line between methods and properties. $ws_node->setText(str_repeat($nl, 2) . $indent); } if ($whitespace->count() === 1) { return; } $blank_lines_around_class_body = $this->config['blank_lines_around_class_body']; $nl_count = $blank_lines_around_class_body + 1; /** @var WhitespaceNode $open_whitespace */ $open_whitespace = $whitespace->get(0); $open_whitespace->setText(str_repeat($nl, $nl_count) . $indent); /** @var WhitespaceNode $close_whitespace */ $close_whitespace = $whitespace->last()->get(0); $indent = str_repeat($indent, $this->indentLevel); $close_whitespace->setText(str_repeat($nl, $nl_count) . $indent); }
/** * Determine if the node belongs to this namespace. * * @param ClassNode|InterfaceNode|TraitNode|FunctionDeclarationNode|ConstantDeclarationNode $node * Node to test if owned by namespace. * * @return bool */ public function owns($node) { return $this === $node->getName()->getNamespace(); }