protected function selectNearestValue(array $values, $wantedValue)
    {
        if (in_array($wantedValue, $values)) {
            $result = $wantedValue;
        } else {
            $result = null;
            $minDelta = PHP_INT_MAX;
            foreach ($values as $value) {
                $delta = abs($value - $wantedValue);
                if ($delta < $minDelta) {
                    $minDelta = $delta;
                    $result = $value;
                }
            }
        }

        return $result;
    }