protected function resolveDependencies()
    {
        $sortedNodes = [];
        while (count($this->nodesWithoutIncoming) > 0) {
            $node = array_pop($this->nodesWithoutIncoming);
            $sortedNodes[] = $node;
            $nodeHash = spl_object_hash($node);
            if (isset($this->dependenciesOutgoing[$nodeHash])) {
                foreach ($this->dependenciesOutgoing[$nodeHash] as $dependencyHash => $dependencyNode) {
                    unset($this->dependenciesOutgoing[$nodeHash][$dependencyHash]);
                    unset($this->dependenciesIncoming[$dependencyHash][$nodeHash]);

                    if (count($this->dependenciesIncoming[$dependencyHash]) === 0) {
                        $this->nodesWithoutIncoming[$dependencyHash] = $dependencyNode;
                    }
                }
            }
        }
        return $sortedNodes;
    }