diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 index 8ecab03..05c4d35 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## in progress +## 1.2.0 (30. April 2019) ++ Added feature for whole section removal + Added tests for php 7.3 ## 1.1.0 (21. December 2018) diff --git a/src/ComposerReader.php b/src/ComposerReader.php old mode 100644 new mode 100755 index eefe7fb..7aebb0f --- a/src/ComposerReader.php +++ b/src/ComposerReader.php @@ -134,6 +134,20 @@ public function updateSection($section, $data) $this->_content = $content; } + + /** + * @inheritdoc + */ + public function removeSection($section) + { + $content = $this->getContent(); + + if(isset($content[$section])) { + unset ($content[$section]); + } + + $this->_content = $content; + } /** * Run a composer command in the given composer.json. diff --git a/src/ComposerReaderInterface.php b/src/ComposerReaderInterface.php old mode 100644 new mode 100755 index 70f53d7..4374550 --- a/src/ComposerReaderInterface.php +++ b/src/ComposerReaderInterface.php @@ -28,6 +28,16 @@ public function contentSection($section, $defaultValue); */ public function updateSection($section, $data); + /** + * Remove a given section. + * + * This will remove the whole section! + * + * @param string $section + * @since 1.2.0 + */ + public function removeSection($section); + /** * Save the current Data. * diff --git a/tests/ComposerReaderTest.php b/tests/ComposerReaderTest.php old mode 100644 new mode 100755 index 19ad4ad..b061188 --- a/tests/ComposerReaderTest.php +++ b/tests/ComposerReaderTest.php @@ -106,4 +106,13 @@ public function testRunCommand() $this->assertTrue($r); } + + public function testRemove() + { + $reader = new ComposerReader($this->getValidJson()); + + $reader->removeSection('autoload'); + + $this->assertArrayNotHasKey('autoload', $reader->getContent()); + } }