Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Scott committed Feb 14, 2018
1 parent 803fe5b commit 201ac01
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 40 deletions.
10 changes: 5 additions & 5 deletions src/Article.php
Expand Up @@ -232,7 +232,7 @@ public function getDomain(): ?string {
*
* @return self
*/
public function setTopNode(Element $topNode = null): ?self {
public function setTopNode(Element $topNode = null): self {
$this->topNode = $topNode;

return $this;
Expand All @@ -255,7 +255,7 @@ public function getTopNode(): ?Element {
*
* @return self
*/
public function setTopImage(Image $topImage = null): ?self {
public function setTopImage(Image $topImage = null): self {
$this->topImage = $topImage;

return $this;
Expand Down Expand Up @@ -424,7 +424,7 @@ public function setRawHtml(string $rawHtml = null): self {
}

/** @return string|null */
public function getRawHtml(): string {
public function getRawHtml(): ?string {
return $this->rawHtml;
}

Expand Down Expand Up @@ -510,14 +510,14 @@ public function getRawResponse(): \Psr\Http\Message\ResponseInterface {
*
* @return self
*/
public function setPublishDate(\DateTime $publishDate = null): ?self {
public function setPublishDate(\DateTime $publishDate = null): self {
$this->publishDate = $publishDate;

return $this;
}

/** @return \DateTime|null */
public function getPublishDate(): \DateTime {
public function getPublishDate(): ?\DateTime {
return $this->publishDate;
}

Expand Down
12 changes: 4 additions & 8 deletions src/Configuration.php
Expand Up @@ -53,9 +53,7 @@ class Configuration {
* @param mixed[] $options
*/
public function __construct(array $options = []) {
if (is_array($options)) {
$this->options = array_replace_recursive($this->options, $options);
}
$this->options = array_replace_recursive($this->options, $options);
}

/**
Expand Down Expand Up @@ -164,11 +162,9 @@ public function isValidModule(string $category, string $class): bool {
* @return bool
*/
public function areValidModules(string $category, array $classes): bool {
if (is_array($classes)) {
foreach ($classes as $class) {
if (!$this->isValidModule($category, $class)) {
return false;
}
foreach ($classes as $class) {
if (!$this->isValidModule($category, $class)) {
return false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Images/ImageUtils.php
Expand Up @@ -72,7 +72,7 @@ public static function storeImagesToLocalFile($imageSrcs, bool $returnAll, Confi
*
* @return string
*/
private static function getFileExtensionName(string $imageDetails): string {
private static function getFileExtensionName(object $imageDetails): string {
$extensions = [
'image/gif' => '.gif',
'image/jpeg' => '.jpg',
Expand All @@ -98,7 +98,7 @@ private static function handleEntity($imageSrcs, bool $returnAll, Configuration

$results = [];

$requests = function($urls) use ($guzzle, $config, &$results) {
$requests = function($urls) use ($guzzle, &$results) {
foreach ($urls as $key => $url) {
$file = tempnam(sys_get_temp_dir(), 'goose');

Expand Down
6 changes: 5 additions & 1 deletion src/Modules/Extractors/AdditionalDataExtractor.php
Expand Up @@ -101,7 +101,7 @@ private function getVideos(): array {
/**
* Pulls out links we like
*
* @return string[]
* @return array
*/
private function getLinks(): array {
$goodLinks = [];
Expand Down Expand Up @@ -143,6 +143,10 @@ private function getPopularWords(): array {
$text = html_entity_decode($text, ENT_COMPAT | ENT_HTML5, 'UTF-8');
$words = preg_split('@[\s]+@iu', $text, -1, PREG_SPLIT_NO_EMPTY);

if (!$words) {
return array();
}

// Determine stop words currently in $words
$ignoreWords = array_intersect($words, $stopWords);
// Remove ignored words from $words
Expand Down
23 changes: 2 additions & 21 deletions src/Modules/Extractors/ImageExtractor.php
Expand Up @@ -129,7 +129,7 @@ private function checkForMetaTag(): ?Image {
private function checkForLargeImages(Element $node, int $parentDepthLevel, int $siblingDepthLevel): ?Image {
$goodLocalImages = $this->getImageCandidates($node);

$scoredLocalImages = $this->scoreLocalImages($goodLocalImages, $parentDepthLevel);
$scoredLocalImages = $this->scoreLocalImages($goodLocalImages);

ksort($scoredLocalImages);

Expand Down Expand Up @@ -202,11 +202,10 @@ private function getDepthLevel(Element $node, int $parentDepth, int $siblingDept
* so if the image is 3rd found in the dom it's sequence score would be 1 / 3 = .33 * diff in area from the first image
*
* @param LocallyStoredImage[] $locallyStoredImages
* @param int $depthLevel
*
* @return LocallyStoredImage[]
*/
private function scoreLocalImages($locallyStoredImages, int $depthLevel): array {
private function scoreLocalImages($locallyStoredImages): array {
$results = [];
$i = 1;
$initialArea = 0;
Expand Down Expand Up @@ -234,24 +233,6 @@ private function scoreLocalImages($locallyStoredImages, int $depthLevel): array
return $results;
}

/**
* @param LocallyStoredImage $locallyStoredImage
* @param int $depthLevel
*
* @return bool
*/
private function isWorthyImage($locallyStoredImage, int $depthLevel): bool {
if ($locallyStoredImage->getWidth() <= $this->config()->get('image_min_width')
|| $locallyStoredImage->getHeight() <= $this->config()->get('image_min_height')
|| $locallyStoredImage->getFileExtension() == 'NA'
|| ($depthLevel < 1 && $locallyStoredImage->getWidth() < 300) || $depthLevel >= 1
|| $this->isBannerDimensions($locallyStoredImage->getWidth(), $locallyStoredImage->getHeight())) {
return false;
}

return true;
}

/**
* @return Image[]
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Modules/Extractors/PublishDateExtractor.php
Expand Up @@ -20,8 +20,6 @@ class PublishDateExtractor extends AbstractModule implements ModuleInterface {
public function run(Article $article): self {
$this->article($article);

$dt = null;

$dt = $this->getDateFromSchemaOrg();

if (is_null($dt)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/NodeCommonTrait.php
Expand Up @@ -30,7 +30,7 @@ private function isHighLinkDensity(Element $node, float $limit = 1.0): bool {

$words = preg_split('@[\s]+@iu', $node->text(), -1, PREG_SPLIT_NO_EMPTY);

if (count($words) == 0) {
if (!$words) {
return false;
}

Expand Down

0 comments on commit 201ac01

Please sign in to comment.