]> git.mxchange.org Git - friendica.git/commitdiff
Renamed function name
authorMichael <heluecht@pirati.ca>
Tue, 5 Dec 2023 19:55:27 +0000 (19:55 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 5 Dec 2023 19:55:27 +0000 (19:55 +0000)
src/Content/Post/Factory/PostMedia.php
src/Util/Network.php
tests/src/Util/NetworkTest.php

index 38c5f28ebf64b1cdea7dd5e9eb7d2a4783c20a7d..864786569fa535d44e5f9f3a2fb85040d9c8039a 100644 (file)
@@ -49,24 +49,24 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
        {
                return new Entity\PostMedia(
                        $row['uri-id'],
-                       UtilNetwork::isValidUri($row['url']) ? new Uri($row['url']) : '',
+                       UtilNetwork::createUriFromString($row['url']) ?: '',
                        $row['type'],
                        $this->mimeTypeFactory->createFromContentType($row['mimetype']),
                        $row['media-uri-id'],
                        $row['width'],
                        $row['height'],
                        $row['size'],
-                       UtilNetwork::isValidUri($row['preview']) ? new Uri($row['preview']) : null,
+                       UtilNetwork::createUriFromString($row['preview']),
                        $row['preview-width'],
                        $row['preview-height'],
                        $row['description'],
                        $row['name'],
-                       UtilNetwork::isValidUri($row['author-url']) ? new Uri($row['author-url']) : null,
+                       UtilNetwork::createUriFromString($row['author-url']),
                        $row['author-name'],
-                       UtilNetwork::isValidUri($row['author-image']) ? new Uri($row['author-image']) : null,
-                       UtilNetwork::isValidUri($row['publisher-url']) ? new Uri($row['publisher-url']) : null,
+                       UtilNetwork::createUriFromString($row['author-image']),
+                       UtilNetwork::createUriFromString($row['publisher-url']),
                        $row['publisher-name'],
-                       UtilNetwork::isValidUri($row['publisher-image']) ? new Uri($row['publisher-image']) : null,
+                       UtilNetwork::createUriFromString($row['publisher-image']),
                        $row['blurhash'],
                        $row['id']
                );
index e18173c72cd6c5afcd39a06b36b1e59a70262096..b2f472ba7738e4ffbbde54f10ab881bbb0f2cf7a 100644 (file)
@@ -660,23 +660,22 @@ class Network
        }
 
        /**
-        * Check if a provided URI is valid
+        * Creates an Uri object out of a given Uri string
         *
         * @param string|null $uri
-        * @return boolean
+        * @return UriInterface|null
         */
-       public static function isValidUri(string $uri = null): bool
+       public static function createUriFromString(string $uri = null): ?UriInterface
        {
                if (empty($uri)) {
-                       return false;
+                       return null;
                }
 
                try {
-                       new Uri($uri);
+                       return new Uri($uri);
                } catch (\Exception $e) {
                        Logger::debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]);
-                       return false;
+                       return null;
                }
-               return true;
        }
 }
index 6f28cef1ebc9325cff8d1d85a9c307e9746c8252..945abf84dbe585a367fed772897e2a1fec65733d 100644 (file)
@@ -31,11 +31,11 @@ class NetworkTest extends TestCase
 {
        public function testValidUri()
        {
-               self::assertTrue(Network::isValidUri('https://friendi.ca'));
-               self::assertTrue(Network::isValidUri('magnet:?xs=https%3A%2F%2Ftube.jeena.net%2Flazy-static%2Ftorrents%2F04bec7a8-34de-4847-b080-6ee00c4b3d49-1080-hls.torrent&xt=urn:btih:5def5a24dfa7307e999a0d4f0fcc29c3e2b13be2&dn=My+fediverse+setup+-+I+host+everything+myself&tr=https%3A%2F%2Ftube.jeena.net%2Ftracker%2Fannounce&tr=wss%3A%2F%2Ftube.jeena.net%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Ftube.jeena.net%2Fstatic%2Fstreaming-playlists%2Fhls%2F23989f41-e230-4dbf-9111-936bc730bf50%2Fe5905de3-e488-4bb8-a1e8-eb7a53ac24ad-1080-fragmented.mp4'));
-               self::assertTrue(Network::isValidUri('did:plc:geqiabvo4b4jnfv2paplzcge'));
-               self::assertFalse(Network::isValidUri('https://'));
-               self::assertFalse(Network::isValidUri(''));
-               self::assertFalse(Network::isValidUri(null));
+               self::assertNotNull(Network::createUriFromString('https://friendi.ca'));
+               self::assertNotNull(Network::createUriFromString('magnet:?xs=https%3A%2F%2Ftube.jeena.net%2Flazy-static%2Ftorrents%2F04bec7a8-34de-4847-b080-6ee00c4b3d49-1080-hls.torrent&xt=urn:btih:5def5a24dfa7307e999a0d4f0fcc29c3e2b13be2&dn=My+fediverse+setup+-+I+host+everything+myself&tr=https%3A%2F%2Ftube.jeena.net%2Ftracker%2Fannounce&tr=wss%3A%2F%2Ftube.jeena.net%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Ftube.jeena.net%2Fstatic%2Fstreaming-playlists%2Fhls%2F23989f41-e230-4dbf-9111-936bc730bf50%2Fe5905de3-e488-4bb8-a1e8-eb7a53ac24ad-1080-fragmented.mp4'));
+               self::assertNotNull(Network::createUriFromString('did:plc:geqiabvo4b4jnfv2paplzcge'));
+               self::assertNull(Network::createUriFromString('https://'));
+               self::assertNull(Network::createUriFromString(''));
+               self::assertNull(Network::createUriFromString(null));
        }
 }