Repository: symfony/symfony
File: src/Symfony/Component/Config/Resource/ReflectionClassResource.php (PHP)

Code before:

        return hash_final($hash);
    }

    private function generateSignature(\ReflectionClass $class): iterable
    {
        $attributes = [];
        foreach ($class->getAttributes() as $a) {
            $attributes[] = [$a->getName(), (string) $a];
        }
        yield print_r($attributes, true);
        $attributes = [];

        yield $class->getDocComment() ?: '';
        yield (int) $class->isFinal();
        yield (int) $class->isAbstract();

        $enum = null;
        if ($class->isEnum()) {
            $enum = new \ReflectionEnum($class->name);
        }

        if ($class->isTrait()) {
            yield print_r(class_uses($class->name), true);
        } elseif ($enum) {
            yield print_r(class_implements($class->name), true);
        } else {
            yield print_r(class_parents($class->name), true);
            yield print_r(class_implements($class->name), true);
            yield print_r($class->getConstants(), true);
        }

        foreach ($class->getReflectionConstants() as $constant) {
            foreach ($constant->getAttributes() as $a) {
                $attributes[] = [$a->getName(), (string) $a];
            }
            yield print_r($attributes, true);
            $attributes = [];
            yield $constant->getName();
            if ($enum && $constant->isEnumCase() && $case = $enum->getCase($constant->name)) {
                if ($case instanceof \ReflectionEnumBackedCase) {
                    yield $case->getBackingValue();
                }
            }
        }

        if (!$class->isInterface()) {
            $defaults = $class->getDefaultProperties();

            foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
                foreach ($p->getAttributes() as $a) {

Review comment (refactor):
can't we remove this "elseif" and rely on the "else" ? then maybe simplify a bit the added loop below since getConstants will return part of it already?

Code after:

        return hash_final($hash);
    }

    private function generateSignature(\ReflectionClass $class): iterable
    {
        $attributes = [];
        foreach ($class->getAttributes() as $a) {
            $attributes[] = [$a->getName(), (string) $a];
        }
        yield print_r($attributes, true);
        $attributes = [];

        yield $class->getDocComment() ?: '';
        yield (int) $class->isFinal();
        yield (int) $class->isAbstract();

        if ($class->isTrait()) {
            yield print_r(class_uses($class->name), true);
        } else {
            yield print_r(class_parents($class->name), true);
            yield print_r(class_implements($class->name), true);
            yield print_r($class->getConstants(), true);
        }

        foreach ($class->getReflectionConstants() as $constant) {
            foreach ($constant->getAttributes() as $a) {
                $attributes[] = [$a->getName(), (string) $a];
            }
            yield $constant->name.print_r($attributes, true);
            $attributes = [];
        }

        if (!$class->isInterface()) {
            $defaults = $class->getDefaultProperties();

            foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
                foreach ($p->getAttributes() as $a) {
                    $attributes[] = [$a->getName(), (string) $a];
                }
                yield print_r($attributes, true);
                $attributes = [];

                yield $p->getDocComment() ?: '';
                yield $p->isDefault() ? '<default>' : '';
                yield $p->isPublic() ? 'public' : 'protected';
                yield $p->isStatic() ? 'static' : '';
                yield '$'.$p->name;
                yield print_r(isset($defaults[$p->name]) && !\is_object($defaults[$p->name]) ? $defaults[$p->name] : null, true);
            }
        }