- public function readCsvFileLine ($columnSeparator) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s - CALLED!', __METHOD__, __LINE__, $columnSeparator));
-
- // Read raw line
- $data = $this->getPointerInstance()->readLine();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data()=%d', __METHOD__, __LINE__, strlen($data)));
+ public function readCsvFileLine (string $columnSeparator, int $expectedMatches = 0) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] columnSeparator=%s,expectedMatches=%d - CALLED!', __METHOD__, __LINE__, $columnSeparator, $expectedMatches));
+ if (strlen($columnSeparator) === 0) {
+ // No empty column separator
+ throw new InvalidArgumentException('Parameter "columnSeparator" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ } elseif ($expectedMatches < 0) {
+ // Below zero is not valid
+ throw new InvalidArgumentException(sprintf('expectedMatches=%d is below zero', $expectedMatches));
+ }
+
+ // Read raw line and trim anything unwanted away
+ $data = trim($this->getPointerInstance()->readLine());
+
+ // Is the line empty?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] data(%d)=%s', __METHOD__, __LINE__, strlen($data), $data));
+ if (empty($data)) {
+ // Yes, then skip below code
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d:] Read data is an empty line - EXIT!', __METHOD__, __LINE__));
+ return;
+ }