Merge pull request #1279 from midnite81/bug/declare-strict-types-with-comments-above

Strict types expectation allows for comments above declaration
This commit is contained in:
Nuno Maduro
2024-09-29 19:12:06 +01:00
committed by GitHub
5 changed files with 49 additions and 1 deletions

View File

@ -509,7 +509,7 @@ final class Expectation
{
return Targeted::make(
$this,
fn (ObjectDescription $object): bool => (bool) preg_match('/^<\?php\s+declare\(.*?strict_types\s?=\s?1.*?\);/', (string) file_get_contents($object->path)),
fn (ObjectDescription $object): bool => (bool) preg_match('/^<\?php\s*(\/\*[\s\S]*?\*\/|\/\/[^\r\n]*(?:\r?\n|$)|\s)*declare\s*\(\s*strict_types\s*=\s*1\s*\)\s*;/m', (string) file_get_contents($object->path)),
'to use strict types',
FileLineFinder::where(fn (string $line): bool => str_contains($line, '<?php')),
);