Skip to content

[cnpj-gen] Analyze CnpjGenerator constructor behavior when both $options and scalar args are provided #40

@coderabbitai

Description

@coderabbitai

Overview

When a CnpjGeneratorOptions instance is passed as $options to CnpjGenerator::__construct(), the scalar arguments $format, $prefix, and $type are silently ignored. This is in contrast to the generate() method, which layers scalar args as overrides on top of the instance options.

Design question

Should the constructor apply the same override layering as generate()? Two possible approaches:

  1. Layer the scalar args as overrides — when $options is a CnpjGeneratorOptions instance, still apply ['format' => $format, 'prefix' => $prefix, 'type' => $type] on top, making the constructor symmetric with generate().
  2. Raise an exception when both an options instance and scalar args are provided simultaneously, making the precedence explicit rather than silently favouring the instance.

The current silent-ignore behaviour is documented in the constructor docblock but may surprise consumers who expect symmetry with generate().

References

Raised by @juliolmuller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions