protected function findParent(\ReflectionClass $class, $parents)
    {
        $parents = array_reverse($parents);

        foreach (array_reverse($parents) as $parent) {
            if ($class->getName() === get_class($parent)) {
                return $parent;
            }
        }

        foreach (array_reverse($parents) as $parent) {
            if ($class->isInstance($parent)) {
                return $parent;
            }
        }

        return null;
    }