Skip to content

Commit

Permalink
Merge pull request #5 from rochdi80tn/master
Browse files Browse the repository at this point in the history
Add removeSection() method to remove a whole section
  • Loading branch information
nadar authored Apr 30, 2019
2 parents c478fea + 6df2d6b commit 1498c17
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/ComposerReader.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/ComposerReaderInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/ComposerReaderTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 1498c17

Please sign in to comment.