@@ -28,6 +28,8 @@ public function __construct(ComposerFile $composer, RepositoryAPI $repo_api, Pro
2828 */
2929 public function getDependencyInfo (string $ directory , bool $ verbose ): array
3030 {
31+ $ min_stability = $ this ->composer ->getMinimumStability ($ directory );
32+
3133 $ repository_urls = $ this ->composer ->getRepositories ($ directory );
3234 $ repositories = array_map (fn (string $ url ) => $ this ->repo_api ->getInfo ($ url , $ verbose ), $ repository_urls );
3335
@@ -36,22 +38,32 @@ public function getDependencyInfo(string $directory, bool $verbose): array
3638 $ this ->progress ->setTotal (count ($ dependencies ));
3739 $ this ->progress ->display ();
3840 foreach ($ dependencies as $ dependency ) {
39- $ this ->updateVersionInfo ($ dependency , array_filter ($ repositories ), $ verbose , $ directory );
41+ $ this ->updateVersionInfo ($ dependency , array_filter ($ repositories ), $ verbose , $ min_stability );
4042 $ this ->progress ->tick ();
4143 }
4244 $ this ->progress ->finish ();
4345
4446 return $ dependencies ;
4547 }
4648
49+ private static array $ stability_order = ['stable ' , 'RC ' , 'beta ' , 'alpha ' , 'dev ' ];
50+
51+ private static function isValidVersion (string $ version , string $ min_stability ): bool
52+ {
53+ $ min_index = array_search ($ min_stability , self ::$ stability_order );
54+ $ my_stability = VersionParser::parseStability ($ version );
55+ $ my_index = array_search ($ my_stability , self ::$ stability_order );
56+ return $ my_index <= $ min_index ;
57+ }
58+
4759 /**
4860 * @param Dependency $dependency
4961 * @param Repository[] $repositories
5062 * @param bool $verbose
51- * @param string $directory
63+ * @param string $min_stability
5264 * @return void
5365 */
54- private function updateVersionInfo (Dependency $ dependency , array $ repositories , bool $ verbose , string $ directory )
66+ private function updateVersionInfo (Dependency $ dependency , array $ repositories , bool $ verbose , string $ min_stability ): void
5567 {
5668 $ package_info = [];
5769 foreach ($ repositories as $ repository ) {
@@ -66,14 +78,9 @@ private function updateVersionInfo(Dependency $dependency, array $repositories,
6678 return ;
6779 }
6880
69- $ stabilities = ['stable ' , 'RC ' , 'beta ' , 'alpha ' , 'dev ' ];
7081 $ sorted_versions = Semver::rsort (array_keys ($ versions ));
71- $ minStability = $ this ->composer ->getMinimumStability ($ directory );
72- $ minStabilityIndex = array_search ($ minStability , $ stabilities );
73- $ sorted_versions = array_values (array_filter (
74- $ sorted_versions ,
75- fn ($ version ) => array_search (VersionParser::parseStability ($ version ), $ stabilities ) <= $ minStabilityIndex
76- ));
82+ $ valid_versions = array_filter ($ sorted_versions , fn (string $ version ) => self ::isValidVersion ($ version , $ min_stability ));
83+ $ sorted_versions = array_values ($ valid_versions );
7784
7885 $ current_version = $ dependency ->current_version ->version_number ;
7986 $ current_version_release_date = $ this ->getReleaseDate ($ sorted_versions , $ versions , $ current_version );
0 commit comments