Permalink
Browse files

Make interfaces more fluent

This addresses #15.
  • Loading branch information...
1 parent 908b759 commit 6de9485e12f6a65e494f23c719f78646a46f6b15 @lanthaler committed Feb 6, 2013
Showing with 66 additions and 10 deletions.
  1. +5 −1 Document.php
  2. +4 −0 DocumentInterface.php
  3. +4 −0 Graph.php
  4. +4 −0 GraphInterface.php
  5. +4 −0 LanguageTaggedString.php
  6. +21 −9 Node.php
  7. +16 −0 NodeInterface.php
  8. +4 −0 TypedValue.php
  9. +4 −0 Value.php
View
@@ -84,6 +84,8 @@ public function __construct($iri = null)
public function setIri($iri)
{
$this->iri = new IRI($iri);
+
+ return $this;
}
/**
@@ -150,7 +152,7 @@ public function removeGraph($graph = null)
if (null === $graph) {
$this->defaultGraph = new Graph($this);
- return;
+ return $this;
}
$name = $graph;
@@ -171,6 +173,8 @@ public function removeGraph($graph = null)
unset($this->namedGraphs[$name]);
}
+
+ return $this;
}
/**
@@ -22,6 +22,8 @@
* Set the document's IRI
*
* @param string|IRI The IRI.
+ *
+ * @return self
*/
public function setIri($iri);
@@ -80,6 +82,8 @@ public function containsGraph($name);
* @param null|string|GraphInterface $graph The graph (or its name) to
* remove. If null is passed,
* the default will be reset.
+ *
+ * @return self
*/
public function removeGraph($graph = null);
}
View
@@ -84,6 +84,8 @@ public function removeNode(NodeInterface $node)
}
unset($this->nodes[$id]);
+
+ return $this;
}
/**
@@ -167,6 +169,8 @@ public function removeFromDocument()
$this->document = null;
$doc->removeGraph($this);
+
+ return $this;
}
/**
View
@@ -39,6 +39,8 @@ public function createNode($id = null);
* document.
*
* @param NodeInterface $node The node to remove from the document.
+ *
+ * @return self
*/
public function removeNode(NodeInterface $node);
@@ -94,6 +96,8 @@ public function getDocument();
/**
* Removes the graph from the document
+ *
+ * @return self
*/
public function removeFromDocument();
@@ -43,6 +43,8 @@ public function __construct($value, $language)
*
* @param string $language The language.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If the language is not a string. No
* further checks are currently done.
*/
@@ -53,6 +55,8 @@ public function setLanguage($language)
}
$this->language = $language;
+
+ return $this;
}
/**
View
@@ -81,23 +81,29 @@ public function setType($type)
}
}
- return $this->setProperty(self::TYPE, $type);
+ $this->setProperty(self::TYPE, $type);
+
+ return $this;
}
/**
* {@inheritdoc}
*/
public function addType(NodeInterface $type)
{
- return $this->addPropertyValue(self::TYPE, $type);
+ $this->addPropertyValue(self::TYPE, $type);
+
+ return $this;
}
/**
* {@inheritdoc}
*/
public function removeType(NodeInterface $type)
{
- return $this->removePropertyValue(self::TYPE, $type);
+ $this->removePropertyValue(self::TYPE, $type);
+
+ return $this;
}
/**
@@ -157,6 +163,8 @@ public function removeFromGraph()
$this->graph = null;
$g->removeNode($this);
+
+ return $this;
}
/**
@@ -174,11 +182,11 @@ public function setProperty($property, $value)
{
if (null === $value) {
$this->removeProperty($property);
-
- return;
+ } else {
+ $this->doMergeIntoProperty((string) $property, array(), $value);
}
- $this->doMergeIntoProperty((string) $property, array(), $value);
+ return $this;
}
/**
@@ -195,6 +203,8 @@ public function addPropertyValue($property, $value)
}
$this->doMergeIntoProperty((string) $property, $existing, $value);
+
+ return $this;
}
/**
@@ -248,7 +258,7 @@ private function doMergeIntoProperty($property, $existingValues, $value)
public function removeProperty($property)
{
if (!isset($this->properties[(string) $property])) {
- return;
+ return $this;
}
$values = is_array($this->properties[(string) $property])
@@ -262,6 +272,8 @@ public function removeProperty($property)
}
unset($this->properties[(string) $property]);
+
+ return $this;
}
/**
@@ -270,7 +282,7 @@ public function removeProperty($property)
public function removePropertyValue($property, $value)
{
if (!$this->isValidPropertyValue($value) || !isset($this->properties[(string) $property])) {
- return;
+ return $this;
}
$values =& $this->properties[(string) $property];
@@ -293,7 +305,7 @@ public function removePropertyValue($property, $value)
if (0 === count($values)) {
unset($this->properties[(string) $property]);
- return;
+ return $this;
}
$this->properties[(string) $property] = array_values($values); // re-index the array
View
@@ -28,6 +28,8 @@ public function getId();
*
* @param null|NodeInterface|array[NodeInterface] The type(s) of this node.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If type is not null, a Node or an
* array of Nodes.
*/
@@ -37,13 +39,17 @@ public function setType($type);
* Add a type to this node
*
* @param NodeInterface The type to add.
+ *
+ * @return self
*/
public function addType(NodeInterface $type);
/**
* Remove a type from this node
*
* @param NodeInterface The type to remove.
+ *
+ * @return self
*/
public function removeType(NodeInterface $type);
@@ -78,6 +84,8 @@ public function getGraph();
*
* This will also remove all references to and from other nodes in this
* node's graph.
+ *
+ * @return self
*/
public function removeFromGraph();
@@ -104,6 +112,8 @@ public function isBlankNode();
* @param mixed $value The value of the property. This MUST NOT be
* an array. Use null to remove the property.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If value is an array or an object
* which is neither a language-tagged
* string nor a typed value or a node.
@@ -125,6 +135,8 @@ public function setProperty($property, $value);
* @param mixed $value The value of the property. This MUST NOT be
* an array.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If value is an array or an object
* which is neither a language-tagged
* string nor a typed value or a node.
@@ -135,6 +147,8 @@ public function addPropertyValue($property, $value);
* Removes a property and all it's values
*
* @param string $property The name of the property to remove.
+ *
+ * @return self
*/
public function removeProperty($property);
@@ -144,6 +158,8 @@ public function removeProperty($property);
* @param string $property The name of the property.
* @param mixed $value The value of the property. This MUST NOT be
* an array.
+ *
+ * @return self
*/
public function removePropertyValue($property, $value);
View
@@ -46,6 +46,8 @@ public function __construct($value, $type)
*
* @param string $type The type.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If the type is not a string. No
* further checks are currently done.
*/
@@ -56,6 +58,8 @@ public function setType($type)
}
$this->type = $type;
+
+ return $this;
}
/**
View
@@ -31,6 +31,8 @@
*
* @param string $value The value.
*
+ * @return self
+ *
* @throws \InvalidArgumentException If the value is not a string.
*/
public function setValue($value)
@@ -40,6 +42,8 @@ public function setValue($value)
}
$this->value = $value;
+
+ return $this;
}
/**

0 comments on commit 6de9485

Please sign in to comment.