Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Provide additional context in the DisallowedEmptyRule error message

Open
#103 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
devtools

Research direction

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.

Written by the indexing model from the issue text.

Description

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?

Dominant language
PHP
Stars
711
Forks
62
Avg merge
35m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-strict-rules

All issues in phpstan/phpstan-strict-rules

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.