Provide additional context in the DisallowedEmptyRule error message

Offen
#103 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
php
Bereich
devtools

Rechercherichtung

Start by locating the DisallowedEmptyRule implementation and the code that constructs its generic error message. Update the diagnostic so it includes the type passed to empty(), then verify that mixed-based cases can be targeted without broad path-based suppression.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

In doctrine/dbal, the Schema and Driver APIs use array<string,mixed> parameters heavily (e.g. as connection parameters and column definitions).

While overall the value type is mixed, each array element usually has a certain type.

Since most of the array elements are optional, the boolean values are checked like this:

if (isset($field['unique']) && $field['unique']) {
    // this is a unique column 
}

Or like this:

if (empty($column['fixed'])) {
    // this is a fixed-length column
}

Before reimplementing these APIs using objects with well-defined properties, I want to suppress the error reporting of such cases.

The first case is suppressed nicely like this:

-
    message: '~^Only booleans are allowed.*mixed given~'
    paths:
        - %currentWorkingDirectory%/src/Driver/*/Driver.php
        - %currentWorkingDirectory%/src/Platforms/*Platform.php
        - %currentWorkingDirectory%/src/Schema/*SchemaManager.php

However, the second cannot be pin-pointed since the error message is generic for all cases:

Construct empty() is not allowed. Use more strict comparison.

I could rework expressions like empty($array[$key]) to isset($array[$key]) && $array[$key] and suppress them as above but I'd rather do the opposite since the empty() approach is more compact and has exactly the same meaning.

Would it be possible to include the type passed to empty() so that instead of whitelisting all such cases in certain paths, I could only whitelist the cases where a mixed like the above is passed?

Vorherrschende Sprache
PHP
Sterne
714
Forks
63
Ø Merge
1 T. 11 Std.
Gemergte PRs (30 T.)
8

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus phpstan/phpstan-strict-rules

Alle Issues in phpstan/phpstan-strict-rules

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.