public function sort(Comparator $comparator = null) { if (is_null($comparator)) { if (TypeUtil::isPrimitive($this->type)) { sort($this->elements); } elseif (TypeUtil::isObjectType($this->type)) { if (!TypeUtil::isClassComparable($this->type)) { throw new ListNotSortableException("List of type " . $this->type . " is not sortable"); } usort($this->elements, function ($a, $b) { return $a->compareTo($b); }); } } else { usort($this->elements, function ($a, $b) use($comparator) { return $comparator->compare($a, $b); }); } }
function testPrimitiveIsNotObjectType() { $this->assertFalse(TypeUtil::isObjectType("string")); }