diff --git a/.gitignore b/.gitignore index 3858810..f694442 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ vendor/* .idea/* tmp/* +.phpunit.result.cache +tests/.phpunit.result.cache tests/test_output_*.ged tests/test_converted_*.ged -tests/tmp_gedcom70_output.ged \ No newline at end of file +tests/tmp_gedcom70_output.ged diff --git a/composer.json b/composer.json index 6f2696d..e8e8db3 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,7 @@ }, "require-dev": { "phpunit/phpunit": "^11.0", - "squizlabs/php_codesniffer": "^3.8", - "rector/rector": "^1.0", - "driftingly/rector-laravel": "^1.0", - "phpstan/phpstan": "^1.10" + "squizlabs/php_codesniffer": "^3.8" }, "autoload": { "psr-4": { diff --git a/src/Parser.php b/src/Parser.php index 2c6b9b1..9ff25e2 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -13,14 +13,23 @@ class Parser implements ParserInterface private int $currentLine = 0; private array $errors = []; - // PHP 8.4 property hooks for lazy initialization - private \SplFileObject $fileHandle { - get => $this->fileHandle ??= new \SplFileObject($this->fileName, 'r'); - } + // Lazy-initialized file handle for streaming + private ?\SplFileObject $fileHandle = null; private string $fileName; private bool $useStreaming = false; + /** + * Get the file handle, creating it if it doesn't exist (lazy initialization) + */ + private function getFileHandle(): \SplFileObject + { + if ($this->fileHandle === null) { + $this->fileHandle = new \SplFileObject($this->fileName, 'r'); + } + return $this->fileHandle; + } + public function __construct() { $this->gedcom = new Gedcom(); @@ -103,9 +112,10 @@ public function parse(string $fileName): ?Gedcom */ private function parseStreaming(): ?Gedcom { - $this->fileHandle->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE); + $fileHandle = $this->getFileHandle(); + $fileHandle->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE); - foreach ($this->fileHandle as $lineNumber => $line) { + foreach ($fileHandle as $lineNumber => $line) { $record = $this->parseLine($line); if (empty($record)) { diff --git a/tests/library/Gedcom/ParserTest.php b/tests/library/Gedcom/ParserTest.php index b564cb3..b0281da 100644 --- a/tests/library/Gedcom/ParserTest.php +++ b/tests/library/Gedcom/ParserTest.php @@ -15,6 +15,7 @@ namespace GedcomTest; +use Gedcom\Gedcom; use Gedcom\Parser; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -82,7 +83,7 @@ public function testHead() $this->assertEquals($head->getSubm(), 'SUBMITTER'); $this->assertEquals($head->getSubn(), 'SUBMISSION'); - $this->assertEquals($head->getDest(), 'ANSTFILE'); + $this->assertEquals($head->getDest()->getDest(), 'ANSTFILE'); $this->assertEquals($head->getDate()->getDate(), '1 JAN 1998'); $this->assertEquals($head->getDate()->getTime(), '13:57:24.80'); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 3fec931..bb14fe0 100755 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,7 +7,7 @@ displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerWarnings="true" - requireCoverageMetadata="true"> + requireCoverageMetadata="false"> library/Gedcom/