nforce strict type cant add space to separate ? from class

In some class i have a code like that, example full php code:

<?php

declare(strict_types=1);

namespace Example\ClassFooUp;

class ClassFoo
{

    private static ?ClassFoo $instance = null;
    
    public static function getInstance(): ClassFoo
    {
        if (!self::$instance instanceof self) {
            self::$instance = new self();
        }

        return self::$instance;
  }
}

the problems is when i run it on code sniffer online With PSR-12: https://www.webcodesniffer.net/index.php i get this report:

----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
 10 | ERROR | [x] Expected at least 1 space after "?"; 0 found
 12 | ERROR | [x] Expected at least 1 space before ":"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 79ms; Memory: 4Mb

How can i set to add space after "?" and before ":" this is related to code style but i cant find the right option to set the spaces correctly.

0
1 comment

Hmm, I have just tried to run the most recent version of CodeSniffer with the PSR12 standard against your code sample and it was not able to find any imperfections:

Moreover, if I add spaces near "?" and ":", I got an opposite result:

So, looks like, PhpStorm PSR12 code styling is correct and apparently, something might be wrong with the webcodesniffer.com rules.

0

Please sign in to leave a comment.