File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace Wikibase \DataModel \Snak ;
44
5+ use InvalidArgumentException ;
6+ use Traversable ;
57use Wikibase \DataModel \HashArray ;
68use Wikibase \DataModel \Internal \MapValueHasher ;
79
1719 */
1820class SnakList extends HashArray {
1921
22+ /**
23+ * @param Snak[]|Traversable $snaks
24+ *
25+ * @throws InvalidArgumentException
26+ */
27+ public function __construct ( $ snaks = [] ) {
28+ if ( !is_array ( $ snaks ) && !( $ snaks instanceof Traversable ) ) {
29+ throw new InvalidArgumentException ( '$snaks must be an array or an instance of Traversable ' );
30+ }
31+
32+ foreach ( $ snaks as $ index => $ snak ) {
33+ $ this ->setElement ( $ index , $ snak );
34+ }
35+ }
36+
2037 /**
2138 * @see GenericArrayObject::getObjectType
2239 *
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public function instanceProvider() {
3535 $ instances = [];
3636
3737 foreach ( $ this ->constructorProvider () as $ args ) {
38- $ instances [] = [ new $ class ( array_key_exists ( 0 , $ args ) ? $ args [0 ] : null ) ];
38+ $ instances [] = [ new $ class ( array_key_exists ( 0 , $ args ) ? $ args [0 ] : [] ) ];
3939 }
4040
4141 return $ instances ;
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ public function invalidConstructorArgumentsProvider() {
8484 $ id1 = new PropertyId ( 'P1 ' );
8585
8686 return [
87+ [ null ],
8788 [ false ],
8889 [ 1 ],
8990 [ 0.1 ],
You can’t perform that action at this time.
0 commit comments