From 6866e606a7cb19708dab3c4731f8ea077871cc45 Mon Sep 17 00:00:00 2001 From: Austin Kregel <5355937+austinkregel@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:19:31 -0400 Subject: [PATCH] Add support for using strict types in configs (#4) --- src/ArrayFile.php | 1 + tests/ArrayFileTest.php | 10 ++++++++++ tests/fixtures/array/strict-file-types.php | 7 +++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/fixtures/array/strict-file-types.php diff --git a/src/ArrayFile.php b/src/ArrayFile.php index 02fd9b3..e8be566 100644 --- a/src/ArrayFile.php +++ b/src/ArrayFile.php @@ -305,6 +305,7 @@ protected function getAstReturnIndex(array $ast): ?int switch (get_class($item)) { case Stmt\Use_::class: case Stmt\Expression::class: + case Stmt\Declare_::class: break; case Stmt\Return_::class: return $index; diff --git a/tests/ArrayFileTest.php b/tests/ArrayFileTest.php index 382f42d..8727b5b 100644 --- a/tests/ArrayFileTest.php +++ b/tests/ArrayFileTest.php @@ -845,4 +845,14 @@ public function testSingleLineCommentSubItem() str_replace("\r", '', $arrayFile->render()) ); } + + public function testStrictFileTypes() + { + $file = __DIR__ . '/fixtures/array/strict-file-types.php'; + $arrayFile = ArrayFile::open($file); + + $code = $arrayFile->render(); + + $this->assertStringContainsString('declare', $code); + } } diff --git a/tests/fixtures/array/strict-file-types.php b/tests/fixtures/array/strict-file-types.php new file mode 100644 index 0000000..8bcef5d --- /dev/null +++ b/tests/fixtures/array/strict-file-types.php @@ -0,0 +1,7 @@ + Response::HTTP_OK +];