Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| InMemoryHtaccessFile | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| valid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isReadable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * In-memory SplFileObject used as a safe input for the tivie/htaccess-parser. |
| 5 | * |
| 6 | * The parser drives the read loop with `while ($file->valid()) { $file->getCurrentLine(); }`, |
| 7 | * which mixes SPL's iterator protocol with raw `fgets()`. Under PHP 8.6 the iterator |
| 8 | * state and the underlying file pointer can desync, causing `getCurrentLine()` to |
| 9 | * throw "Cannot read from file" at EOF. Aligning `valid()` with `!eof()` restores |
| 10 | * the behavior the parser expects across PHP versions without patching the library. |
| 11 | * |
| 12 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 13 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 14 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 15 | * |
| 16 | * @package phpMyFAQ |
| 17 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 18 | * @copyright 2026 phpMyFAQ Team |
| 19 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 20 | * @link https://www.phpmyfaq.de |
| 21 | * @since 2026-04-16 |
| 22 | */ |
| 23 | |
| 24 | declare(strict_types=1); |
| 25 | |
| 26 | namespace phpMyFAQ\Setup; |
| 27 | |
| 28 | use SplTempFileObject; |
| 29 | |
| 30 | final class InMemoryHtaccessFile extends SplTempFileObject |
| 31 | { |
| 32 | public function valid(): bool |
| 33 | { |
| 34 | return !$this->eof(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * The parser's readability guard uses SplFileInfo::isReadable(), which returns |
| 39 | * false for in-memory temp objects because they have no filesystem path. The |
| 40 | * content is always available here, so advertise the file as readable. |
| 41 | */ |
| 42 | public function isReadable(): bool |
| 43 | { |
| 44 | return true; |
| 45 | } |
| 46 | } |