public function sort(array $nodes)
    {
        $this->buildNodeDependencies($nodes);
        $sortedNodes = $this->resolveDependencies();

        $dependencyCount = array_filter($this->dependenciesOutgoing, function ($a) {
            return $a !== [];
        });
        if (count($dependencyCount) > 0) {
            throw new WorkspaceException('Cannot publish a list of nodes because of cycles', 1416484223);
        }

        return $sortedNodes;
    }