]> git.mxchange.org Git - friendica.git/commitdiff
Fix some undefined variable/index notices in tests
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 1 Jul 2018 04:15:11 +0000 (00:15 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Mon, 2 Jul 2018 11:44:55 +0000 (07:44 -0400)
include/api.php
include/security.php
src/Core/System.php
src/Network/Probe.php
tests/ApiTest.php

index 32fe6c651d945daf42f01ae7bc0030ae5473ba67..6d38be95b76633a6f44052a94adf78aaf39bc987 100644 (file)
@@ -90,11 +90,15 @@ function api_source()
        }
 
        // Support for known clients that doesn't send a source name
-       if (strpos($_SERVER['HTTP_USER_AGENT'], "Twidere") !== false) {
-               return "Twidere";
+       if (!empty($_SERVER['HTTP_USER_AGENT'])) {
+               if(strpos($_SERVER['HTTP_USER_AGENT'], "Twidere") !== false) {
+                       return "Twidere";
+               }
+
+               logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
        }
 
-       logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
+       logger("Empty user-agent", LOGGER_DEBUG);
 
        return "api";
 }
@@ -193,8 +197,8 @@ function api_login(App $a)
                throw new UnauthorizedException("This API requires login");
        }
 
-       $user = $_SERVER['PHP_AUTH_USER'];
-       $password = $_SERVER['PHP_AUTH_PW'];
+       $user = defaults($_SERVER, 'PHP_AUTH_USER', '');
+       $password = defaults($_SERVER, 'PHP_AUTH_PW', '');
 
        // allow "user@server" login (but ignore 'server' part)
        $at = strstr($user, "@", true);
@@ -258,7 +262,7 @@ function api_check_method($method)
        if ($method == "*") {
                return true;
        }
-       return (strpos($method, $_SERVER['REQUEST_METHOD']) !== false);
+       return (stripos($method, defaults($_SERVER, 'REQUEST_METHOD', 'GET')) !== false);
 }
 
 /**
@@ -298,7 +302,7 @@ function api_call(App $a)
                                //unset($_SERVER['PHP_AUTH_USER']);
 
                                /// @TODO should be "true ==[=] $info['auth']", if you miss only one = character, you assign a variable (only with ==). Let's make all this even.
-                               if ($info['auth'] === true && api_user() === false) {
+                               if (!empty($info['auth']) && api_user() === false) {
                                        api_login($a);
                                }
 
@@ -659,7 +663,7 @@ function api_get_user(App $a, $contact_id = null)
                                'geo_enabled' => false,
                                'verified' => false,
                                'statuses_count' => 0,
-                               'lang' => '',
+                               'language' => '',
                                'contributors_enabled' => false,
                                'is_translator' => false,
                                'is_translation_enabled' => false,
@@ -740,7 +744,7 @@ function api_get_user(App $a, $contact_id = null)
                'geo_enabled' => false,
                'verified' => true,
                'statuses_count' => intval($countitems),
-               'lang' => '',
+               'language' => '',
                'contributors_enabled' => false,
                'is_translator' => false,
                'is_translation_enabled' => false,
@@ -773,13 +777,13 @@ function api_get_user(App $a, $contact_id = null)
                                $link_color = PConfig::get($ret['uid'], 'frio', 'link_color');
                                $bgcolor = PConfig::get($ret['uid'], 'frio', 'background_color');
                        }
-                       if (!$nav_bg) {
+                       if (empty($nav_bg)) {
                                $nav_bg = "#708fa0";
                        }
-                       if (!$link_color) {
+                       if (empty($link_color)) {
                                $link_color = "#6fdbe8";
                        }
-                       if (!$bgcolor) {
+                       if (empty($bgcolor)) {
                                $bgcolor = "#ededed";
                        }
 
@@ -801,12 +805,12 @@ function api_get_user(App $a, $contact_id = null)
  */
 function api_item_get_user(App $a, $item)
 {
-       $status_user = api_get_user($a, $item["author-id"]);
+       $status_user = api_get_user($a, defaults($item, 'author-id', null));
 
-       $status_user["protected"] = $item["private"];
+       $status_user["protected"] = defaults($item, 'private', 0);
 
-       if ($item['thr-parent'] == $item['uri']) {
-               $owner_user = api_get_user($a, $item["owner-id"]);
+       if (defaults($item, 'thr-parent', '') == defaults($item, 'uri', '')) {
+               $owner_user = api_get_user($a, defaults($item, 'author-id', null));
        } else {
                $owner_user = $status_user;
        }
@@ -1308,7 +1312,7 @@ function api_status_show($type)
                        'favorited' => $lastwall['starred'] ? true : false,
                        'retweeted' => false,
                        'possibly_sensitive' => false,
-                       'lang' => "",
+                       'language' => "",
                        'statusnet_html' => $converted["html"],
                        'statusnet_conversation_id' => $lastwall['parent'],
                        'external_url' => System::baseUrl() . "/display/" . $lastwall['guid'],
@@ -2205,7 +2209,7 @@ function api_favorites_create_destroy($type)
        // for versioned api.
        /// @TODO We need a better global soluton
        $action_argv_id = 2;
-       if ($a->argv[1] == "1.1") {
+       if (count($a->argv) > 1 && $a->argv[1] == "1.1") {
                $action_argv_id = 3;
        }
 
index e8a03ad0fe9dfebd37525c9226c1830322521bae..dbba09172e7159200b1faf1e1f6b8ab41cd95041 100644 (file)
@@ -41,7 +41,7 @@ function new_cookie($time, $user = [])
        if ($user) {
                $value = json_encode(["uid" => $user["uid"],
                        "hash" => cookie_hash($user),
-                       "ip" => $_SERVER['REMOTE_ADDR']]);
+                       "ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
        } else {
                $value = "";
        }
@@ -70,7 +70,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive
        $_SESSION['page_flags'] = $user_record['page-flags'];
        $_SESSION['my_url'] = System::baseUrl() . '/profile/' . $user_record['nickname'];
        $_SESSION['my_address'] = $user_record['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
-       $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
+       $_SESSION['addr'] = defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0');
 
        $a->user = $user_record;
 
index ded781da835ade4ab7460653e6e59bd34abce218..abc39e5a2a7650baa62136685c3ecf451e2ffab2 100644 (file)
@@ -72,6 +72,7 @@ class System extends BaseObject
                                }
                        } elseif (!in_array($func['function'], $ignore)) {
                                $callstack[] = $func['function'];
+                               $func['class'] = '';
                                $previous = $func;
                        }
                }
index 5f665814b4d3cda1c48e924e2c47e6c80dd04b0e..8e44c8a50bb8b5f6942263c1a2e9c257fe9f7f64 100644 (file)
@@ -109,6 +109,7 @@ class Probe
                $redirects = 0;
 
                logger("Probing for ".$host, LOGGER_DEBUG);
+               $xrd = null;
 
                $ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                if ($ret['success']) {
@@ -1510,6 +1511,7 @@ class Probe
                        return false;
                }
                $feed = $ret['body'];
+               $dummy1 = $dummy2 = $dummy3 = null;
                $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
 
                if (!$feed_data) {
index c21f651d5fa051dc83e01660e380f1a4157a12ea..4c63af7a91306889725d266075d4f97a9f657f0e 100644 (file)
@@ -629,7 +629,7 @@ class ApiTest extends DatabaseTest
         */
        public function testApiRssExtra()
        {
-               $user_info = ['url' => 'user_url'];
+               $user_info = ['url' => 'user_url', 'language' => 'en'];
                $result = api_rss_extra($this->app, [], $user_info);
                $this->assertEquals($user_info, $result['$user']);
                $this->assertEquals($user_info['url'], $result['$rss']['alternate']);
@@ -1073,6 +1073,7 @@ class ApiTest extends DatabaseTest
                                'width' => 666,
                                'height' => 666,
                                'tmp_name' => $this->getTempImage(),
+                               'name' => 'spacer.png',
                                'type' => 'image/png'
                        ]
                ];