Skip to content

Commit 9d48cfc

Browse files
johnathanmdellclue
authored andcommitted
Added AttributeAware::removeAttribute()
1 parent 0336a4d commit 9d48cfc

8 files changed

Lines changed: 85 additions & 0 deletions

File tree

src/Attribute/AttributeAware.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function getAttribute($name, $default = null);
2626
*/
2727
public function setAttribute($name, $value);
2828

29+
/**
30+
* @param $name
31+
* @return mixed
32+
*/
33+
public function removeAttribute($name);
34+
2935
/**
3036
* get a container for all attributes
3137
*

src/Attribute/AttributeBagContainer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ public function setAttribute($name, $value)
4141
return $this;
4242
}
4343

44+
/**
45+
* remove a single attribute with the given $name
46+
*
47+
* @param $name
48+
* @return $this
49+
*/
50+
public function removeAttribute($name)
51+
{
52+
if (isset($this->attributes[$name]) === true) {
53+
unset($this->attributes[$name]);
54+
}
55+
56+
return $this;
57+
}
58+
4459
/**
4560
* get an array of all attributes
4661
*

src/Attribute/AttributeBagNamespaced.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public function setAttribute($name, $value)
6868
$this->bag->setAttribute($this->prefix . $name, $value);
6969
}
7070

71+
/**
72+
* remove a single attribute with the given $name
73+
*
74+
* @param $name
75+
* @return $this
76+
*/
77+
public function removeAttribute($name)
78+
{
79+
if (isset($this->attributes[$name]) === true) {
80+
unset($this->attributes[$name]);
81+
}
82+
83+
return $this;
84+
}
85+
7186
/**
7287
* get an array of all attributes
7388
*

src/Attribute/AttributeBagReference.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ public function setAttribute($name, $value)
5555
return $this;
5656
}
5757

58+
/**
59+
* remove a single attribute with the given $name
60+
*
61+
* @param $name
62+
* @return $this
63+
*/
64+
public function removeAttribute($name)
65+
{
66+
if (isset($this->attributes[$name]) === true) {
67+
unset($this->attributes[$name]);
68+
}
69+
70+
return $this;
71+
}
72+
5873
/**
5974
* get an array of all attributes
6075
*

src/Edge/Base.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ public function setAttribute($name, $value)
303303
$this->attributes[$name] = $value;
304304
}
305305

306+
public function removeAttribute($name)
307+
{
308+
if (isset($this->attributes[$name]) === true) {
309+
unset($this->attributes[$name]);
310+
}
311+
}
312+
306313
public function getAttributeBag()
307314
{
308315
return new AttributeBagReference($this->attributes);

src/Graph.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ public function setAttribute($name, $value)
462462
$this->attributes[$name] = $value;
463463
}
464464

465+
public function removeAttribute($name)
466+
{
467+
if (isset($this->attributes[$name]) === true) {
468+
unset($this->attributes[$name]);
469+
}
470+
}
471+
465472
public function getAttributeBag()
466473
{
467474
return new AttributeBagReference($this->attributes);

src/Vertex.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ public function setAttribute($name, $value)
382382
$this->attributes[$name] = $value;
383383
}
384384

385+
public function removeAttribute($name)
386+
{
387+
if (isset($this->attributes[$name]) === true) {
388+
unset($this->attributes[$name]);
389+
}
390+
}
391+
385392
public function getAttributeBag()
386393
{
387394
return new AttributeBagReference($this->attributes);

tests/Attribute/AbstractAttributeAwareTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public function testAttributeSetGetDefault(AttributeAware $entity)
2727
$this->assertEquals('default', $entity->getAttribute('unknown', 'default'));
2828
}
2929

30+
/**
31+
* @depends testAttributeAwareInterface
32+
* @param AttributeAware $entity
33+
*/
34+
public function testAttributeSetRemoveGet(AttributeAware $entity)
35+
{
36+
$entity->setAttribute('test', 'value');
37+
$this->assertEquals('value', $entity->getAttribute('test'));
38+
39+
$entity->removeAttribute('test');
40+
$this->assertEquals(null, $entity->getAttribute('test'));
41+
}
42+
3043
/**
3144
* @depends testAttributeAwareInterface
3245
* @param AttributeAware $entity

0 commit comments

Comments
 (0)