Skip to content

Commit

Permalink
fix: Call Favicon::baseUrl statically (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophWurst authored Oct 23, 2024
1 parent 44f1e0d commit 2f2af25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/Favicon/Favicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public function get($url = '', $type = FaviconDLType::HOTLINK_URL)
$this->url = $url;
}

$url = rtrim($this->baseUrl($this->url, true), '/');
$url = rtrim(self::baseUrl($this->url, true), '/');
$original = $url;

if (
($favicon = $this->checkCache($original, self::$TYPE_CACHE_URL)) === false
&& ! $favicon = $this->getFavicon($original, false)
) {
$url = rtrim($this->endRedirect($this->baseUrl($this->url, false)), '/');
$url = rtrim($this->endRedirect(self::baseUrl($this->url, false)), '/');
if (
($favicon = $this->checkCache($url, self::$TYPE_CACHE_URL)) === false
&& ! $favicon = $this->getFavicon($url)
Expand Down Expand Up @@ -214,7 +214,7 @@ private function getFavicon($url, $checkDefault = true)
if ($favicon && filter_var($favicon, FILTER_VALIDATE_URL) === false) {
// Make sure that favicons starting with "/" get concatenated with host instead of full URL
if ($favicon[0] === '/') {
$favicon = $this->baseUrl($url) . ltrim($favicon, '/');
$favicon = self::baseUrl($url) . ltrim($favicon, '/');
} else {
$favicon = rtrim($url, '/') . '/' . ltrim($favicon, '/');
}
Expand Down
28 changes: 14 additions & 14 deletions tests/Favicon/FaviconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public function testBaseFalseUrl()
$invalidPrefixUrl = 'ftp://domain.tld';
$emptyUrl = '';

$this->assertEquals(false, $fav->baseUrl($notAnUrl));
$this->assertEquals(false, $fav->baseUrl($notPrefixedUrl));
$this->assertEquals(false, $fav->baseUrl($noHostUrl));
$this->assertEquals(false, $fav->baseUrl($invalidPrefixUrl));
$this->assertEquals(false, $fav->baseUrl($emptyUrl));
$this->assertEquals(false, $fav::baseUrl($notAnUrl));
$this->assertEquals(false, $fav::baseUrl($notPrefixedUrl));
$this->assertEquals(false, $fav::baseUrl($noHostUrl));
$this->assertEquals(false, $fav::baseUrl($invalidPrefixUrl));
$this->assertEquals(false, $fav::baseUrl($emptyUrl));
}

/**
Expand All @@ -130,15 +130,15 @@ public function testBaseUrlValid()
$urlWithUnusedInfo = 'http://domain.tld/index.php?foo=bar&bar=foo#foobar';
$urlWithPath = 'http://domain.tld/my/super/path';

$this->assertEquals(self::slash($simpleUrl), $fav->baseUrl($simpleUrl));
$this->assertEquals(self::slash($simpleHttpsUrl), $fav->baseUrl($simpleHttpsUrl));
$this->assertEquals(self::slash($simpleUrlWithTraillingSlash), $fav->baseUrl($simpleUrlWithTraillingSlash));
$this->assertEquals(self::slash($simpleWithPort), $fav->baseUrl($simpleWithPort));
$this->assertEquals(self::slash($userWithoutPasswordUrl), $fav->baseUrl($userWithoutPasswordUrl));
$this->assertEquals(self::slash($userPasswordUrl), $fav->baseUrl($userPasswordUrl));
$this->assertEquals(self::slash($simpleUrl), $fav->baseUrl($urlWithUnusedInfo));
$this->assertEquals(self::slash($simpleUrl), $fav->baseUrl($urlWithPath, false));
$this->assertEquals(self::slash($urlWithPath), $fav->baseUrl($urlWithPath, true));
$this->assertEquals(self::slash($simpleUrl), $fav::baseUrl($simpleUrl));
$this->assertEquals(self::slash($simpleHttpsUrl), $fav::baseUrl($simpleHttpsUrl));
$this->assertEquals(self::slash($simpleUrlWithTraillingSlash), $fav::baseUrl($simpleUrlWithTraillingSlash));
$this->assertEquals(self::slash($simpleWithPort), $fav::baseUrl($simpleWithPort));
$this->assertEquals(self::slash($userWithoutPasswordUrl), $fav::baseUrl($userWithoutPasswordUrl));
$this->assertEquals(self::slash($userPasswordUrl), $fav::baseUrl($userPasswordUrl));
$this->assertEquals(self::slash($simpleUrl), $fav::baseUrl($urlWithUnusedInfo));
$this->assertEquals(self::slash($simpleUrl), $fav::baseUrl($urlWithPath, false));
$this->assertEquals(self::slash($urlWithPath), $fav::baseUrl($urlWithPath, true));
}

/**
Expand Down

0 comments on commit 2f2af25

Please sign in to comment.