Issue #2392805 by yched: Remove useless isset() checks in ItemList / FieldItemList
parent
09e8ddabb6
commit
4f1de4e0f8
|
@ -27,10 +27,9 @@ use Drupal\Core\TypedData\TypedDataInterface;
|
|||
class FieldItemList extends ItemList implements FieldItemListInterface {
|
||||
|
||||
/**
|
||||
* Numerically indexed array of field items, implementing the
|
||||
* FieldItemInterface.
|
||||
* Numerically indexed array of field items.
|
||||
*
|
||||
* @var array
|
||||
* @var \Drupal\Core\Field\FieldItemInterface[]
|
||||
*/
|
||||
protected $list = array();
|
||||
|
||||
|
@ -111,14 +110,12 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
|
|||
* @todo Revisit the need when all entity types are converted to NG entities.
|
||||
*/
|
||||
public function getValue($include_computed = FALSE) {
|
||||
if (isset($this->list)) {
|
||||
$values = array();
|
||||
foreach ($this->list as $delta => $item) {
|
||||
$values[$delta] = $item->getValue($include_computed);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -239,12 +236,10 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
|
|||
* The name of the method.
|
||||
*/
|
||||
protected function delegateMethod($method) {
|
||||
if (isset($this->list)) {
|
||||
foreach ($this->list as $item) {
|
||||
$item->{$method}();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -31,9 +31,9 @@ use Drupal\Core\TypedData\TypedDataInterface;
|
|||
class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
||||
|
||||
/**
|
||||
* Numerically indexed array items.
|
||||
* Numerically indexed array of items.
|
||||
*
|
||||
* @var array
|
||||
* @var \Drupal\Core\TypedData\TypedDataInterface[]
|
||||
*/
|
||||
protected $list = array();
|
||||
|
||||
|
@ -41,14 +41,12 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* Overrides \Drupal\Core\TypedData\TypedData::getValue().
|
||||
*/
|
||||
public function getValue() {
|
||||
if (isset($this->list)) {
|
||||
$values = array();
|
||||
foreach ($this->list as $delta => $item) {
|
||||
$values[$delta] = $item->getValue();
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\TypedData\TypedData::setValue().
|
||||
|
@ -66,9 +64,7 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
}
|
||||
|
||||
// Clear the values of properties for which no value has been passed.
|
||||
if (isset($this->list)) {
|
||||
$this->list = array_intersect_key($this->list, $values);
|
||||
}
|
||||
|
||||
// Set the values.
|
||||
foreach ($values as $delta => $value) {
|
||||
|
@ -94,14 +90,12 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
*/
|
||||
public function getString() {
|
||||
$strings = array();
|
||||
if (isset($this->list)) {
|
||||
foreach ($this->list as $item) {
|
||||
$strings[] = $item->getString();
|
||||
}
|
||||
// Remove any empty strings resulting from empty items.
|
||||
return implode(', ', array_filter($strings, '\Drupal\Component\Utility\Unicode::strlen'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -146,17 +140,15 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* Implements \ArrayAccess::offsetExists().
|
||||
*/
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->list) && array_key_exists($offset, $this->list) && $this->get($offset)->getValue() !== NULL;
|
||||
return array_key_exists($offset, $this->list) && $this->get($offset)->getValue() !== NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \ArrayAccess::offsetUnset().
|
||||
*/
|
||||
public function offsetUnset($offset) {
|
||||
if (isset($this->list)) {
|
||||
unset($this->list[$offset]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -196,24 +188,20 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* Implements \IteratorAggregate::getIterator().
|
||||
*/
|
||||
public function getIterator() {
|
||||
if (isset($this->list)) {
|
||||
return new \ArrayIterator($this->list);
|
||||
}
|
||||
return new \ArrayIterator(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Countable::count().
|
||||
*/
|
||||
public function count() {
|
||||
return isset($this->list) ? count($this->list) : 0;
|
||||
return count($this->list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\TypedData\ListInterface::isEmpty().
|
||||
*/
|
||||
public function isEmpty() {
|
||||
if (isset($this->list)) {
|
||||
foreach ($this->list as $item) {
|
||||
if ($item instanceof ComplexDataInterface || $item instanceof ListInterface) {
|
||||
if (!$item->isEmpty()) {
|
||||
|
@ -225,7 +213,6 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -233,7 +220,6 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function filter($callback) {
|
||||
if (isset($this->list)) {
|
||||
$removed = FALSE;
|
||||
// Apply the filter, detecting if some items were actually removed.
|
||||
$this->list = array_filter($this->list, function ($item) use ($callback, &$removed) {
|
||||
|
@ -252,7 +238,6 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
$item->setContext($delta, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -270,11 +255,10 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* Magic method: Implements a deep clone.
|
||||
*/
|
||||
public function __clone() {
|
||||
if (isset($this->list)) {
|
||||
foreach ($this->list as $delta => $item) {
|
||||
$this->list[$delta] = clone $item;
|
||||
$this->list[$delta]->setContext($delta, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue