Constructs a custom basic associative array based on the PHPIDS report
when an intrusion is detected. Will contains essential data such as
impact, targeted inputs and detection descriptions.

@param Report[] $reports
@return mixed[]
177355
private function getDetectionData($reports): array
    {
        $data = [
            'impact' => 0,
            'detections' => []
        ];
        foreach ($reports as $report) {
            $variableName = $report->getVarName();
            $filters = $report->getFilterMatch();
            if (!isset($data['detections'][$variableName])) {
                $data['detections'][$variableName] = [
                    'value' => $report->getVarValue(),
                    'events' => []
                ];
            }
            foreach ($filters as $filter) {
                $data['detections'][$variableName]['events'][] = [
                    'description' => $filter->getDescription(),
                    'impact' => $filter->getImpact()
                ];
                $data['impact'] += $filter->getImpact();
            }
        }
        return $data;
    }
1240880
public function getMultipleByName(array $permissions): array
    {
        if ($this->permissions === null) {
            $this->getAll();
        }

        $results = [];

        foreach ($permissions as $permission) {
            if (isset($this->names[$permission])) {
                $results[] = $this->permissions[$this->names[$permission]];
            }
        }

        return $results;
    }
950636
public function insert(array $values)
    {
        // Since every insert gets treated like a batch insert, we will have to detect
        // if the user is inserting a single document or an array of documents.
        $batch = true;

        foreach ($values as $value) {
            // As soon as we find a value that is not an array we assume the user is
            // inserting a single document.
            if (!is_array($value)) {
                $batch = false;
                break;
            }
        }

        if (!$batch) {
            $values = [$values];
        }

        // Batch insert
        $result = $this->collection->insertMany($values);

        return (1 == (int) $result->isAcknowledged());
    }
1306356
private function getUniqueValueFromArray(array $values)
    {
        $serializedValues = false;
        foreach ($values as $key => $value) {
            if (!\is_array($value)) {
                continue;
            }

            $values[$key] = \serialize($value);

            $serializedValues = true;
        }

        if (!$serializedValues) {
            return 1 === \count(\array_unique($values)) ? $values[0] : null;
        }

        return 1 === \count(\array_unique($values)) ? \unserialize($values[0], ['allowed_classes' => true]) : null;
    }
29349
private function tracksIds(array $items): array
    {
        $_ = [];
        foreach ($items as $item)
        {
            $_[] = sprintf('%d_%d', $item[1], $item[0]);
        }

        return $_;
    }
1370900
function fromAssociativeResultArray($values) {
		foreach (static::$_columns as $column_name => &$type) {
			if (array_key_exists($column_name, $values)) {
				$this->{$column_name} = $values[$column_name];
			}
		}
		if (static::$_primaryKeys && !$this->hasPrimaryKeyValues()) {
			return false;
		}
		$this->castInts();
		$this->setNew(false);
		return true;
	}
1005684
protected function setForeignKeys(array $values)
    {
        foreach ($values as $key => &$value) {
            if ($this->endsWith($key, '_id')) {
                $value = $this->generateKey($value);
            }
        }

        return $values;
    }
589648
public function parseAlerts()
    {

        $reports = [ ];

        preg_match_all(
            '/\s*(?<ip>[a-f0-9:\.]+)/',
            // Someone from spamcop found it funny to prefix IPv6 addresses, so lets strip that off
            str_replace('IPv6 ', '', $this->parsedMail->getMessageBody()),
            $matches
        );

        $received = $this->parsedMail->getHeaders()['date'];
        if (strtotime(date('d-m-Y H:i:s', strtotime($received))) !== (int)strtotime($received)) {
            $received = date('d-m-Y H:i:s');
        }

        if (is_array($matches) && !empty($matches['ip']) && count($matches['ip']) > 0) {
            foreach ($matches['ip'] as $ip) {
                $reports[] = [
                    'Source-IP' => $ip,
                    'Received-Date' => $received,
                    'Note' => 'A spamtrap hit notification was received.'.
                        ' These notifications do not provide any evidence.'
                ];
            }
        }

        return $reports;

    }
686555
private function getItemById(array $ids)
    {
        $ids = array_map('intval', $ids);

        try {
            $stmtResult = $this->neo4jClient->run('MATCH (n) WHERE ID(n) IN {ids} RETURN n', ['ids' => $ids]);
        } catch (\Exception $e) {
            return [];
        }

        $result = [];

        if (!$stmtResult->size()) {
            return $result;
        }

        foreach ($stmtResult->records() as $record) {
            $result[] = $record->get('n');
        }

        return $result;
    }
96645
private function parseIds(array $ids)
    {
        $ids = \array_map('intval', $ids);
        $ids = \array_filter($ids);
        $ids = \array_unique($ids);

        return \array_values($ids);
    }
477481
public static function idToArrayIndex(&$models)
    {
        $result = [];
        foreach ($models as $index => &$model) {
            $result[$model->id] = $index;
        }
        return $result;
    }
745175
public function fetch(ReportInterface $report, array $configuration = [])
    {
        if (null === $type = $report->getDataFetcher()) {
            throw new \InvalidArgumentException('Cannot fetch data for ReportInterface instance without DataFetcher defined.');
        }

        /** @var DataFetcherInterface $dataFetcher */
        $dataFetcher = $this->registry->get($type);
        $configuration = empty($configuration) ? $report->getDataFetcherConfiguration() : $configuration;

        return $dataFetcher->fetch($configuration);
    }
672556
public function getReportsInfo()
    {
        $reports    = [];
        $reportsRaw = $this->getFlexiData($this->getEvidenceURL().'/reports');
        if (!empty($reportsRaw) && array_key_exists('reports', $reportsRaw) && !empty($reportsRaw['reports'])
            && array_key_exists('report', $reportsRaw['reports']) &&
            !empty($reportsRaw['reports']['report'])) {
            if (\Ease\jQuery\Part::isAssoc($reportsRaw['reports']['report'])) {
                $reports = [$reportsRaw['reports']['report']['reportId'] => $reportsRaw['reports']['report']];
            } else {
                $reports = self::reindexArrayBy($reportsRaw['reports']['report'],
                        'reportId');
            }
        }
        return $reports;
    }
1153960
protected function getResultsByRelatedKey($relations)
	{
		$resultsByRelatedKey = [];

		foreach ($relations as $relation)
		{
			if (!isset($resultsByRelatedKey[$relation->{$this->associativeLocal}]))
			{
				$resultsByRelatedKey[$relation->{$this->associativeLocal}] = new Rows;
			}

			$resultsByRelatedKey[$relation->{$this->associativeLocal}]->push($relation);
		}

		return $resultsByRelatedKey;
	}
717414
private function processResults($results)
    {
        $entries = $this->connection->getEntries($results);

        $objects = [];

        if (array_key_exists('count', $entries)) {
            for ($i = 0; $i < $entries['count']; $i++) {
                $entry = $this->newLdapEntry($entries[$i], $this->connection);

                $objects[] = $entry->getAttributes();
            }

            if (!empty($this->sortByField)) {
                return $this->processSortBy($objects);
            }
        }

        return $objects;
    }
648187
public function introspect(): array
	{
		$output = [];
		$registry = $this->getRegistry();
		$subreports = $this->container->findByTag(ReportExtension::TAG_INTROSPECTION);
		foreach ($subreports as $service => $tag) {
			$output[] = $def = ArrayHash::from([
				'id' => 'rp' . md5(serialize($tag)),
				'file' => $tag['file'],
				'rid' => $tag['rid'],
				'sid' => $tag['sid'],
				'metadata' => $tag['metadata'],
				'services' => [
					'report' => (object) [
						'type' => $this->container->getServiceType($tag['services']['report']),
						'name' => Arrays::pop(explode('\\', $this->container->getServiceType($tag['services']['report']))),
						'created' => false,
						'service' => null,
					],
					'subreport' => (object) [
						'type' => $this->container->getServiceType($tag['services']['subreport']),
						'name' => Arrays::pop(explode('\\', $this->container->getServiceType($tag['services']['subreport']))),
						'created' => false,
						'service' => null,
					],
					'datasource' => (object) [
						'type' => $this->container->getServiceType($tag['services']['datasource']),
						'name' => Arrays::pop(explode('\\', $this->container->getServiceType($tag['services']['datasource']))),
						'created' => false,
						'service' => null,
					],
					'renderer' => (object) [
						'type' => $this->container->getServiceType($tag['services']['renderer']),
						'name' => Arrays::pop(explode('\\', $this->container->getServiceType($tag['services']['renderer']))),
						'created' => false,
						'service' => null,
					],
				],
				'tags' => [],
			]);

			$def->tags = $tag;

			if ((isset($registry[$tag['services']['report']]) && !$registry[$tag['services']['report']] instanceof Container)) {
				$def->services->report->created = true;
				$def->services->report->service = $registry[$tag['services']['report']];
			}

			if ((isset($registry[$tag['services']['subreport']]) && !$registry[$tag['services']['subreport']] instanceof Container)) {
				$def->services->subreport->created = true;
				$def->services->subreport->service = $registry[$tag['services']['subreport']];
			}

			if ((isset($registry[$tag['services']['datasource']]) && !$registry[$tag['services']['datasource']] instanceof Container)) {
				$def->services->datasource->created = true;
				$def->services->datasource->service = $registry[$tag['services']['datasource']];
			}

			if ((isset($registry[$tag['services']['renderer']]) && !$registry[$tag['services']['renderer']] instanceof Container)) {
				$def->services->renderer->created = true;
				$def->services->renderer->service = $registry[$tag['services']['renderer']];
			}
		}

		return $output;
	}
1239190
public function info($identities)
	{
		$ids   = [];
		$names = [];
		if (is_array($identities))
		{
			foreach ($identities as $identity)
			{
				if (gettype($identity) === 'integer')
				{
					// it's the id
					$ids[] = $identity;
				}
				else
				{
					// the summoner name
					$names[] = $identity;
				}
			}
		}
		else
		{
			if (gettype($identities) === 'integer')
			{
				// it's the id
				$ids[] = $identities;
			}
			else
			{
				// the summoner name
				$names[] = $identities;
			}
		}

		if (count($ids) > 0)
		{
			// it's the id
			$ids = $this->infoByIds($ids);
		}
		if (count($names) > 0)
		{
			// the summoner name
			$names = $this->infoByNames($names);
		}

		$summoners = $ids + $names;

		if (count($summoners) == 1)
		{
			return reset($summoners);
		}
		else
		{
			return $summoners;
		}

	}