Skip to content

Commit

Permalink
Add AttributeAware::removeAttribute()
Browse files Browse the repository at this point in the history
This reverts the revert graphp#171/graphp#138 (commit
09ea558).
  • Loading branch information
clue committed Oct 2, 2019
1 parent e19c342 commit ab2212e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Attribute/AttributeAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function getAttribute($name, $default = null);
*/
public function setAttribute($name, $value);

/**
* Removes a single attribute with the given $name
*
* @param string $name
*/
public function removeAttribute($name);

/**
* get a container for all attributes
*
Expand Down
1 change: 1 addition & 0 deletions src/Attribute/AttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface AttributeBag extends AttributeAware
{
// public function getAttribute($name, $default);
// public function setAttribute($name, $value);
// public function removeAttribute();
// public function getAttributeBag();

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public function setAttribute($name, $value)
return $this;
}

/**
* Removes a single attribute with the given $name
*
* @param string $name
*/
public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

/**
* get an array of all attributes
*
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagNamespaced.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public function setAttribute($name, $value)
$this->bag->setAttribute($this->prefix . $name, $value);
}

/**
* Removes a single attribute with the given $name
*
* @param string $name
*/
public function removeAttribute($name)
{
$this->bag->removeAttribute($this->prefix . $name);
}

/**
* get an array of all attributes
*
Expand Down
10 changes: 10 additions & 0 deletions src/Attribute/AttributeBagReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public function setAttribute($name, $value)
return $this;
}

/**
* Removes a single attribute with the given $name
*
* @param string $name
*/
public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

/**
* get an array of all attributes
*
Expand Down
5 changes: 5 additions & 0 deletions src/Edge/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ public function setAttribute($name, $value)
$this->attributes[$name] = $value;
}

public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

public function getAttributeBag()
{
return new AttributeBagReference($this->attributes);
Expand Down
5 changes: 5 additions & 0 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ public function setAttribute($name, $value)
$this->attributes[$name] = $value;
}

public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

public function getAttributeBag()
{
return new AttributeBagReference($this->attributes);
Expand Down
5 changes: 5 additions & 0 deletions src/Vertex.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ public function setAttribute($name, $value)
$this->attributes[$name] = $value;
}

public function removeAttribute($name)
{
unset($this->attributes[$name]);
}

public function getAttributeBag()
{
return new AttributeBagReference($this->attributes);
Expand Down
13 changes: 13 additions & 0 deletions tests/Attribute/AbstractAttributeAwareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public function testAttributeSetGetDefault(AttributeAware $entity)
$this->assertEquals('default', $entity->getAttribute('unknown', 'default'));
}

/**
* @depends testAttributeAwareInterface
* @param AttributeAware $entity
*/
public function testAttributeSetRemoveGet(AttributeAware $entity)
{
$entity->setAttribute('test', 'value');
$this->assertEquals('value', $entity->getAttribute('test'));

$entity->removeAttribute('test');
$this->assertEquals(null, $entity->getAttribute('test'));
}

/**
* @depends testAttributeAwareInterface
* @param AttributeAware $entity
Expand Down

0 comments on commit ab2212e

Please sign in to comment.