From 17eb5a1129b8c62c8bb22c3ac3e3a739e8b2130b Mon Sep 17 00:00:00 2001
From: "a.shamavov" <a.shamavov@iqdev.digital>
Date: Tue, 9 Apr 2024 11:02:36 +0500
Subject: [PATCH] add readFileLineByLine

---
 .../a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82   |  2 ++
 src/Controller/HomeController.php                  | 14 +++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82
index e69de29..ea6a1d3 100644
--- a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82
+++ b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82
@@ -0,0 +1,2 @@
+
+vphp:S121"0Add curly braces around the nested statement(s).(ïŠí±üÿÿÿÿ8ÌÆ‹ì1J$562771d0-0b91-4f4c-beaf-90c25c2ac224
\ No newline at end of file
diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php
index 51d19fa..168fb51 100644
--- a/src/Controller/HomeController.php
+++ b/src/Controller/HomeController.php
@@ -12,26 +12,26 @@ use Symfony\Component\Routing\Attribute\Route;
 
 class HomeController extends AbstractController
 {
-    private function readLogFile(string $fileName): string {
+    private function readFileLineByLine(string $fileName): iterable  {
         $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName;
         if (file_exists($filePath)) {
-            $text = "";
             $file = fopen($filePath, "r");
             while(!feof($file)) {
-                $line = fgets($file);
-                $text .= $line;
+                yield fgets($file);
             }
             fclose($file);
-            return $text;
         }
-        return "Такого файла не существует.";
+        else yield "Такого файла не существует.";
     }
 
 
     #[Route('/{fileName}', name: 'home')]
     public function home(string $fileName): Response // text.txt
     {
-        $text = $this->readLogFile($fileName);
+        $text = "";
+        foreach($this->readFileLineByLine($fileName) as $line) {
+            $text .= $line;
+        }
         return $this->render('home.html.twig', ['text' => $text]);
     }
 }
-- 
GitLab