Php-cs-fixer: Shouldn't phpdoc_types_order => ['null_adjustment' => 'always_first',] sort 'void' first too ?

Created on 22 Sep 2020  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

Bug report

Shouldn't in @return string|void the 'void' be treated like null when asking to order nulls first ?

$ php -v
PHP 7.3.22-1+ubuntu18.04.1+deb.sury.org+1
$ vendor/bin/php-cs-fixer -V
PHP CS Fixer 2.16.4 Yellow Bird by Fabien Potencier and Dariusz Ruminski

Code snippet that reproduces the problem

E.g. something like the following .php_cs:
php <?php return PhpCsFixer\Config::create() ->setRules([ 'phpdoc_types_order' => [ 'null_adjustment' => 'always_first', 'sort_algorithm' => 'alpha' ] ])

Should sort this (pretty stock from Laravel, just vimeo/psalm replacing null with void in the past):

<?php declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
use function route;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param Request $request
     * @return string|void
     */
    protected function redirectTo($request)
    {
        if (!$request->expectsJson()) {
            return route('login');
        }
    }
}

as @return void|string, since return void is null-ish.

kinbug statuwon't do

Most helpful comment

Mixing void with other possible return types does not make sense: void specifically means the function never returns any value, including null. I'm closing as I don't think this should be implemented.

All 3 comments

For now I replaced 'void|' with 'null|' in my code, as that might be more propper.

.. this could be a fixer in and of itself 馃檴

Mixing void with other possible return types does not make sense: void specifically means the function never returns any value, including null. I'm closing as I don't think this should be implemented.

Fine with me. I fixed the annotation bug at Laravel too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UksusoFF picture UksusoFF  路  3Comments

carusogabriel picture carusogabriel  路  3Comments

vitek-rostislav picture vitek-rostislav  路  3Comments

OskarStark picture OskarStark  路  3Comments

EvgenyOrekhov picture EvgenyOrekhov  路  3Comments