Make options declaration mandatory

Aperta
#237 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php
Ambito
databases

Direzione di ricerca

Start by reading AbstractAnonymizer validation and the existing option handling, then inspect anonymizer implementations that duplicate the columns validation introduced in #234. Define how initialize(), addOption(), declared options, and the Options array should interact; done means mandatory and type validation is centralized and declared options can support the proposed column-name checks.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In all multiple column anonymizers that accept other options than column names, columns cannot be named with the same names as options, such as sample_size, source, etc...

In #234 I introduced this in validation:

        $columns = $this->options->get('columns', null, true);
        if (!\is_array($columns)) {
            throw new ConfigurationException("'columns' must be an array of string or null values.");
        }
        $invalidNames = ['source', 'columns', 'file_csv_enclosure', 'file_csv_escape', 'file_csv_separator', 'file_skip_header'];
        foreach ($columns as $index => $column) {
            if (\in_array($column, $invalidNames)) {
                throw new ConfigurationException(\sprintf("'columns' values cannot be one of ('%s') for column #%d.", \implode("', '", $invalidNames), $index));
            }
            if (!\is_string($column) && null !== $column) {
                throw new ConfigurationException(\sprintf("'columns' must be an array of string or null values (invalid type for column #%d.", $index));
            }
        }

This works, but I now have to repeat this a second, then a third time for new anonymizer implementations.

It's becoming hard to maintain:

  • copy-pasted code more than two times is wrong,
  • some other options can be set at the abstract anonymizer level (sample size, for example).

What I propose is to force anonymizers to declare their options, for example:

    protected function initialize(): void
    {
        $this->addOption(
            'sample_size',
            Option::TYPE_INT,
            "Some short description",
            null /* default value) */,
            true /* Is optional (default true) */,
            "Some long description..."
        );
        // ...
    }

Then, in AbstractAnonymizer, when validation happens, check the given Options array and validate automatically at least the mandatory and type state.

  • We can also generate documentation from this.
  • We also can get rid of long class PHP doc.
  • We can generate meaningful console commands that documents it as well.
  • We can automatize some validation in check command.
  • We can use this declared attribute list for the custom validation I presented on top of this issue: instead of iterating over a raw array, we could iterate over \array_keys($this->getDeclaredOptions()) for example.
Lingua principale
PHP
Stelle
235
Fork
17
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di makinacorpus/DbToolsBundle

Tutte le issue di makinacorpus/DbToolsBundle

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.