diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b17983a..17b8cd1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,11 +50,6 @@ parameters: count: 1 path: src/ShapeFile.php - - - message: "#^Parameter \\#2 \\$shpFile of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:loadFromFile\\(\\) expects resource, resource\\|false given\\.$#" - count: 1 - path: src/ShapeFile.php - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" count: 4 diff --git a/src/ShapeFile.php b/src/ShapeFile.php index af0aace..1b49be8 100644 --- a/src/ShapeFile.php +++ b/src/ShapeFile.php @@ -457,7 +457,7 @@ private function loadRecords(): bool /* Need to start at offset 100 */ while (! $this->eofSHP()) { $record = new ShapeRecord(-1); - $record->loadFromFile($this, $this->shpFile, $this->dbfFile); + $record->loadFromFile($this, $this->dbfFile); if ($record->lastError !== '') { $this->setError($record->lastError); diff --git a/src/ShapeRecord.php b/src/ShapeRecord.php index 33c4995..50245f6 100644 --- a/src/ShapeRecord.php +++ b/src/ShapeRecord.php @@ -42,9 +42,6 @@ class ShapeRecord /** @var resource */ private $shpFile; - /** @var resource|false */ - private $dbfFile = false; - private ShapeFile|null $shapeFile = null; private int $size = 0; @@ -69,14 +66,11 @@ public function __construct(public int $shapeType) * Loads record from files. * * @param ShapeFile $shapeFile The ShapeFile object - * @param resource $shpFile Opened SHP file * @param resource|false $dbfFile Opened DBF file */ - public function loadFromFile(ShapeFile $shapeFile, $shpFile, $dbfFile): void + public function loadFromFile(ShapeFile $shapeFile, $dbfFile): void { $this->shapeFile = $shapeFile; - $this->shpFile = $shpFile; - $this->dbfFile = $dbfFile; $this->loadHeaders(); /* No header read */ @@ -111,11 +105,11 @@ public function loadFromFile(ShapeFile $shapeFile, $shpFile, $dbfFile): void $this->setError(sprintf('Failed to parse record, read=%d, size=%d', $this->read, $this->size)); } - if (! ShapeFile::supportsDbase()) { + if (! ShapeFile::supportsDbase() || $dbfFile === false) { return; } - $this->loadDBFData(); + $this->loadDBFData($dbfFile); } /** @@ -128,7 +122,6 @@ public function loadFromFile(ShapeFile $shapeFile, $shpFile, $dbfFile): void public function saveToFile($shpFile, $dbfFile, int $recordNumber): void { $this->shpFile = $shpFile; - $this->dbfFile = $dbfFile; $this->recordNumber = $recordNumber; $this->saveHeaders(); @@ -149,11 +142,11 @@ public function saveToFile($shpFile, $dbfFile, int $recordNumber): void default => $this->setError(sprintf('The Shape Type "%s" is not supported.', $this->shapeType)), }; - if (! ShapeFile::supportsDbase() || $this->dbfFile === false) { + if (! ShapeFile::supportsDbase() || $dbfFile === false) { return; } - $this->saveDBFData(); + $this->saveDBFData($dbfFile); } /** @@ -788,28 +781,26 @@ public function getContentLength(): int|null return $result; } - private function loadDBFData(): void + /** @param resource $dbfFile Opened DBF file */ + private function loadDBFData($dbfFile): void { - if ($this->dbfFile === false) { - return; - } - - $this->dbfData = @dbase_get_record_with_names($this->dbfFile, $this->recordNumber); + $this->dbfData = @dbase_get_record_with_names($dbfFile, $this->recordNumber); unset($this->dbfData['deleted']); } - private function saveDBFData(): void + /** @param resource $dbfFile */ + private function saveDBFData($dbfFile): void { - if ($this->dbfData === [] || $this->dbfFile === false) { + if ($this->dbfData === []) { return; } unset($this->dbfData['deleted']); - if ($this->recordNumber <= dbase_numrecords($this->dbfFile)) { - if (! dbase_replace_record($this->dbfFile, array_values($this->dbfData), $this->recordNumber)) { + if ($this->recordNumber <= dbase_numrecords($dbfFile)) { + if (! dbase_replace_record($dbfFile, array_values($this->dbfData), $this->recordNumber)) { $this->setError("I wasn't possible to update the information in the DBF file."); } - } elseif (! dbase_add_record($this->dbfFile, array_values($this->dbfData))) { + } elseif (! dbase_add_record($dbfFile, array_values($this->dbfData))) { $this->setError("I wasn't possible to add the information to the DBF file."); } }