protected function orderByDependencies(array $dependencies): array
    {
        $ordered = [];
        $available = array_keys($dependencies);

        while (0 !== \count($dependencies)) {
            $success = $this->doResolve($dependencies, $ordered, $available);

            if (false === $success) {
                throw new UnresolvableDependenciesException(
                    "The dependencies order could not be resolved.\n".print_r($dependencies, true)
                );
            }
        }

        return $ordered;
    }