Remove password and pwd contents and clean up message status data and single item arrays

@param array $data
@return mixed
971326
private function _toCleanArray(array $data)
    {
        switch (count($data)) {
            case 0:
                return null;

            case 1:
                if (isset($data[0])) {
                    // Return array content when only one item
                    // with the key 0.
                    if (is_array($data[0])) {
                        return $this->_toCleanArray($data[0]);
                    } else {
                        return $data[0];
                    }
                }
                break;

            case 2:
                if (isset($data[0], $data[1]) && is_string($data[1])) {
                    if (('info' === $data[1]) || ('warning' === $data[1]) || ('error' === $data[1])) {
                        if (is_array($data[0])) {
                            return $this->_toCleanArray($data[0]);
                        } else {
                            return $data[0];
                        }
                    }
                }
        }
        $output = array();
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $output[$key] = $this->_toCleanArray($value);
            } else {
                if (is_string($value)) {
                    // Filter passwords from the log
                    if (\MUtil_String::contains($key, 'password', true) || \MUtil_String::contains($key, 'pwd', true)) {
                        $value = '****';
                    }
                } elseif ($value instanceof Zend_Date) {
                    // Output iso representation for date objects
                    $value = $value->getIso();
                }
                $output[$key] = $value;
            }
        }

        return $output;
    }
300871
public static function REMOVE_EMPTY( array $data)
	{
		$a = array();
	    foreach ($data as $key => $value) {
	       $a[$key] = is_array($value)?array_filter($value):$value;
	    }
	    return array_filter($a);
	}
392169
protected function cleanData(array $data): array
    {
        $options = $this->getOptions();

        $disallowedDataKeys = array(
            $options->getIdColumnName(),
            $options->getLeftColumnName(),
            $options->getRightColumnName(),
            $options->getLevelColumnName(),
            $options->getParentIdColumnName(),
        );

        if (null !== $options->getScopeColumnName()) {
            $disallowedDataKeys[] = $options->getScopeColumnName();
        }

        return array_diff_key($data, array_flip($disallowedDataKeys));
    }
559245
protected function _modify(array $data = null)
	{
		if ($this->is_valid()) {
			if (isset($data['password'])) {
				$this->password = Auth::hash($data['password']);
			}
			return $this->save();
		}

		return $this->errors->full_messages();
	}
113026
public function process(array $data)
    {
        $processedData = [
            'meta' => Hash::get($data, 'meta'),
            'data' => []
        ];
        $processedData['meta']['type'] = 'Module';
        $processedData['meta']['title'] = $this->name();
        unset($data['meta']);
        foreach ($data as $attr => $value) {
            $processedData['data'][$attr] = $value;
        }
        return $processedData;
    }
270425
public function batchReplaceParty(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_PARTY_BATCH_REPLACE_PREFIX, $data, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok' ? $result['jobid'] : $this->dump($result);
    }
604783
private function hashContent(string $data) {
    $hash = hash_hmac(
      $this->algorithm,
      $data,
      $this->key
    );

    return $this->validate($hash);
  }
1027031
public function remove($data)
    {
        if (is_array($data)) {
            foreach ($data as $entity) {
                $this
                    ->manager
                    ->remove($entity);
            }
        } else {
            $this
                ->manager
                ->remove($data);
        }

        $this
            ->manager
            ->flush($data);

        return $data;
    }
1087463
private function normalizeArrayForNewLines(array $data) {
		foreach($data as $k => $item) {
			if(is_string($item)) {
				$data[$k] = str_replace(["\r\n", "\n\r", "\r"], "\n", $item);
			} elseif(is_array($item)) {
				$data[$k] = $this->normalizeArrayForNewLines($item);
			}
		}
		return $data;
	}
238970
protected function validate(array &$data)
    {
        $messages = [];
        if (!empty($data['errors']) && !empty($data['activity']) && !empty($data['requests'])) {
            array_push($messages, ['warning', trans('It is recommended to periodically clean system logs.')]);
        }
        $data = array_merge($data, ['messages' => $messages]);
        return $data;
    }
1036201
private function cleanData(array $data) : array
  {
    foreach($data as $key => $value) {
      $data[$key] = $this->replace($key, $value);
    }

    return $data;
  }
97870
public function updateNewsMaterial(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_MATERIAL_DELETE_PREFIX, $data, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errcode']) && !$result['errcode'];
    }
849414
public function deserialize(array $data)
    {
        $original = $data;
        $this->deserializeTos($data);
        $data = $this->getJavascriptsData($data);
        $data = $this->getLogoData($data);
        unset($data['tos']['text']);
        //maybe move this somewhere else
        unset($data['archives']);

        $data = array_merge($this->serialize([Options::SERIALIZE_MINIMAL]), $data);
        ksort($data);
        $data = json_encode($data, JSON_PRETTY_PRINT);

        file_put_contents($this->filePath, $data);

        return $original;
    }
101338
public function encrypt($data): string
    {
        if (!$this->password)
        {
            return JSON::encode($data);
        }

        return $this->security()
            ->encrypt(JSON::encode($data));
    }
242550
protected function parseData(array $data)
	{
		$this->files = array();

		foreach ($data as $key => $value)
		{
			// If this value is an instance of the HttpFoundation File class we will
			// remove it from the data array and add it to the files array, which
			// is used to conveniently separate out the files from other datas.
			if ($value instanceof File)
			{
				$this->files[$key] = $value;

				unset($data[$key]);
			}
		}

		return $data;
	}
643872
public function filter($data)
    {
        // filtering and sorting
        if ($this->options['plugins-only']) {
            unset($data['themes']);
        }
        if ($this->options['themes-only']) {
            unset($data['plugins']);
        }

        $filter = [
            $this->options['filter'],
            $this->options['installed-only'],
            $this->options['updates-only'],
            $this->options['desc']
        ];

        if (\count(array_filter($filter))) {
            foreach ($data as $type => $packages) {
                foreach ($packages as $slug => $package) {
                    $filter = true;

                    // Filtering by string
                    if ($this->options['filter']) {
                        $filter = preg_grep('/(' . implode('|', $this->options['filter']) . ')/i', [$slug, $package->name]);
                    }

                    // Filtering updatables only
                    if ($filter && $this->options['installed-only']) {
                        $method = ucfirst(preg_replace('/s$/', '', $package->package_type));
                        $function = 'is' . $method . 'Installed';
                        $filter = $this->gpm->{$function}($package->slug);
                    }

                    // Filtering updatables only
                    if ($filter && $this->options['updates-only']) {
                        $method = ucfirst(preg_replace('/s$/', '', $package->package_type));
                        $function = 'is' . $method . 'Updatable';
                        $filter = $this->gpm->{$function}($package->slug);
                    }

                    if (!$filter) {
                        unset($data[$type][$slug]);
                    }
                }
            }
        }

        return $data;
    }
1170747
protected function excludeKeys(array $data) {
        $keys = isset($this->config['excludeKeys']) ? $this->config['excludeKeys'] : [];
        foreach ($data as $key => &$value) {
            if (in_array($key, $keys)) {
                unset($data[$key]);
            } else if (is_array($value)) {
                $value = $this->excludeKeys($value);
            }
        }

        return $data;
    }