Mercurial > packages > magicforger
diff src/Helpers/FileModifier.php @ 14:c969ed13c570 main-dev
Changes for various files
| author | luka |
|---|---|
| date | Mon, 23 Sep 2024 20:35:14 -0400 |
| parents | 4bb4daa9e3f1 |
| children | 19b7a8de0019 |
line wrap: on
line diff
--- a/src/Helpers/FileModifier.php Wed Apr 24 20:11:52 2024 -0400 +++ b/src/Helpers/FileModifier.php Mon Sep 23 20:35:14 2024 -0400 @@ -19,80 +19,55 @@ { private $contents; - /** - * @var mixed - */ public $file_path; - - /** - * @param mixed $file_path - */ public function __construct($file_path) { $this->get_file_contents($file_path); $this->file_path = $file_path; } - - /** - * @param mixed $file_path - * @return void - */ public function get_file_contents($file_path): void { - //TODO: there needs to be more/any error checking - $f = fopen($file_path, "r"); + // TODO: there needs to be more/any error checking + $f = fopen($file_path, 'r'); $this->contents = fread($f, filesize($file_path)); fclose($f); } - - /** - * @param mixed $file_path - */ public function write_to_path($file_path = null): void { $file_path = $file_path ?? $this->file_path; - $f = fopen($file_path, "w"); + $f = fopen($file_path, 'w'); fwrite($f, $this->contents); fclose($f); } - /** - * Replaces the replacement point with the value in the current contents - * - * @param mixed $value - * @param mixed $replacement_point + * Replaces the replacement point with the value in the current contents. */ public function replace($value, $replacement_point): void { $this->contents = str_replace($replacement_point, $value, $this->contents); } - /** - * Inserts the value above the insert point in the current contents - * - * @param mixed $value - * @param mixed $insert_point - * @return void + * Inserts the value above the insert point in the current contents. */ public function insert($value, $insert_point): void { - //seperate on new lines into an array + // seperate on new lines into an array $file_arr = explode("\n", $this->contents); $temp_arr = []; - foreach($file_arr as $line) { - if(str_contains($line, $insert_point)) { + foreach ($file_arr as $line) { + if (str_contains($line, $insert_point)) { $temp_arr[] = $value; } $temp_arr[] = $line; } - $this->contents = implode("\n",$temp_arr); + $this->contents = implode("\n", $temp_arr); } }
