Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and jordisala1991 committed Mar 6, 2023
1 parent 00d7100 commit dd9d676
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/Source/IteratorCallbackSourceIterator.php
Expand Up @@ -20,17 +20,15 @@
*/
final class IteratorCallbackSourceIterator extends IteratorSourceIterator
{
private \Closure $transformer;

/**
* @param \Iterator $iterator Iterator with string array elements
* @param \Closure $transformer Altering a data row
*/
public function __construct(\Iterator $iterator, \Closure $transformer)
{
public function __construct(
\Iterator $iterator,
private \Closure $transformer
) {
parent::__construct($iterator);

$this->transformer = $transformer;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Writer/GsaFeedWriter.php
Expand Up @@ -69,7 +69,12 @@ public function write(array $data): void
$this->generateNewPart();
}

$this->bufferSize += fwrite($this->getBuffer(), $line);
$written = fwrite($this->getBuffer(), $line);
if (false === $written) {
throw new \Exception(sprintf('Cannot write line %s in the buffer.', $line));
}

$this->bufferSize += $written;
}

public function close(): void
Expand Down Expand Up @@ -104,7 +109,7 @@ private function generateNewPart(): void
}
$this->buffer = $buffer;

$this->bufferSize += fwrite(
$written = fwrite(
$this->buffer,
<<<XML
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -119,6 +124,11 @@ private function generateNewPart(): void
XML
);
if (false === $written) {
throw new \Exception(sprintf('Cannot write file %s.', $filename));
}

$this->bufferSize += $written;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Writer/SitemapWriter.php
Expand Up @@ -166,7 +166,12 @@ private function generateNewPart(): void
}
$this->buffer = $buffer;

$this->bufferSize += fwrite($this->buffer, '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.$this->getHeaderByFlag().'>'."\n");
$written = fwrite($this->buffer, '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.$this->getHeaderByFlag().'>'."\n");
if (false === $written) {
throw new \Exception(sprintf('Cannot write file %s.', $this->folder.'/'.$filename));
}

$this->bufferSize += $written;
}

/**
Expand All @@ -184,7 +189,12 @@ private function addSitemapLine(string $line): void

++$this->bufferUrlCount;

$this->bufferSize += fwrite($this->getBuffer(), $line);
$written = fwrite($this->getBuffer(), $line);
if (false === $written) {
throw new \Exception(sprintf('Cannot write line %s in the buffer.', $line));
}

$this->bufferSize += $written;
}

/**
Expand Down

0 comments on commit dd9d676

Please sign in to comment.