public function sort()
    {
        if ($this->modules) {
            $modules = [];
            $sorter = new StringSort();

            foreach ($this->modules as $slug => $module) {
                $sorter->add($slug, array_intersect(array_keys($module->getAttribute('require')), array_keys($this->modules)));
            }

            foreach ($sorter->sort() as $slug) {
                $modules[$slug] = $this->modules[$slug];
            }

            // Override modules array
            $this->modules = $modules;
        }

        return $this;
    }