| Conditions | 4 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function handle(string $needle, string $value, string $dir) |
||
| 22 | { |
||
| 23 | if (!$this->fileSystem->exists($dir)) { |
||
| 24 | throw new \Exception('There is no such directory'); |
||
| 25 | } |
||
| 26 | |||
| 27 | $files = $this->finder |
||
| 28 | ->files() |
||
| 29 | ->in($dir) |
||
| 30 | ->contains($needle); |
||
| 31 | |||
| 32 | foreach ($files as $file) { |
||
| 33 | $updated = str_replace($needle, $value, $file->getContents()); |
||
| 34 | |||
| 35 | try { |
||
| 36 | $this->fileSystem->dumpFile($file->getRealPath(), $updated); |
||
| 37 | } catch (IOExceptionInterface $exception) { |
||
| 38 | throw new \Exception($exception->getMessage()); |
||
| 39 | } |
||
| 43 |