Collects double column names for better error messages

@param array $row

@return array
777403
protected function collectDoubledColumns(array $row)
    {
        $foundNames = [];
        $doubledColumns = [];

        foreach ($row as $column) {

            if (isset($foundNames[$column])) {
                $doubledColumns[] = $column;
            }
            $foundNames[$column] = true;
        }

        return $doubledColumns;
    }
264562
public function applyFilter(array $row)
    {
        $wasTrueOneTime = false;
        $isApply = false;

        foreach ($this->getFilter()->getValues() as $filterValue) {
            $filter = $this->getFilter();
            $col = $filter->getColumn();

            $value = $row[$col->getUniqueId()];
            $value = $col->getType()->getFilterValue($value);

            if ($filter->getOperator() == DatagridFilter::BETWEEN) {
                //BETWEEN have to be tested in one call
                $isApply = DatagridFilter::isApply($value, $this->getFilter()->getValues(), $filter->getOperator());

                return $isApply;
            } else {
                $isApply = DatagridFilter::isApply($value, $filterValue, $filter->getOperator());
            }
            if (true === $isApply) {
                $wasTrueOneTime = true;
            }

            switch ($filter->getOperator()) {
                case DatagridFilter::NOT_LIKE:
                case DatagridFilter::NOT_LIKE_LEFT:
                case DatagridFilter::NOT_LIKE_RIGHT:
                case DatagridFilter::NOT_EQUAL:
                case DatagridFilter::NOT_IN:
                    if (false === $isApply) {
                        // normally one "match" is okay -> so it's applied
                        // but e.g. NOT_LIKE is not allowed to match so even if the othere rules are true
                        // it has to fail!
                        return false;
                    }
                    break;
            }
        }

        if (false === $isApply && true === $wasTrueOneTime) {
            return true;
        }

        return $isApply;
    }
1130131
public function createFromArray(array $row)
    {
        $entities = $this->unitOfWork->getEntityRegistry()->getEntityBuilder()->castToEntity([$row], $this->className);

        return array_shift($entities);
    }
461711
protected function get_responses_for_external($row) {
        $responses = [];
        foreach ($row as $el => $val) {
            // Get id from column name.
            if (preg_match('/^val(\d+)$/', $el, $matches)) {
                $id = $matches[1];

                $responses[] = [
                    'id' => $id,
                    'name' => $this->headers[$this->columns[$el]],
                    'printval' => $this->other_cols($el, $row),
                    'rawval' => $val,
                ];
            }
        }
        return $responses;
    }
872316
public static function convertToArray($row)
    {
        $data = $row instanceof Arrayable ? $row->toArray() : (array) $row;

        foreach ($data as &$value) {
            if (is_object($value) || is_array($value)) {
                $value = self::convertToArray($value);
            }

            unset($value);
        }

        return $data;
    }
211503
private function validateRows($rows)
    {
        if ($rows === false)
            return $rows;
        if (empty($rows))
            return $rows ?: [];
        foreach($rows as $e=>$r){

            $rows[$e] = $this->validateRow($r);
        }
        return $rows;

    }
1131771
public function replaceRows(array $rows): array
    {
        if (null === $this->data) {
            $this->buildIndex();
        }

        $list = [];
        foreach ($rows as $key => $row) {
            if (strpos($key, '@@')) {
                $key = $this->getNewKey();
            }
            $this->data[$key] = $list[$key] = $row;
        }

        if ($list) {
            $this->save();
        }

        return $list;
    }
420621
public function decode(string $row): array
    {
        $stream = fopen('php://memory', 'r+');
        fputs($stream, $row);
        rewind($stream);
        $result = [];
        $names = fgetcsv($stream, 0, "\t");
        if (empty($names) === true) {
            throw new \RuntimeException('failed decoding names from response');
        }
        while(($row = fgetcsv($stream, 0, "\t")) !== false) {
            $result[] = array_combine($names, $row);
        }
        fclose($stream);
        return $result;
    }
184942
private function resolveAvailableLocales(Row $row)
    {
        $locales = [];
        foreach ($row->getValues() as $key => $value) {
            if (preg_match('/^node.([a-zA-Z_]*?)Template/', $key, $matches) && '' !== $value
                && !$row->getValue(sprintf('node.%sShadow_on', $matches[1]))
            ) {
                $locales[] = $matches[1];
            }
        }

        return $locales;
    }
181022
public static function mapArraybleRow($row): array
    {
        // When dealing with eloquent models, we'll skip the relations
        // as we won't be able to display them anyway.
        if (method_exists($row, 'attributesToArray')) {
            return $row->attributesToArray();
        }

        if ($row instanceof Arrayable) {
            return $row->toArray();
        }

        // Convert StdObjects to arrays
        if (is_object($row)) {
            return json_decode(json_encode($row), true);
        }

        return $row;
    }
583713
protected function getAttributesString(array $row)
    {
        $attributes = [];
        foreach ($this->getAttributes() as $attrKey => $attrValue) {
            if ('href' === $attrKey) {
                $attrValue = $this->getLinkReplaced($row);
            }
            $attributes[] = $attrKey.'="'.$attrValue.'"';
        }

        return implode(' ', $attributes);
    }
646374
protected function getReferences(array $row){
		$references = [];
		$types      = [];

		foreach($row as &$field){
			$type = gettype($field);

			if($type === 'integer'){
				$types[] = 'i';
			}
			elseif($type === 'double'){
				$types[] = 'd';
			}
			else{
				$types[] = 's';
			}

			$references[] = &$field;
		}

		array_unshift($references, implode('', $types));

		return $references;
	}
1265043
public function getColNames()
    {
        $colNames = array();
        foreach ($this->_array as $row) {
            foreach (array_keys($row) as $key) {
                if (!is_numeric($key) && !isset($colNames[$key])) {
                    $colNames[$key] = $key;
                }
            }
        }
        return $colNames;
    }
1252287
protected function validateRowInRange($row)
    {
        $row = static::validateRow($row);
        if ($row > $this->rows) {
            throw new Exception('Requested Row exceeds matrix size');
        }

        return $row;
    }
949553
public function decode(string $row): array
    {
        $rows = explode(PHP_EOL, rtrim($row));
        return array_map(function($row) { return json_decode($row, true); }, $rows);
    }
480908
public function getContents($row)
    {
        if (is_callable($this->options['callable'])) {
            if (is_array($this->options['callable'])) {
                return call_user_func($this->options['callable'], [$row]);
            }

            return $this->options['callable']($row);
        }

        $propertyAccessor = PropertyAccess::createPropertyAccessor();

        try {
            return $propertyAccessor->getValue($row, $this->options['accessor_path']);
        } catch (UnexpectedTypeException $e) {
            return '';
        } catch (NoSuchPropertyException $e) {
            return $e->getMessage();
        }
    }
320675
protected function displayRowMessages($row)
    {
        $messages = array();

        foreach ($this->columns as $column) {
            $messages = array_merge($messages, $column->getMessages($row));
        }

        foreach ($this->spanning_columns as $column) {
            $messages = array_merge($messages, $column->getMessages($row));
        }

        if (count($messages) > 0) {
            $tr_tag = new SwatHtmlTag('tr');
            $tr_tag->class = 'swat-table-view-input-row-messages';
            $tr_tag->open();

            $td_tag = new SwatHtmlTag('td');
            $td_tag->colspan = $this->getXhtmlColspan();
            $td_tag->open();

            $ul_tag = new SwatHtmlTag('ul');
            $ul_tag->class = 'swat-table-view-input-row-messages';
            $ul_tag->open();

            $li_tag = new SwatHtmlTag('li');
            foreach ($messages as &$message) {
                $li_tag->setContent(
                    $message->primary_content,
                    $message->content_type
                );

                $li_tag->class = $message->getCssClass();
                $li_tag->display();
            }

            $ul_tag->close();

            $td_tag->close();
            $tr_tag->close();
        }
    }