previousValue = $previousValue = (array) json_decode($previousValue, true); } if (is_string($currentValue)) { // decode JSON string (update internal property too) $this->currentValue = $currentValue = (array) json_decode($currentValue, true); } if (!is_array($previousValue) || !is_array($currentValue)) { // both values must be arrays return false; } // convert all the elements of the arrays into strings $previousValue = array_map('strval', $previousValue); $currentValue = array_map('strval', $currentValue); // sort arrays to make sure the position of the elements is the same sort($previousValue); sort($currentValue); // the arrays must be different return $previousValue !== $currentValue; } /** * @inheritDoc */ protected function doDescribe($previousValue, $currentValue) { $chunks = []; $added = array_diff($currentValue, $previousValue); if ($added) { $chunks[] = $this->describeAddedItems($added); } $removed = array_diff($previousValue, $currentValue); if ($removed) { $chunks[] = $this->describeRemovedItems($removed); } return implode(' ', $chunks); } /** * Describes the added items. * * @param string[] $added * * @return string */ abstract protected function describeAddedItems(array $added); /** * Describes the removed items. * * @param string[] $removed * * @return string */ abstract protected function describeRemovedItems(array $removed); }