Repository: symfony/symfony
File: src/Symfony/Component/Validator/ValidatorBuilder.php (PHP)

Code before:

        return $this;
    }

    /**
     * Adds a list of YAML constraint mappings file to the validator.
     *
     * @param string[] $paths The paths to the mapping files
     *
     * @return $this
     */
    public function addYamlMappings(array $paths): static
    {
        if (null !== $this->metadataFactory) {
            throw new ValidatorException('You cannot add custom mappings after setting a custom metadata factory. Configure your metadata factory instead.');
        }

        $this->yamlMappings = array_merge($this->yamlMappings, $paths);

        return $this;
    }

    /**
     * Adds a list of classes with mapping constraints as attributes.
     *
     * @param array<class-string, class-string[]> $classes
     *
     * @return $this
     */
    public function addAttributeMappings(array $classes): static
    {
        if (null !== $this->metadataFactory) {
            throw new ValidatorException('You cannot add custom mappings after setting a custom metadata factory. Configure your metadata factory instead.');
        }

        $this->attributeMappings = array_merge_recursive($this->attributeMappings, $classes);

        return $this;
    }

    /**
     * Enables constraint mapping using the given static method.
     *
     * @return $this
     */
    public function addMethodMapping(string $methodName): static
    {
        if (null !== $this->metadataFactory) {
            throw new ValidatorException('You cannot add custom mappings after setting a custom metadata factory. Configure your metadata factory instead.');
        }


Review comment (suggestion):
should be defined as `array<class-string, list<class-string>>`, to ensure that the recursive merge produces the expected type, as the recursion behavior is totally different for lists and non-list arrays

Code after:

        return $this;
    }

    /**
     * Adds a list of YAML constraint mappings file to the validator.
     *
     * @param string[] $paths The paths to the mapping files
     *
     * @return $this
     */
    public function addYamlMappings(array $paths): static
    {
        if (null !== $this->metadataFactory) {
            throw new ValidatorException('You cannot add custom mappings after setting a custom metadata factory. Configure your metadata factory instead.');
        }

        $this->yamlMappings = array_merge($this->yamlMappings, $paths);

        return $this;
    }

    /**
     * Adds classes with mapping constraints as attributes.
     *
     * The keys are the classes on which the constraints should be added.
     * The values are the classes that contain the constraints to add as attributes.
     *
     * @param array<class-string, list<class-string>> $classes
     *
     * @return $this
     */
    public function addAttributeMappings(array $classes): static
    {
        if (null !== $this->metadataFactory) {
            throw new ValidatorException('You cannot add custom mappings after setting a custom metadata factory. Configure your metadata factory instead.');
        }

        $this->attributeMappings = array_merge_recursive($this->attributeMappings, $classes);

        return $this;
    }

    /**
     * Enables constraint mapping using the given static method.
     *
     * @return $this
     */
    public function addMethodMapping(string $methodName): static
    {
        if (null !== $this->metadataFactory) {