public function testSetVisibilityTokenText()
 {
     /** @var ClassNode $class_node */
     $class_node = Parser::parseSnippet('class Foo { public function wrassle() {} }');
     /** @var ClassMethodNode $method */
     $method = $class_node->getStatements()[0];
     $method->setVisibility('private');
     $this->assertSame('private', $method->getVisibility()->getText());
     $method->setVisibility('protected');
     $this->assertSame('protected', $method->getVisibility()->getText());
     $method->setVisibility('public');
     $this->assertSame('public', $method->getVisibility()->getText());
     $method->setVisibility(T_PRIVATE);
     $this->assertSame('private', $method->getVisibility()->getText());
     $method->setVisibility(T_PROTECTED);
     $this->assertSame('protected', $method->getVisibility()->getText());
     $method->setVisibility(T_PUBLIC);
     $this->assertSame('public', $method->getVisibility()->getText());
     $method->setVisibility(Token::_private());
     $this->assertSame('private', $method->getVisibility()->getText());
     $method->setVisibility(Token::_protected());
     $this->assertSame('protected', $method->getVisibility()->getText());
     $method->setVisibility(Token::_public());
     $this->assertSame('public', $method->getVisibility()->getText());
 }
Esempio n. 2
0
 /**
  * @param string|integer|TokenNode|NULL $visibility
  * @return $this
  */
 public function setVisibility($visibility)
 {
     if ($visibility === NULL) {
         $this->removeVisibility();
     } else {
         if ($visibility === 'private' || $visibility === T_PRIVATE) {
             $visibility = Token::_private();
         } elseif ($visibility === 'protected' || $visibility === T_PROTECTED) {
             $visibility = Token::_protected();
         } elseif ($visibility === 'public' || $visibility === T_PUBLIC) {
             $visibility = Token::_public();
         }
         if (isset($this->visibility)) {
             $this->visibility->replaceWith($visibility);
         } else {
             /** @var \Pharborist\ParentNode $this */
             $this->prepend([$visibility, Token::space()]);
             $this->visibility = $visibility;
         }
     }
     return $this;
 }
 public function testClassProperty()
 {
     $property = ClassMemberListNode::create('someProperty');
     $this->assertEquals('private $someProperty;', $property->getText());
     $property->setVisibility(Token::_protected());
     $this->assertEquals('protected $someProperty;', $property->getText());
 }