Skip to content

Commit

Permalink
Merge pull request #2 from wallabag/fix/reset-foreach
Browse files Browse the repository at this point in the history
Remove use of reset() inside foreach() loops
  • Loading branch information
j0k3r authored Mar 8, 2021
2 parents ae4861e + e55548c commit b2f5e8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/PHPePub/Core/EPub.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,17 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f
$this->chapterCount++;

foreach ($chapter as $oneChapter) {
$v = reset($oneChapter);
if ($this->encodeHTML === true) {
$v = StringHelper::encodeHtml($v);
$oneChapter = StringHelper::encodeHtml($oneChapter);
}

if ($externalReferences !== EPub::EXTERNAL_REF_IGNORE) {
$this->processChapterExternalReferences($v, $externalReferences, $baseDir);
$this->processChapterExternalReferences($oneChapter, $externalReferences, $baseDir);
}
$partCount++;
$partName = $name . "_" . $partCount;
$this->addFile($partName . "." . $extension, $partName, $v, "application/xhtml+xml");
$this->extractIdAttributes($partName, $v);
$this->addFile($partName . "." . $extension, $partName, $oneChapter, "application/xhtml+xml");
$this->extractIdAttributes($partName, $oneChapter);

$this->opf->addItemRef($partName);
}
Expand Down
4 changes: 1 addition & 3 deletions src/PHPePub/Core/EPubChapterSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ function splitChapter($chapter, $splitOnSearchString = false, $searchString = '/
$curParent = $curFile;
if ($domDepth > 0) {
foreach ($domClonedPath as $oneDomClonedPath) {
/** @var $v \DOMNode */
$v = reset($oneDomClonedPath);
$newParent = $v->cloneNode(false);
$newParent = $oneDomClonedPath->cloneNode(false);
$curParent->appendChild($newParent);
$curParent = $newParent;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PHPePub/Core/Structure/OPF/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = null) {
}

foreach ($this->metaProperties as $data) {
$content = reset($data);
$content = current($data);
$name = key($data);
$metadata .= "\t\t<meta property=\"" . $name . "\">" . $content . "</meta>\n";
}

foreach ($this->meta as $data) {
$content = reset($data);
$content = current($data);
$name = key($data);
$metadata .= "\t\t<meta name=\"" . $name . "\" content=\"" . $content . "\" />\n";
}
Expand Down

0 comments on commit b2f5e8a

Please sign in to comment.