Skip to content

Commit 1498c17

Browse files
authored
Merge pull request #5 from rochdi80tn/master
Add removeSection() method to remove a whole section
2 parents c478fea + 6df2d6b commit 1498c17

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

CHANGELOG.md

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## in progress
7+
## 1.2.0 (30. April 2019)
88

9+
+ Added feature for whole section removal
910
+ Added tests for php 7.3
1011

1112
## 1.1.0 (21. December 2018)

src/ComposerReader.php

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public function updateSection($section, $data)
134134

135135
$this->_content = $content;
136136
}
137+
138+
/**
139+
* @inheritdoc
140+
*/
141+
public function removeSection($section)
142+
{
143+
$content = $this->getContent();
144+
145+
if(isset($content[$section])) {
146+
unset ($content[$section]);
147+
}
148+
149+
$this->_content = $content;
150+
}
137151

138152
/**
139153
* Run a composer command in the given composer.json.

src/ComposerReaderInterface.php

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public function contentSection($section, $defaultValue);
2828
*/
2929
public function updateSection($section, $data);
3030

31+
/**
32+
* Remove a given section.
33+
*
34+
* This will remove the whole section!
35+
*
36+
* @param string $section
37+
* @since 1.2.0
38+
*/
39+
public function removeSection($section);
40+
3141
/**
3242
* Save the current Data.
3343
*

tests/ComposerReaderTest.php

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ public function testRunCommand()
106106

107107
$this->assertTrue($r);
108108
}
109+
110+
public function testRemove()
111+
{
112+
$reader = new ComposerReader($this->getValidJson());
113+
114+
$reader->removeSection('autoload');
115+
116+
$this->assertArrayNotHasKey('autoload', $reader->getContent());
117+
}
109118
}

0 commit comments

Comments
 (0)