Mmoreram\PHPFormatter\Sorter\UseSorter::createGroups PHP Method

createGroups() private method

Create blocks.
private createGroups ( array $namespaces ) : array
$namespaces array Namespaces
return array Groups
    private function createGroups(array $namespaces)
    {
        $groups = [];
        foreach ($this->groups as $group) {
            if (is_array($group)) {
                $groups[] = array_fill_keys($group, []);
            } else {
                $groups[$group] = [];
            }
        }
        if (!array_key_exists('_main', $groups)) {
            $groups = array_merge(['_main' => []], $groups);
        }
        foreach ($namespaces as $namespace) {
            foreach ($groups as $groupKey => $group) {
                if (is_int($groupKey)) {
                    foreach ($group as $subGroupKey => $subGroup) {
                        if (strpos($namespace, $subGroupKey) === 0) {
                            array_push($groups[$groupKey][$subGroupKey], $namespace);
                            continue 3;
                        }
                    }
                } elseif (is_string($groupKey) && strpos($namespace, $groupKey) === 0) {
                    array_push($groups[$groupKey], $namespace);
                    continue 2;
                }
            }
            array_push($groups['_main'], $namespace);
        }
        return $groups;
    }