Turn list of length 1 into value type

@param array $value

@return array
17656
protected function flattenList($value)
    {
        if ($value[0] === Type::T_LIST && count($value[2]) === 1) {
            return $this->flattenList($value[2][0]);
        }

        return $value;
    }
576898
private function convertArrayToEntityValue(array $value)
    {
        $excludes = $this->pluck(Entity::EXCLUDE_FROM_INDEXES, $value, false) ?: [];

        $properties = [];
        foreach ($value as $key => $val) {
            $properties[$key] = $this->valueObject(
                $val,
                in_array($key, $excludes)
            );
        }

        if (!$properties) {
            $properties = (object) $properties;
        }

        return [
            'entityValue' => [
                'properties' => $properties
            ]
        ];
    }
314451
protected function cleanValue($value)
	{
		if (is_array($value)) {
			return array_map(function ($v) {
				return $this->cleanValue($v);
			}, $value);
		} else {
			return stripslashes($value);
		}
	}
836848
public function parse(string $value)
    {
        $parsedValue = $this->parser->parse($value);
        if (false === $parsedValue instanceof ListValue) {
            return $parsedValue;
        }

        $mergedValues = array_reduce(
            $parsedValue->getValue(),
            [$this, 'mergeStrings'],
            $initial = []
        );

        return (1 === count($mergedValues))
            ? $mergedValues[0]
            : new ListValue($mergedValues)
        ;
    }
732661
public static function toArray($value)
    {
        if (is_array($value)) {
            return $value;
        }

        if ($value instanceof Collection) {
            return $value->all();
        }

        return [$value];
    }
959708
protected function extractArray($value)
    {
        if (empty($value)) {
            return [];
        }

        if ($value instanceof \Traversable) {
            $array = [];
            foreach ($value as $key => $value) {
                $array[$key] = $value;
            }
            return $array;
        }

        return (Array) $value;
    }
106586
public static function stringToArray($value)
    {
        $value = strtoupper($value);
        $newValue = [];
        foreach (explode(';', $value) as $part) {
            // Skipping empty parts.
            if (empty($part)) {
                continue;
            }
            list($partName, $partValue) = explode('=', $part);

            // The value itself had multiple values..
            if (false !== strpos($partValue, ',')) {
                $partValue = explode(',', $partValue);
            }
            $newValue[$partName] = $partValue;
        }

        return $newValue;
    }
1177991
private static function getListFromString($value)
    {
        if (is_string($value_array = $value)) {
            $value = str_replace([',', ' '], ';', $value);
            $value_array = explode(';', $value);
        }

        if (is_array($value_array)) {
            return array_filter(array_map('trim', $value_array));
        }

        return [];
    }
1272406
public static function toArray($value)
    {
        if (!is_array($value) && !$value instanceof Traversable) {
            $name = static::of($value);
            throw new TypeException("Can only cast Traversable and arrays to array, not $name");
        }

        return is_array($value) ? $value : iterator_to_array($value);
    }
688868
public function serialize($value)
    {
        if ($this->getDataType() === 'json') {
            return json_encode($value);
        } elseif ($this->getDataType() === 'array') {
            return json_encode($value);
        } elseif ($this->getDataType() === 'list') {
            return implode(',', $value);
        }

        return trim($value);
    }
729081
private function formatValueForApi($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'string':
                return ['string_value' => $value];
            case 'double':
            case 'integer':
                return ['number_value' => $value];
            case 'boolean':
                return ['bool_value' => $value];
            case 'NULL':
                return ['null_value' => NullValue::NULL_VALUE];
            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return ['struct_value' => $this->formatStructForApi($value)];
                }

                return ['list_value' => $this->formatListForApi($value)];
        }
    }
628975
public static function getValueAsList($value) {
		$tokens = token_get_all('<?php '.$value);

		$resultArray = array();
		
		// Le's find all the strings, and let's put each string in the table.
		foreach ($tokens as $token) {
			if ($token[0] == T_CONSTANT_ENCAPSED_STRING) {
				$resultArray[] = substr($token[1], 1, strlen($token[1])-2) ;
			}
		}

		return  $resultArray;
	}
357887
public static function toArray($value)
    {
        $data = [];

        $cookies = $value ? explode(';', $value) : [];
        foreach ($cookies as $cookie) {
            list($name, $value) = explode('=', $cookie);
            $name = trim($name);
            $value = urldecode($value);
            if (!isset($data[$name])) {
                $data[$name] = $value;
            }
        }
        return $data;
    }
117615
public static function arrayize($value)
    {
        $forbidden = [];
        if ($value instanceof Model) {
            $forbidden = $value->getHidden();
        }

        $array = [];
        foreach ($value as $key => $item) {
            if (!in_array(trim($key), $forbidden)) {
                switch (gettype($item)) {
                    case 'object':
                    case 'array':
                        $buffer = self::arrayize($item);
                        if (!empty($buffer)) {
                            $array[trim($key)] = $buffer;
                        }

                        break;
                    default:
                        if (isset($item)) {
                            $array[trim($key)] = $item;
                        }
                }
            }
        }

        return $array;
    }
912287
public function reverseTransform($value)
    {
        $result = array();
        if (is_array($value)) {
            array_walk_recursive($value, function($item, $key) use (&$result) {
                if ($item) {
                    $result[] = $key;
                }
            });
        }

        return $result;
    }
1043499
static public function stripslashes($value) 
    {
        if(!is_array($value)) {
            return stripslashes($value);
        }
        foreach($value as $key => $val) {
            $value[$key] = static::stripslashes($val);
        }
        return $value;
    }
385872
public function unwrapValue($value)
    {
        if (is_array($value)) {
            $self = $this;
            return array_map(function ($item) use ($self) {
                if ($item instanceof Context) {
                    return $item->unwrap();
                } else {
                    return $self->unwrapValue($item);
                }
            }, $value);
        } else {
            return $value;
        }
    }