Do not use each() anymore (breaks on PHP 8)
[phorkie.git] / src / phorkie / Repository / LinkbackReceiver.php
index c9b3d0369422b9193e09073f2488f8c56bed3878..1bb466433a1fe49450072d0511c048a28f7b5091 100644 (file)
@@ -46,7 +46,8 @@ class Repository_LinkbackReceiver
         $remoteCloneUrl = $remoteTitle = null;
         if (count($arRemoteCloneUrls)) {
             reset($arRemoteCloneUrls);
-            list($remoteCloneUrl, $remoteTitle) = each($arRemoteCloneUrls);
+            $remoteCloneUrl = key($arRemoteCloneUrls);
+            $remoteTitle    = current($arRemoteCloneUrls);
         }
         $remoteid = 'fork-' . uniqid();
         //check if we already know this remote
@@ -120,13 +121,19 @@ class Repository_LinkbackReceiver
      */
     protected function localizeGitUrls($arGitUrls)
     {
-        $pub = $GLOBALS['phorkie']['cfg']['git']['public'];
-        $pri = $GLOBALS['phorkie']['cfg']['git']['private'];
+        $pub = $pri = null;
+        if (isset($GLOBALS['phorkie']['cfg']['git']['public'])) {
+            $pub = $GLOBALS['phorkie']['cfg']['git']['public'];
+        }
+        if (isset($GLOBALS['phorkie']['cfg']['git']['private'])) {
+            $pri = $GLOBALS['phorkie']['cfg']['git']['private'];
+        }
 
         $arRemoteCloneUrls = array();
         foreach ($arGitUrls as $remoteTitle => $arUrls) {
             foreach ($arUrls as $remoteCloneUrl) {
-                if (substr($remoteCloneUrl, 0, strlen($pub)) == $pub
+                if ($pub !== null
+                    && substr($remoteCloneUrl, 0, strlen($pub)) == $pub
                     && substr($remoteCloneUrl, -4) == '.git'
                 ) {
                     $id = substr($remoteCloneUrl, strlen($pub), -4);
@@ -136,7 +143,8 @@ class Repository_LinkbackReceiver
                         $arRemoteCloneUrls[$repo->gitDir] = $remoteTitle;
                     } catch (Exception $e) {
                     }
-                } else if (substr($remoteCloneUrl, 0, strlen($pri)) == $pri
+                } else if ($pri !== null
+                    && substr($remoteCloneUrl, 0, strlen($pri)) == $pri
                     && substr($remoteCloneUrl, -4) == '.git'
                 ) {
                     $id = substr($remoteCloneUrl, strlen($pri), -4);