Skip to content

Commit

Permalink
Merge branch 'transition-words-in-content' of github.com:vormkracht10…
Browse files Browse the repository at this point in the history
…/laravel-seo-scanner into transition-words-in-content
  • Loading branch information
Baspa committed Aug 11, 2023
2 parents d94e249 + 1813c80 commit 561f296
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config/seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
|--------------------------------------------------------------------------
|
| The following array lists the default options for the application.
|
|
*/
// en, nl or null (which will use the app locale)
'language' => null,
'language' => null,

/*
|--------------------------------------------------------------------------
Expand Down
19 changes: 10 additions & 9 deletions src/Checks/Content/TransitionWordRatioCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Vormkracht10\Seo\Checks\Content;

use Illuminate\Http\Client\Response;
use Vormkracht10\Seo\Interfaces\Check;
use Symfony\Component\DomCrawler\Crawler;
use Vormkracht10\Seo\Traits\PerformCheck;
use Vormkracht10\Seo\Helpers\TransitionWords;
use Vormkracht10\Seo\Interfaces\Check;
use Vormkracht10\Seo\Traits\PerformCheck;

class TransitionWordRatioCheck implements Check
{
Expand Down Expand Up @@ -56,13 +56,14 @@ public function validateContent(Crawler $crawler): bool
return true;
}

public function calculatePercentageOfTransitionWordsInContent($content, $transitionWords)
public function calculatePercentageOfTransitionWordsInContent($content, $transitionWords)
{
$totalPhrases = preg_match_all('/\b[\w\s]+\b/', $content, $matches);

if ($totalPhrases === 0) {
$this->actualValue = 0;
$this->failureReason = __('failed.content.transition_words_ratio_check.no_phrases_found');

return 0;
}

Expand All @@ -75,18 +76,18 @@ public function calculatePercentageOfTransitionWordsInContent($content, $transit
return round($phrasesWithTransitionWord / $totalPhrases * 100, 0, PHP_ROUND_HALF_UP);
}

public function calculateNumberOfPhrasesWithTransitionWord(string $content, string $transitionWord): int
public function calculateNumberOfPhrasesWithTransitionWord(string $content, string $transitionWord): int
{
preg_match_all('/\b[\w\s]+\b/', $content, $matches);

$phrasesWithTransitionWord = 0;

foreach ($matches[0] as $phrase) {
if (stripos($phrase, $transitionWord) !== false) {
$phrasesWithTransitionWord++;
}
}

return $phrasesWithTransitionWord;
}
}
}
2 changes: 1 addition & 1 deletion src/Helpers/TransitionWords.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function getTransitionWords(): array
return self::$transitionWords;
}

public static function getTransitionWordsOnly(?string $locale = null): array
public static function getTransitionWordsOnly(string $locale = null): array
{
$transitionWords = self::$transitionWords;

Expand Down
2 changes: 1 addition & 1 deletion tests/Checks/Content/TransitionWordRatioCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());

$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
});
});

0 comments on commit 561f296

Please sign in to comment.