@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery; |
| 5 | 5 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | foreach ($json as $key => $values) { |
| 133 | 133 | $existingValues = $array[$key] ?? []; |
| 134 | 134 | if (!is_array($values)) { |
| 135 | - $values = [ $values ]; |
|
| 135 | + $values = [$values]; |
|
| 136 | 136 | } |
| 137 | 137 | $existingValues = array_merge($existingValues, $values); |
| 138 | 138 | $array[$key] = $existingValues; |
@@ -19,61 +19,61 @@ |
||
| 19 | 19 | * @param PackageInterface[] $unorderedPackagesList |
| 20 | 20 | * @return array|PackageInterface[] |
| 21 | 21 | */ |
| 22 | - public static function reorderPackages(array $unorderedPackagesList) : array { |
|
| 23 | - // The very first step is to reorder the packages alphabetically. |
|
| 24 | - // This is to ensure the same order every time, even between packages that are unrelated. |
|
| 25 | - usort($unorderedPackagesList, function(PackageInterface $packageA, PackageInterface $packageB) { |
|
| 26 | - return strcmp($packageA->getName(), $packageB->getName()); |
|
| 27 | - }); |
|
| 22 | + public static function reorderPackages(array $unorderedPackagesList) : array { |
|
| 23 | + // The very first step is to reorder the packages alphabetically. |
|
| 24 | + // This is to ensure the same order every time, even between packages that are unrelated. |
|
| 25 | + usort($unorderedPackagesList, function(PackageInterface $packageA, PackageInterface $packageB) { |
|
| 26 | + return strcmp($packageA->getName(), $packageB->getName()); |
|
| 27 | + }); |
|
| 28 | 28 | |
| 29 | - $orderedPackagesList = array(); |
|
| 30 | - foreach ($unorderedPackagesList as $package) { |
|
| 31 | - $orderedPackagesList = self::walkPackagesList($package, $orderedPackagesList, $unorderedPackagesList); |
|
| 32 | - } |
|
| 29 | + $orderedPackagesList = array(); |
|
| 30 | + foreach ($unorderedPackagesList as $package) { |
|
| 31 | + $orderedPackagesList = self::walkPackagesList($package, $orderedPackagesList, $unorderedPackagesList); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return $orderedPackagesList; |
|
| 35 | - } |
|
| 34 | + return $orderedPackagesList; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Function used to sort packages by dependencies (packages depending from no other package in front of others) |
|
| 39 | - * Invariant hypothesis for this function: $orderedPackagesList is already ordered and the package we add |
|
| 40 | - * has all its dependencies already accounted for. If not, we add the dependencies first. |
|
| 41 | - * |
|
| 42 | - * @param PackageInterface $package |
|
| 43 | - * @param PackageInterface[] $orderedPackagesList The list of sorted packages |
|
| 44 | - * @param PackageInterface[] $availablePackages The list of all packages not yet sorted |
|
| 45 | - * @return PackageInterface[] |
|
| 46 | - */ |
|
| 47 | - private static function walkPackagesList(PackageInterface $package, array $orderedPackagesList, array &$availablePackages) : array { |
|
| 48 | - // First, let's check that the package we want to add is not already in our list. |
|
| 49 | - foreach ($orderedPackagesList as $includedPackage) { |
|
| 50 | - if ($includedPackage->equals($package)) { |
|
| 51 | - return $orderedPackagesList; |
|
| 52 | - } |
|
| 53 | - } |
|
| 37 | + /** |
|
| 38 | + * Function used to sort packages by dependencies (packages depending from no other package in front of others) |
|
| 39 | + * Invariant hypothesis for this function: $orderedPackagesList is already ordered and the package we add |
|
| 40 | + * has all its dependencies already accounted for. If not, we add the dependencies first. |
|
| 41 | + * |
|
| 42 | + * @param PackageInterface $package |
|
| 43 | + * @param PackageInterface[] $orderedPackagesList The list of sorted packages |
|
| 44 | + * @param PackageInterface[] $availablePackages The list of all packages not yet sorted |
|
| 45 | + * @return PackageInterface[] |
|
| 46 | + */ |
|
| 47 | + private static function walkPackagesList(PackageInterface $package, array $orderedPackagesList, array &$availablePackages) : array { |
|
| 48 | + // First, let's check that the package we want to add is not already in our list. |
|
| 49 | + foreach ($orderedPackagesList as $includedPackage) { |
|
| 50 | + if ($includedPackage->equals($package)) { |
|
| 51 | + return $orderedPackagesList; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // We need to make sure there is no loop (if a package A requires a package B that requires the package A)... |
|
| 56 | - // We do that by removing the package from the list of all available packages. |
|
| 57 | - $key = array_search($package, $availablePackages); |
|
| 58 | - unset($availablePackages[$key]); |
|
| 55 | + // We need to make sure there is no loop (if a package A requires a package B that requires the package A)... |
|
| 56 | + // We do that by removing the package from the list of all available packages. |
|
| 57 | + $key = array_search($package, $availablePackages); |
|
| 58 | + unset($availablePackages[$key]); |
|
| 59 | 59 | |
| 60 | - // Now, let's see if there are dependencies. |
|
| 61 | - foreach ($package->getRequires() as $require) { |
|
| 62 | - /* @var $require Link */ |
|
| 63 | - foreach ($availablePackages as $iterPackage) { |
|
| 64 | - if ($iterPackage->getName() == $require->getTarget()) { |
|
| 65 | - $orderedPackagesList = self::walkPackagesList($iterPackage, $orderedPackagesList, $availablePackages); |
|
| 66 | - break; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 60 | + // Now, let's see if there are dependencies. |
|
| 61 | + foreach ($package->getRequires() as $require) { |
|
| 62 | + /* @var $require Link */ |
|
| 63 | + foreach ($availablePackages as $iterPackage) { |
|
| 64 | + if ($iterPackage->getName() == $require->getTarget()) { |
|
| 65 | + $orderedPackagesList = self::walkPackagesList($iterPackage, $orderedPackagesList, $availablePackages); |
|
| 66 | + break; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // FIXME: manage dev-requires and "provides" |
|
| 71 | + // FIXME: manage dev-requires and "provides" |
|
| 72 | 72 | |
| 73 | - // Finally, let's add the package once all dependencies have been added. |
|
| 74 | - $orderedPackagesList[] = $package; |
|
| 73 | + // Finally, let's add the package once all dependencies have been added. |
|
| 74 | + $orderedPackagesList[] = $package; |
|
| 75 | 75 | |
| 76 | - return $orderedPackagesList; |
|
| 77 | - } |
|
| 76 | + return $orderedPackagesList; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery; |
| 5 | 5 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery; |
| 5 | 5 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery\Utils; |
| 5 | 5 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery\Utils; |
| 5 | 5 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace TheCodingMachine\Discovery\Utils; |
| 5 | 5 | |