Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 4fd16a0

Browse files
committed
Only add declartion to PHP files
1 parent 64cf92f commit 4fd16a0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Tasks/DeclareStrictTypes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public function perform(): int
2424

2525
$contents = file_get_contents($file);
2626

27+
if (! str_starts_with($contents, '<?php')) {
28+
continue;
29+
}
30+
2731
$found = preg_match('/\s+declare\([^)]+?\);/', $contents, $matches);
2832
if ($found) {
2933
if (str_contains($matches[0], 'strict_types')) {

tests/Feature/Tasks/DeclareStrictTypesTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ public function it_adds_declaration_to_files()
3030
'app/Support/NoOpClass.php' => 'tests/fixtures/strict-types/no-op.php',
3131
'app/Support/SimpleClass.php' => 'tests/fixtures/strict-types/simple.php',
3232
'app/Support/ComplexClass.php' => 'tests/fixtures/strict-types/complex.php',
33+
'resources/views/template.blade.php' => '@noop',
34+
'some/other/file.php' => '<html lang="en"><title>File with <?php echo "PHP"; ?></title></html>',
3335
]);
3436

3537
$result = $this->subject->perform();
3638

3739
$this->assertSame(0, $result);
3840

3941
$this->assertFileNotChanged('app/Support/NoOpClass.php');
42+
$this->assertFileNotChanged('resources/views/template.blade.php');
43+
$this->assertFileNotChanged('some/other/file.php');
4044
$this->assertFileChanges('tests/fixtures/strict-types/simple.after.php', 'app/Support/SimpleClass.php');
4145
$this->assertFileChanges('tests/fixtures/strict-types/complex.after.php', 'app/Support/ComplexClass.php');
4246
}

0 commit comments

Comments
 (0)