Selaa lähdekoodia

Make author keys' order deterministic, fixes #8268

Jordi Boggiano 5 vuotta sitten
vanhempi
commit
1e96a080c7
1 muutettua tiedostoa jossa 16 lisäystä ja 0 poistoa
  1. 16 0
      src/Packagist/WebBundle/Entity/Version.php

+ 16 - 0
src/Packagist/WebBundle/Entity/Version.php

@@ -243,6 +243,10 @@ class Version
                 }
             }
         }
+        foreach ($authors as &$author) {
+            uksort($author, [$this, 'sortAuthorKeys']);
+        }
+        unset($author);
 
         $data = array(
             'name' => $this->getName(),
@@ -1024,4 +1028,16 @@ class Version
     {
         return $this->name.' '.$this->version.' ('.$this->normalizedVersion.')';
     }
+
+    private function sortAuthorKeys($a, $b)
+    {
+        static $order = ['name' => 1, 'email' => 2, 'homepage' => 3, 'role' => 4];
+        $aIndex = $order[$a] ?? 5;
+        $bIndex = $order[$b] ?? 5;
+        if ($aIndex === $bIndex) {
+            return $a <=> $b;
+        }
+
+        return $aIndex <=> $bIndex;
+    }
 }