Skip to content

Commit

Permalink
Run rector
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Jan 27, 2022
1 parent b3290dd commit 84a3cec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion maintenance/Rector/MockGrabyResponseRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function refactor(Node $node): ?Node
return null;
}

$url = $fetchUrls[0];
$url = (string) $fetchUrls[0];

// Add imports.
$this->useNodesToAddCollector->addUseImport(
Expand Down
4 changes: 2 additions & 2 deletions src/Extractor/ContentExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ private function extractEntityFromPattern(string $entity, string $pattern, $retu
$returnCallback = fn ($e) => trim($e);
}

if (!$this->xpath) {
if (!$this->xpath || !$this->readability) {
return false;
}

Expand Down Expand Up @@ -1139,7 +1139,7 @@ private function extractMultipleEntityFromPattern(string $entity, string $patter
$returnCallback = fn ($e) => trim($e);
}

if (!$this->xpath) {
if (!$this->xpath || !$this->readability) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function cleanupUrl(string $url): string
{
// rewrite part of urls to something more readable
foreach ($this->config->getRewriteUrl() as $find => $action) {
if (false !== strpos($url, $find) && \is_array($action)) {
if (false !== strpos($url, (string) $find) && \is_array($action)) {
$url = strtr($url, $action);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Graby.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ public function cleanupHtml($contentBlock, string $url): string
return trim($this->cleanupXss($originalContentBlock));
}

$this->extractor->readability->clean($contentBlock, 'select');
if ($this->extractor->readability) {
$this->extractor->readability->clean($contentBlock, 'select');
}

if ($this->config->getRewriteRelativeUrls()) {
$this->makeAbsolute($url, $contentBlock);
}

// footnotes
if ('footnotes' === $this->config->getContentLinks() && false === strpos($url, 'wikipedia.org')) {
if ('footnotes' === $this->config->getContentLinks() && false === strpos($url, 'wikipedia.org') && $this->extractor->readability) {
$this->extractor->readability->addFootnotes($contentBlock);
}

// normalise
$contentBlock->normalize();

// remove empty text nodes
Expand Down Expand Up @@ -282,6 +283,7 @@ private function doFetchContent(string $url): array
$this->logger->info('Attempting to extract content');

$extractResult = $this->extractor->process($html, $effectiveUrl);
/** @var Readability */
$readability = $this->extractor->readability;
$contentBlock = $this->extractor->getContent();
$extractedTitle = $this->extractor->getTitle();
Expand Down

0 comments on commit 84a3cec

Please sign in to comment.