Skip to content

DocBlock: add removeTag() method #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: php

dist: trusty

php:
- 7.0
- 7.1
Expand All @@ -14,14 +16,12 @@ cache:
directories:
- $HOME/.composer/cache

script:
- vendor/bin/phpunit --coverage-clover=coverage.clover -v
- composer update --no-interaction --prefer-source
- vendor/bin/phpunit -v

before_script:
- composer install --no-interaction

script:
- vendor/bin/phpunit --coverage-clover=coverage.clover -v

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
Expand Down
17 changes: 17 additions & 0 deletions src/DocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ public function hasTag($name)
return false;
}

/**
* Remove a tag from this DocBlock.
*
* @param Tag $tag The tag to remove.
*
* @return void
*/
public function removeTag(Tag $tagToRemove)
{
foreach ($this->tags as $key => $tag) {
if ($tag === $tagToRemove) {
unset($this->tags[$key]);
break;
}
}
}

/**
* Adds a tag to this DocBlock.
*
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/DocBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace phpDocumentor\Reflection;

use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\Types\Context;

/**
Expand Down Expand Up @@ -249,4 +250,28 @@ public function testDocBlockKnowsIfItIsTheEndOfADocBlockTemplate()

$this->assertTrue($fixture->isTemplateEnd());
}

/**
* @covers ::__construct
* @covers ::removeTag
*
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Deprecated
*/
public function testRemoveTag()
{
$someTag = new Deprecated();
$anotherTag = new Deprecated();

$fixture = new DocBlock('', null, [$someTag]);

$this->assertCount(1, $fixture->getTags());

$fixture->removeTag($anotherTag);

$this->assertCount(1, $fixture->getTags());

$fixture->removeTag($someTag);

$this->assertCount(0, $fixture->getTags());
}
}