public function getAncestorByType($type)
    {
        $current = $this;
        do
        {
            $parent = $current->parent;
            $current = $parent;
        }
        while($parent && !$parent instanceof $type);

        return $parent;
    }