Closed sirbrillig closed 6 years ago
Howdy! The fix for #20 seems to work now, but it introduces a new error. This message comes from the TypeHintSniff
:
19 | WARNING | Return type with no return
The class is following:
<?php declare(strict_types=1); # -*- coding: utf-8 -*-
namespace Just\Some\Test\Auth;
use Brain\Nonces\NonceInterface;
/**
* Interface SettingsPageAuthInterface
*
* @package Just\Some\Test\Auth
*/
interface SettingsPageAuthInterface
{
/**
* @param array $request_data
*
* @return bool
*/
public function isAllowed(array $request_data = []): bool;
/**
* @return NonceInterface
*/
public function nonce(): NonceInterface;
/**
* @return string
*/
public function cap(): string;
}
When i remove the declare
, then i still get the message, which i thought it was fixed, that for interfaces are declare
is required:
1 | ERROR | File must start with a strict types declaration
Damn, you're right. It's because of this line.
* @package Just\Some\Test\Auth
There's too many possible comment tokens to whitelist. I'm just going to skip comment blocks entirely, which I should have done before.
Current code still fail in detection of interface-only files when the file contains shell-style comments, e.g. a code like this:
# Hi there
interface {}
is still reported for missing strict types.
Reason is that shell-style comment tokens does not have comment_closer
attribute.
this can be fixed by adding T_COMMENT
to the list of ignored toke types.
I've sent a PR (#37) that fixes it.
The interface detection in
RequireStrictTypesSniff
(isFileOnlyAnInterface()
) should ignore harmless top-level tokens like namespaces, phpdoc lines,use
expressions, etc.Discovered in #20