33use Composer \Composer ;
44use Composer \Config ;
55use Composer \Config \JsonConfigSource ;
6- use Composer \DependencyResolver \Pool ;
76use Composer \Factory ;
87use Composer \IO \NullIO ;
98use Composer \Installer ;
@@ -223,9 +222,7 @@ public function install( $args, $assoc_args ) {
223222 $ dir_package = false ;
224223 $ version = '' ;
225224 if ( $ this ->is_git_repository ( $ package_name ) ) {
226- if ( '' === $ version ) {
227- $ version = "dev- {$ this ->get_github_default_branch ( $ package_name , $ insecure )}" ;
228- }
225+ $ version = "dev- {$ this ->get_github_default_branch ( $ package_name , $ insecure )}" ;
229226 $ git_package = $ package_name ;
230227 $ matches = [];
231228 if ( preg_match ( '#([^:\/]+\/[^\/]+)\.git# ' , $ package_name , $ matches ) ) {
@@ -247,7 +244,7 @@ public function install( $args, $assoc_args ) {
247244 $ gitlab_token = getenv ( 'GITLAB_TOKEN ' ); // Use GITLAB_TOKEN if available to avoid authorization failures or rate-limiting.
248245 $ headers = $ gitlab_token && strpos ( $ package_name , '://gitlab.com/ ' ) !== false ? [ 'PRIVATE-TOKEN ' => $ gitlab_token ] : [];
249246 $ response = Utils \http_request ( 'GET ' , $ package_name , null , $ headers , $ options );
250- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
247+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
251248 @unlink ( $ temp ); // @codingStandardsIgnoreLine
252249 WP_CLI ::error ( sprintf ( "Couldn't download package from '%s' (HTTP code %d). " , $ package_name , $ response ->status_code ) );
253250 }
@@ -316,11 +313,9 @@ public function install( $args, $assoc_args ) {
316313 }
317314 }
318315
319- if ( $ this ->is_composer_v2 () ) {
320- $ package_name = function_exists ( 'mb_strtolower ' )
321- ? mb_strtolower ( $ package_name )
322- : strtolower ( $ package_name );
323- }
316+ $ package_name = function_exists ( 'mb_strtolower ' )
317+ ? mb_strtolower ( $ package_name )
318+ : strtolower ( $ package_name );
324319
325320 if ( '' === $ version ) {
326321 $ version = self ::DEFAULT_DEV_BRANCH_CONSTRAINTS ;
@@ -822,8 +817,8 @@ private function package_index() {
822817 * Displays a set of packages
823818 *
824819 * @param string $context
825- * @param array
826- * @param array
820+ * @param array $packages
821+ * @param array $assoc_args
827822 */
828823 private function show_packages ( $ context , $ packages , $ assoc_args ) {
829824 $ default_fields = [];
@@ -866,7 +861,7 @@ private function show_packages( $context, $packages, $assoc_args ) {
866861 $ update_version = '' ;
867862 if ( 'list ' === $ context && ! $ skip_update_check ) {
868863 try {
869- $ latest = $ this ->find_latest_package ( $ package , $ composer, null );
864+ $ latest = $ this ->find_latest_package ( $ package , $ composer );
870865 if ( $ latest && $ latest ->getFullPrettyVersion () !== $ package ->getFullPrettyVersion () ) {
871866 $ update = 'available ' ;
872867 $ update_version = $ latest ->getPrettyVersion ();
@@ -929,7 +924,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
929924 // Check if the package exists on Packagist.
930925 $ url = "https://repo.packagist.org/p2/ {$ package_name }.json " ;
931926 $ response = Utils \http_request ( 'GET ' , $ url , null , [], $ options );
932- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
927+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
933928 return $ package_name ;
934929 }
935930
@@ -938,7 +933,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
938933 $ github_token = getenv ( 'GITHUB_TOKEN ' ); // Use GITHUB_TOKEN if available to avoid authorization failures or rate-limiting.
939934 $ headers = $ github_token ? [ 'Authorization ' => 'token ' . $ github_token ] : [];
940935 $ response = Utils \http_request ( 'GET ' , $ url , null /*data*/ , $ headers , $ options );
941- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
936+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
942937 return $ url ;
943938 }
944939
@@ -948,7 +943,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
948943 $ headers = $ github_token ? [ 'Authorization ' => 'token ' . $ github_token ] : [];
949944 $ headers = $ gitlab_token && strpos ( $ package_name , '://gitlab.com/ ' ) !== false ? [ 'PRIVATE-TOKEN ' => $ gitlab_token ] : [];
950945 $ response = Utils \http_request ( 'GET ' , $ url , null /*data*/ , $ headers , $ options );
951- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
946+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
952947 return $ url ;
953948 }
954949
@@ -976,9 +971,6 @@ private function get_installed_packages() {
976971 if ( in_array ( $ package ->getPrettyName (), $ installed_package_keys , true ) ) {
977972 $ installed_packages [] = $ package ;
978973 } elseif ( false !== $ idx ) { // Legacy incorrect name check.
979- if ( ! $ this ->is_composer_v2 () ) {
980- WP_CLI ::warning ( sprintf ( "Found package '%s' misnamed '%s' in '%s'. " , $ package ->getPrettyName (), $ installed_package_keys [ $ idx ], $ this ->get_composer_json_path () ) );
981- }
982974 $ installed_packages [] = $ package ;
983975 }
984976 }
@@ -1130,12 +1122,11 @@ private function create_default_composer_json( $composer_path ) {
11301122 *
11311123 * @param PackageInterface $package
11321124 * @param Composer $composer
1133- * @param string $phpVersion
1134- * @param bool $minorOnly
1125+ * @param bool $minor_only
11351126 *
1136- * @return PackageInterface|null
1127+ * @return PackageInterface|false
11371128 */
1138- private function find_latest_package ( PackageInterface $ package , Composer $ composer , $ php_version , $ minor_only = false ) {
1129+ private function find_latest_package ( PackageInterface $ package , Composer $ composer , $ minor_only = false ) {
11391130 // Find the latest version allowed in this pool/repository set.
11401131 $ name = $ package ->getPrettyName ();
11411132 $ version_selector = $ this ->get_version_selector ( $ composer );
@@ -1156,30 +1147,20 @@ private function find_latest_package( PackageInterface $package, Composer $compo
11561147 $ target_version = '^ ' . $ package ->getVersion ();
11571148 }
11581149
1159- if ( $ this ->is_composer_v2 () ) {
1160- return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ best_stability );
1161- }
1162-
1163- return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ php_version , $ best_stability );
1150+ return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ best_stability );
11641151 }
11651152
11661153 /**
11671154 * @return VersionSelector
11681155 */
11691156 private function get_version_selector ( Composer $ composer ) {
11701157 if ( ! $ this ->version_selector ) {
1171- if ( $ this ->is_composer_v2 () ) {
1172- $ repository_set = new Repository \RepositorySet (
1173- $ composer ->getPackage ()->getMinimumStability (),
1174- $ composer ->getPackage ()->getStabilityFlags ()
1175- );
1176- $ repository_set ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1177- $ this ->version_selector = new VersionSelector ( $ repository_set );
1178- } else {
1179- $ pool = new Pool ( $ composer ->getPackage ()->getMinimumStability (), $ composer ->getPackage ()->getStabilityFlags () );
1180- $ pool ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1181- $ this ->version_selector = new VersionSelector ( $ pool );
1182- }
1158+ $ repository_set = new Repository \RepositorySet (
1159+ $ composer ->getPackage ()->getMinimumStability (),
1160+ $ composer ->getPackage ()->getStabilityFlags ()
1161+ );
1162+ $ repository_set ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1163+ $ this ->version_selector = new VersionSelector ( $ repository_set );
11831164 }
11841165
11851166 return $ this ->version_selector ;
@@ -1213,7 +1194,7 @@ private function check_github_package_name( $package_name, $version = '', $insec
12131194 $ raw_content_url = "https://raw.githubusercontent.com/ {$ package_name }/ {$ this ->get_raw_git_version ( $ version )}/composer.json " ;
12141195
12151196 $ response = Utils \http_request ( 'GET ' , $ raw_content_url , null /*data*/ , $ headers , $ options );
1216- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1197+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
12171198 // Could not get composer.json. Possibly private so warn and return best guess from input (always xxx/xxx).
12181199 WP_CLI ::warning (
12191200 sprintf (
@@ -1360,7 +1341,7 @@ private function get_github_latest_release_tag( $package_name, $insecure ) {
13601341 $ url = "https://api.github.com/repos/ {$ package_name }/releases/latest " ;
13611342 $ options = [ 'insecure ' => $ insecure ];
13621343 $ response = Utils \http_request ( 'GET ' , $ url , null , [], $ options );
1363- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1344+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
13641345 WP_CLI ::warning ( 'Could not guess stable version from GitHub repository, falling back to master branch ' );
13651346 return 'master ' ;
13661347 }
@@ -1500,15 +1481,6 @@ static function () use (
15001481 );
15011482 }
15021483
1503- /**
1504- * Check whether we are dealing with Composer version 2.0.0+.
1505- *
1506- * @return bool
1507- */
1508- private function is_composer_v2 () {
1509- return version_compare ( Composer::getVersion (), '2.0.0 ' , '>= ' );
1510- }
1511-
15121484 /**
15131485 * Try to retrieve default branch via GitHub API.
15141486 *
@@ -1529,7 +1501,7 @@ private function get_github_default_branch( $package_name, $insecure = false ) {
15291501
15301502 $ github_api_repo_url = "https://api.github.com/repos/ {$ package_name }" ;
15311503 $ response = Utils \http_request ( 'GET ' , $ github_api_repo_url , null /*data*/ , $ headers , $ options );
1532- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1504+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
15331505 WP_CLI ::warning (
15341506 sprintf (
15351507 "Couldn't fetch default branch for package '%s' (HTTP code %d). Presuming default branch is 'master'. " ,
0 commit comments