Use real return types in Repositories.php
[phorkie.git] / src / phorkie / Repositories.php
index ab97c566a47291fbd58158e785f3bfe7413ca039..4a91e96903bf5694bb2720192b94072146c89b84 100644 (file)
@@ -9,30 +9,29 @@ class Repositories
         $this->gitDir  = $GLOBALS['phorkie']['cfg']['gitdir'];
     }
 
-    /**
-     * @return Repository
-     */
-    public function createNew()
+    public function createNew(): Repository
     {
         chdir($this->gitDir);
         $dirs = glob('*.git', GLOB_ONLYDIR);
-        array_walk(
-            $dirs,
-            function ($dir) {
-                return substr($dir, 0, -4);
-            }
-        );
+        foreach ($dirs as $key => $dir) {
+            $dirs[$key] = substr($dir, 0, -4);
+        }
         sort($dirs, SORT_NUMERIC);
-        $n = end($dirs) + 1;
+
+        if ($GLOBALS['phorkie']['cfg']['randomIds']) {
+            $n = end($dirs) + mt_rand(65536, 16777216);
+        } else {
+            $n = end($dirs) + 1;
+        }
 
         chdir($this->workDir);
         $dir = $this->workDir . '/' . $n . '/';
-        mkdir($dir, 0777);//FIXME
+        mkdir($dir, fileperms($this->workDir) & 0777);
         $r = new Repository();
         $r->id = $n;
         $r->workDir = $dir;
         $r->gitDir = $this->gitDir . '/' . $n . '.git/';
-        mkdir($r->gitDir, 0777);//FIXME
+        mkdir($r->gitDir, fileperms($this->gitDir) & 0777);
 
         return $r;
     }
@@ -45,7 +44,7 @@ class Repositories
      *
      * @return array Array of Repositories first, number of repositories second
      */
-    public function getList($page = 0, $perPage = 10)
+    public function getList($page = 0, $perPage = 10): array
     {
         chdir($this->gitDir);
         $dirs = glob('*.git', GLOB_ONLYDIR);