@param bool $usedPrioritySorting

@return array
@throws CircularReferenceException

@SuppressWarnings(PHPMD.NPathComplexity)
6346
protected function orderFixturesByDependencies($usedPrioritySorting)
    {
        $sequenceForClasses = $orderedFixtures = [];

        // If fixtures were already ordered by number then we need
        // to remove classes which are not instances of OrderedFixtureInterface
        // in case fixtures implementing DependentFixtureInterface exist.
        // This is because, in that case, the method orderFixturesByDependencies
        // will handle all fixtures which are not instances of
        // OrderedFixtureInterface
        if ($usedPrioritySorting) {
            $this->orderedFixtures = array_filter(
                $this->orderedFixtures,
                function ($fixture) {
                    return $fixture instanceof OrderedFixtureInterface;
                }
            );
        }

        // First we determine which classes has dependencies and which don't
        foreach ($this->fixtures as $fixture) {
            $fixtureClass = get_class($fixture);

            if ($fixture instanceof OrderedFixtureInterface) {
                continue;
            } elseif ($fixture instanceof DependentFixtureInterface) {
                $dependenciesClasses = $fixture->getDependencies();

                $this->validateDependencies($fixtureClass, $dependenciesClasses);

                // We mark this class as unsequenced
                $sequenceForClasses[$fixtureClass] = -1;
            } else {
                // This class has no dependencies, so we assign 0
                $sequenceForClasses[$fixtureClass] = 0;
            }
        }

        // Now we order fixtures by sequence
        $sequence  = 1;
        $lastCount = -1;

        while (($count = count($unsequencedClasses = $this->getUnsequencedClasses($sequenceForClasses))) > 0
            && $count !== $lastCount) {
            foreach ($unsequencedClasses as $key => $class) {
                $fixture                 = $this->fixtures[$class];
                $dependencies            = $fixture->getDependencies();
                $unsequencedDependencies = $this->getUnsequencedClasses($sequenceForClasses, $dependencies);

                if (count($unsequencedDependencies) === 0) {
                    $sequenceForClasses[$class] = $sequence++;
                }
            }

            $lastCount = $count;
        }

        // If there're fixtures unsequenced left and they couldn't be sequenced,
        // it means we have a circular reference
        if ($count > 0) {
            $msg = 'Classes "%s" have produced a CircularReferenceException. ';
            $msg .= 'An example of this problem would be the following: Class C has class B as its dependency. ';
            $msg .= 'Then, class B has class A has its dependency. Finally, class A has class C as its dependency. ';
            $msg .= 'This case would produce a CircularReferenceException.';

            throw new CircularReferenceException(sprintf($msg, implode(',', $unsequencedClasses)));
        } else {
            // We order the classes by sequence
            asort($sequenceForClasses);

            foreach ($sequenceForClasses as $class => $sequence) {
                // If fixtures were ordered
                $orderedFixtures[] = $this->fixtures[$class];
            }
        }

        $this->orderedFixtures = array_merge($this->orderedFixtures, $orderedFixtures);
    }
823448
protected function sort() {
    if( !empty( $this->_callback_list ) ) {

      // sort by the priorities, but keep the original indexes (we need it for the repopulation)
      $priority_list = $this->_priority_list;
      asort( $priority_list );

      // repopulate the callbacks based on the new priority "map"
      $tmp                  = $this->_callback_list;
      $this->_callback_list = [];
      foreach( $priority_list as $index => $_ ) {
        $this->_callback_list[] = $tmp[ $index ];
      }

      // reset priority indexes (to match the repopulated array)
      $this->_priority_list = array_values( $priority_list );
    }
  }
29988
public function getPrimaryKeys($usePrefix = true)
    {
        $ret = [];

        /** @var $obj ActiveRecordInterface */
        foreach ($this as $key => $obj) {
            $key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
            $ret[$key]= $obj->getPrimaryKey();
        }

        return $ret;
    }
431247
public function getRawValue(): array
	{
		$primaryValues = [];
		foreach ($this->getIterator() as $entity) {
			if ($entity->isPersisted()) {
				$primaryValues[] = $entity->getValue('id');
			}
		}
		return $primaryValues;
	}
756965
public function getUseDeclarations() {
    $declarations = [];
    /** @var \Pharborist\Namespaces\UseDeclarationBlockNode[] $use_blocks */
    $use_blocks = $this->children(Filter::isInstanceOf('\Pharborist\Namespaces\UseDeclarationBlockNode'));
    foreach ($use_blocks as $use_block) {
      foreach ($use_block->getDeclarationStatements() as $use_statement) {
        $declarations = array_merge($declarations, $use_statement->getDeclarations()->toArray());
      }
    }
    return new NodeCollection($declarations, FALSE);
  }
927262
public function getRelated()
	{
		if($this->parent->getRawColumnValue($this->getForeignKey()) === null)
		{
			return false;
		}

		return $this->first();
	}
1170974
public function sortAscending(array $prefList)
    {
        $comparator = new MatchedPreferenceComparator();

        usort(
            $prefList,
            function (MatchedPreferenceInterface $lValue, MatchedPreferenceInterface $rValue) use ($comparator) {
                return -1 * $comparator->compare($lValue, $rValue);
            }
        );

        return $prefList;
    }
853883
protected function getValidPriority($desiredPriority)
    {
        // make sure the priority is an integer so we don't screw up the math
        // also multiply everything by 10000 because the priority must be an integer
        // as it will be used as the $filters[$selector] array key
        $desiredPriority = (int) $desiredPriority * 10000;
        if (! in_array($desiredPriority, $this->allocatedPriorities)) {
            return $desiredPriority;
        }
        // the increment will be used to determine when we find an available spot
        // obviously if you have 10000 filters with priority 0,
        // the 10000th will get to priority one but that's a chance we are willing to take
        $increment = 1;
        while (in_array($desiredPriority, $this->allocatedPriorities)) {
            $desiredPriority += $increment;
        }
        return $desiredPriority;
    }
370163
public function sortByName(/* bool $useNaturalSort = false */)
    {
        if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
            @trigger_error(sprintf('The "%s()" method will have a new "bool $useNaturalSort = false" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
        }
        $useNaturalSort = 0 < \func_num_args() && func_get_arg(0);

        $this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL : Iterator\SortableIterator::SORT_BY_NAME;

        return $this;
    }
214953
protected function _fix_getIterator()
    {
        $return = array();

        $data = &$this->_referDataArrayReference();
        foreach ($data as $k => $v) {
            (!array_key_exists($k, $this->__mapedPropObjects))
                ?: $k = $this->__mapedPropObjects[$k];

            $return[] = array($k => $v);
        }

        return new ArrayIterator($return);
    }
587784
private function getPrimaryItemDRSForRole( $primaryItem, $roleUri )
	{
		if ( ! isset( $primaryItem[ $roleUri ] ) )
		{
			$this->log()->warning( "The role '$roleUri' does not exist in the requested primary item" );
			return array();
		}

		// Nothing to do if there are no hypercubes for the primary item
		if ( !isset( $primaryItem[ $roleUri ]['hypercubes'] ) || ! count( $primaryItem[ $roleUri ]['hypercubes'] ) )
		{
			return array();
		}

		$role = $this->getDefinitionRoleRef( $roleUri );
		if ( ! $role )
		{
			return array();
		}

		$primaryItemId = $primaryItem[ $roleUri ]['label'];

		$result = array();

		foreach ( $primaryItem[ $roleUri ]['hypercubes'] as $hypercubeId )
		{
			if ( ! $this->resolvePrimaryItemHypercubeDRS( $primaryItemId, $hypercubeId, $role ) )
			{
				// Something went wrong
				continue;
			}

			if ( ! isset( $this->resolvedDRSCache[ $roleUri ][ $hypercubeId ] ) )
			{
				// Probably not good
				continue;
			}

			$result[ $hypercubeId ][ $roleUri ] = $this->resolvedDRSCache[ $roleUri ][ $hypercubeId ];
		}

		return $result;
	}
807871
public function getReferences(): array
    {
        if (empty($this->parent)) {
            throw new NodeException("Unable to aggregate reference values, parent is missing");
        }

        if (empty($this->parent->references[$this->outerKey])) {
            return [];
        }

        return array_keys($this->parent->references[$this->outerKey]);
    }
1009170
public function toArray($useIdentifierKeys = null)
    {
        $originalUseIdentifierKeys = $this->useIdentifierKeys;
        $useIdentifierKeys = isset($useIdentifierKeys) ? (boolean) $useIdentifierKeys : $this->useIdentifierKeys;
        $cursor = $this;

        /* Let iterator_to_array() decide to use keys or not. This will avoid
         * superfluous RiakCursor::info() from the key() method until the
         * cursor position is tracked internally.
         */
        $this->useIdentifierKeys = true;

        $results = $this->retry(function() use ($cursor, $useIdentifierKeys) {
            return iterator_to_array($cursor, $useIdentifierKeys);
        }, true);

        $this->useIdentifierKeys = $originalUseIdentifierKeys;

        return $results;
    }
488610
private function addRewriterReferenceByPriority(array $rewriterReferences, $taggedServiceId, array $tag)
    {
        $priority = (
            array_key_exists(self::TAG_ATTRIBUTE_PRIORITY, $tag)
            ? (int) $tag[self::TAG_ATTRIBUTE_PRIORITY]
            : self::DEFAULT_PRIORITY
        );

        if (!array_key_exists($priority, $rewriterReferences)) {
            $rewriterReferences[$priority] = [];
        }

        $rewriterReferences[$priority][] = $this->referenceFactory->createReference($taggedServiceId);

        return $rewriterReferences;
    }
436705
public function sort()
    {
        foreach ($this->nodeList as $vertex) {
            if ($vertex->state !== self::NOT_VISITED) {
                continue;
            }

            $this->visit($vertex);
        }

        $sortedList = $this->sortedNodeList;

        $this->nodeList       = [];
        $this->sortedNodeList = [];

        return array_reverse($sortedList);
    }
956180
public function getUserSelectedSorting()
    {
        $sortDirections = ['desc', 'asc'];

        $request = Registry::get(\OxidEsales\Eshop\Core\Request::class);
        $sortBy = $request->getRequestParameter($this->getSortOrderByParameterName());
        $sortOrder = $request->getRequestParameter($this->getSortOrderParameterName());

        if ($sortBy &&
            $sortOrder &&
            Registry::getUtils()->isValidAlpha($sortOrder) &&
            in_array(Str::getStr()->strtolower($sortOrder), $sortDirections) &&
            in_array($sortBy, $this->getSortColumns())
        ) {
            return ['sortby' => $sortBy, 'sortdir' => $sortOrder];
        }
    }
840966
private function getCommitOrder(): array
    {
        static $calculator = null;
        if (null === $calculator) {
            $calculator = new CommitOrderCalculator();
        }

        $objects = array_merge($this->documentInsertions, $this->documentUpdates, $this->documentDeletions);

        $classes = [];
        foreach ($objects as $object) {
            $metadata = $this->manager->getClassMetadata(get_class($object));

            $calculator->addClass($metadata);
            $classes[$metadata->getName()] = $metadata;
        }

        $order = $calculator->getOrder(array_keys($classes));

        return array_map(function (array $element) {
            return $element[0]->getClassName();
        }, $order);
    }