diff --git "a/class-wb\\Claims.php" "b/class-wb\\Claims.php" index 13471ee..d6aedea 100644 --- "a/class-wb\\Claims.php" +++ "b/class-wb\\Claims.php" @@ -1,73 +1,112 @@ . # Wikibase namespace wb; /** - * A Claim collector. + * Claim collector */ class Claims { - var $claims = []; + /** + * All the claims + * + * @TODO: check if it can be declared as private without breaking casts :^) + * @var array + */ + public $claims = []; + /** + * Constructor + * + * @param $claims array + */ public function __construct( $claims = [] ) { foreach( $claims as $claim ) { $this->add( $claim ); } } + /** + * Add a claim + * + * @param $claim $Claim + * @return self + */ public function add( Claim $claim ) { $this->claims[] = $claim; return $this; } + /** + * Count all + * + * @return int + */ public function count() { return count( $this->claims ); } + /** + * Get all the claims in a certain property + * + * @param $property string + * @return array + */ public function getInProperty( $property ) { $claims = []; foreach( $this->claims as $claim ) { if( $claim->getMainSnak()->getProperty() === $property ) { $claims[] = $claim; } } return $claims; } + /** + * Check if there are claims in a certain property + * + * @param $property string + * @return bool + */ public function haveProperty( $property ) { foreach( $this->claims as $claim ) { if( $claim->getMainSnak()->getProperty() === $property ) { return true; } } return false; } + /** + * Get all the claims indexed by their property + * + * @return array + */ public function getAll() { $properties = []; foreach( $this->claims as $claim ) { $property = $claim->getMainSnak()->getProperty(); if( ! isset( $properties[ $property ] ) ) { $properties[ $property ] = []; } $properties[ $property ][] = $claim; } return $properties; } }