LeanMapper\DataDifference::getByPivot PHP Method

getByPivot() public method

Gets differences by given pivot
public getByPivot ( mixed $pivot ) : array
$pivot mixed
return array
    public function getByPivot($pivot)
    {
        $result = [];
        foreach ($this->added as $entry) {
            if (!isset($entry[$pivot])) {
                throw new InvalidArgumentException("Invalid pivot given: '{$pivot}'.");
            }
            if (isset($result[$entry[$pivot]])) {
                $result[$entry[$pivot]]++;
            } else {
                $result[$entry[$pivot]] = 1;
            }
        }
        foreach ($this->removed as $entry) {
            if (!isset($entry[$pivot])) {
                throw new InvalidArgumentException("Invalid pivot given: '{$pivot}'.");
            }
            if (isset($result[$entry[$pivot]])) {
                $result[$entry[$pivot]]--;
                if ($result[$entry[$pivot]] === 0) {
                    unset($result[$entry[$pivot]]);
                }
            } else {
                $result[$entry[$pivot]] = -1;
            }
        }
        return $result;
    }