Loading src/Component/CsvParser.php +5 −12 Original line number Diff line number Diff line Loading @@ -84,13 +84,8 @@ class CsvParser implements \Iterator { if (!is_file($filepath) || !is_readable($filepath)) { throw new \InvalidArgumentException('$filepath must exist and be readable.'); } $previous = ini_set('auto_detect_line_endings', '1'); $handle = fopen($filepath, 'rb'); ini_set('auto_detect_line_endings', $previous); return new static($handle); } Loading @@ -104,12 +99,8 @@ class CsvParser implements \Iterator { * A new CsvParser object. */ public static function createFromString($string) { $previous = ini_set('auto_detect_line_endings', '1'); $handle = fopen('php://temp', 'w+b'); ini_set('auto_detect_line_endings', $previous); fwrite($handle, $string); fseek($handle, 0); Loading Loading @@ -197,6 +188,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::current(). */ #[\ReturnTypeWillChange] public function current() { return $this->currentLine; } Loading @@ -204,6 +196,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::key(). */ #[\ReturnTypeWillChange] public function key() { return $this->linesRead - 1; } Loading @@ -211,7 +204,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::next(). */ public function next() { public function next(): void { // Record the file position before reading the next line since we // preemptively read lines to avoid returning empty rows. $this->filePosition = ftell($this->handle); Loading @@ -235,7 +228,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::rewind(). */ public function rewind() { public function rewind(): void { rewind($this->handle); if ($this->hasHeader && !$this->startByte) { Loading @@ -253,7 +246,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::valid(). */ public function valid() { public function valid(): bool { return (bool) $this->currentLine; } Loading src/Feeds/Processor/EntityProcessorBase.php +4 −4 Original line number Diff line number Diff line Loading @@ -579,8 +579,8 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces // Compose error message. If available, use the entity label to indicate // which item failed. Fallback to the GUID value (if available) or else // no indication. $label = $entity->label(); $guid = $entity->get('feeds_item')->guid; $label = (string) $entity->label(); $guid = (string) $entity->get('feeds_item')->guid; $messages = []; $args = [ Loading @@ -590,10 +590,10 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces '@errors' => \Drupal::service('renderer')->renderRoot($element), ':url' => $this->url('entity.feeds_feed_type.mapping', ['feeds_feed_type' => $this->feedType->id()]), ]; if ($label || $label === '0' || $label === 0) { if ($label || $label === '0') { $messages[] = $this->t('The @entity %label failed to validate with the following errors: @errors', $args); } elseif ($guid || $guid === '0' || $guid === 0) { elseif ($guid || $guid === '0') { $messages[] = $this->t('The @entity with GUID %guid failed to validate with the following errors: @errors', $args); } else { Loading tests/fixtures/feeds-8.x-3.0-alpha11/feeds.feed_type.csv.yml +1 −0 Original line number Diff line number Diff line uuid: 91c601fd-ce86-499e-b15e-bbd9262a90d6 langcode: en status: true dependencies: Loading tests/src/Unit/Component/CsvParserTest.php +0 −6 Original line number Diff line number Diff line Loading @@ -65,15 +65,9 @@ class CsvParserTest extends FeedsUnitTestCase { $item = str_replace("\r\n", "\n", $item); }); $mac = $expected; array_walk_recursive($mac, function (&$item, $key) { $item = str_replace("\r\n", "\r", $item); }); return [ [$expected, "\r\n"], [$unix, "\n"], [$mac, "\r"], ]; } Loading Loading
src/Component/CsvParser.php +5 −12 Original line number Diff line number Diff line Loading @@ -84,13 +84,8 @@ class CsvParser implements \Iterator { if (!is_file($filepath) || !is_readable($filepath)) { throw new \InvalidArgumentException('$filepath must exist and be readable.'); } $previous = ini_set('auto_detect_line_endings', '1'); $handle = fopen($filepath, 'rb'); ini_set('auto_detect_line_endings', $previous); return new static($handle); } Loading @@ -104,12 +99,8 @@ class CsvParser implements \Iterator { * A new CsvParser object. */ public static function createFromString($string) { $previous = ini_set('auto_detect_line_endings', '1'); $handle = fopen('php://temp', 'w+b'); ini_set('auto_detect_line_endings', $previous); fwrite($handle, $string); fseek($handle, 0); Loading Loading @@ -197,6 +188,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::current(). */ #[\ReturnTypeWillChange] public function current() { return $this->currentLine; } Loading @@ -204,6 +196,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::key(). */ #[\ReturnTypeWillChange] public function key() { return $this->linesRead - 1; } Loading @@ -211,7 +204,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::next(). */ public function next() { public function next(): void { // Record the file position before reading the next line since we // preemptively read lines to avoid returning empty rows. $this->filePosition = ftell($this->handle); Loading @@ -235,7 +228,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::rewind(). */ public function rewind() { public function rewind(): void { rewind($this->handle); if ($this->hasHeader && !$this->startByte) { Loading @@ -253,7 +246,7 @@ class CsvParser implements \Iterator { /** * Implements \Iterator::valid(). */ public function valid() { public function valid(): bool { return (bool) $this->currentLine; } Loading
src/Feeds/Processor/EntityProcessorBase.php +4 −4 Original line number Diff line number Diff line Loading @@ -579,8 +579,8 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces // Compose error message. If available, use the entity label to indicate // which item failed. Fallback to the GUID value (if available) or else // no indication. $label = $entity->label(); $guid = $entity->get('feeds_item')->guid; $label = (string) $entity->label(); $guid = (string) $entity->get('feeds_item')->guid; $messages = []; $args = [ Loading @@ -590,10 +590,10 @@ abstract class EntityProcessorBase extends ProcessorBase implements EntityProces '@errors' => \Drupal::service('renderer')->renderRoot($element), ':url' => $this->url('entity.feeds_feed_type.mapping', ['feeds_feed_type' => $this->feedType->id()]), ]; if ($label || $label === '0' || $label === 0) { if ($label || $label === '0') { $messages[] = $this->t('The @entity %label failed to validate with the following errors: @errors', $args); } elseif ($guid || $guid === '0' || $guid === 0) { elseif ($guid || $guid === '0') { $messages[] = $this->t('The @entity with GUID %guid failed to validate with the following errors: @errors', $args); } else { Loading
tests/fixtures/feeds-8.x-3.0-alpha11/feeds.feed_type.csv.yml +1 −0 Original line number Diff line number Diff line uuid: 91c601fd-ce86-499e-b15e-bbd9262a90d6 langcode: en status: true dependencies: Loading
tests/src/Unit/Component/CsvParserTest.php +0 −6 Original line number Diff line number Diff line Loading @@ -65,15 +65,9 @@ class CsvParserTest extends FeedsUnitTestCase { $item = str_replace("\r\n", "\n", $item); }); $mac = $expected; array_walk_recursive($mac, function (&$item, $key) { $item = str_replace("\r\n", "\r", $item); }); return [ [$expected, "\r\n"], [$unix, "\n"], [$mac, "\r"], ]; } Loading