Skip to content

Commit 8a18ca6

Browse files
committed
Allow to remove comments and flags
1 parent 6d38536 commit 8a18ca6

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
Previous releases are documented in [github releases](https://github.com/oscarotero/Gettext/releases)
99

10+
## [5.3.0] - 2020-02-18
11+
### Added
12+
- `Comments::delete()` and `Flags::delete()` methods [#247]
13+
1014
## [5.2.2] - 2020-02-09
1115
### Fixed
1216
- MoLoader with plurals [#246]
@@ -51,7 +55,9 @@ Previous releases are documented in [github releases](https://github.com/oscarot
5155

5256
[#244]: https://github.com/php-gettext/Gettext/issues/244
5357
[#246]: https://github.com/php-gettext/Gettext/issues/246
58+
[#247]: https://github.com/php-gettext/Gettext/issues/247
5459

60+
[5.3.0]: https://github.com/php-gettext/Gettext/compare/v5.2.2...v5.3.0
5561
[5.2.2]: https://github.com/php-gettext/Gettext/compare/v5.2.1...v5.2.2
5662
[5.2.1]: https://github.com/php-gettext/Gettext/compare/v5.2.0...v5.2.1
5763
[5.2.0]: https://github.com/php-gettext/Gettext/compare/v5.1.0...v5.2.0

src/Comments.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public function add(string ...$comments): self
4343
return $this;
4444
}
4545

46+
public function delete(string ...$comments): self
47+
{
48+
foreach ($comments as $comment) {
49+
$key = array_search($comment, $this->comments);
50+
51+
if ($key !== false) {
52+
array_splice($this->comments, $key, 1);
53+
}
54+
}
55+
56+
return $this;
57+
}
58+
4659
public function jsonSerialize()
4760
{
4861
return $this->toArray();

src/Flags.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public function add(string ...$flags): self
4545
return $this;
4646
}
4747

48+
public function delete(string ...$flags): self
49+
{
50+
foreach ($flags as $flag) {
51+
$key = array_search($flag, $this->flags);
52+
53+
if ($key !== false) {
54+
array_splice($this->flags, $key, 1);
55+
}
56+
}
57+
58+
return $this;
59+
}
60+
4861
public function has(string $flag): bool
4962
{
5063
return in_array($flag, $this->flags, true);

tests/CommentsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function testComments()
2929

3030
$this->assertSame(['foo', 'bar'], $comments->toArray());
3131
$this->assertCount(2, $comments);
32+
33+
$comments->delete('foo');
34+
35+
$this->assertSame(['bar'], $comments->toArray());
36+
$this->assertCount(1, $comments);
3237
}
3338

3439
public function testMergeComments()

tests/FlagsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function testFlags()
3434

3535
$this->assertSame(['bar', 'foo', 'one', 'three', 'two'], $flags->toArray());
3636
$this->assertCount(5, $flags);
37+
38+
$flags->delete('bar', 'one', 'two');
39+
40+
$this->assertSame(['foo', 'three'], $flags->toArray());
41+
$this->assertCount(2, $flags);
3742
}
3843

3944
public function testMergeFlags()

0 commit comments

Comments
 (0)