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 ;
@@ -932,8 +927,8 @@ private function package_index() {
932927 * Displays a set of packages
933928 *
934929 * @param string $context
935- * @param array
936- * @param array
930+ * @param array $packages
931+ * @param array $assoc_args
937932 */
938933 private function show_packages ( $ context , $ packages , $ assoc_args ) {
939934 $ default_fields = [];
@@ -976,7 +971,7 @@ private function show_packages( $context, $packages, $assoc_args ) {
976971 $ update_version = '' ;
977972 if ( 'list ' === $ context && ! $ skip_update_check ) {
978973 try {
979- $ latest = $ this ->find_latest_package ( $ package , $ composer, null );
974+ $ latest = $ this ->find_latest_package ( $ package , $ composer );
980975 if ( $ latest && $ latest ->getFullPrettyVersion () !== $ package ->getFullPrettyVersion () ) {
981976 $ update = 'available ' ;
982977 $ update_version = $ latest ->getPrettyVersion ();
@@ -1039,7 +1034,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
10391034 // Check if the package exists on Packagist.
10401035 $ url = "https://repo.packagist.org/p2/ {$ package_name }.json " ;
10411036 $ response = Utils \http_request ( 'GET ' , $ url , null , [], $ options );
1042- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1037+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
10431038 return $ package_name ;
10441039 }
10451040
@@ -1048,7 +1043,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
10481043 $ github_token = getenv ( 'GITHUB_TOKEN ' ); // Use GITHUB_TOKEN if available to avoid authorization failures or rate-limiting.
10491044 $ headers = $ github_token ? [ 'Authorization ' => 'token ' . $ github_token ] : [];
10501045 $ response = Utils \http_request ( 'GET ' , $ url , null /*data*/ , $ headers , $ options );
1051- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1046+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
10521047 return $ url ;
10531048 }
10541049
@@ -1058,7 +1053,7 @@ private function get_package_by_shortened_identifier( $package_name, $insecure =
10581053 $ headers = $ github_token ? [ 'Authorization ' => 'token ' . $ github_token ] : [];
10591054 $ headers = $ gitlab_token && strpos ( $ package_name , '://gitlab.com/ ' ) !== false ? [ 'PRIVATE-TOKEN ' => $ gitlab_token ] : [];
10601055 $ response = Utils \http_request ( 'GET ' , $ url , null /*data*/ , $ headers , $ options );
1061- if ( 20 === (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1056+ if ( 20 === (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
10621057 return $ url ;
10631058 }
10641059
@@ -1086,9 +1081,6 @@ private function get_installed_packages() {
10861081 if ( in_array ( $ package ->getPrettyName (), $ installed_package_keys , true ) ) {
10871082 $ installed_packages [] = $ package ;
10881083 } elseif ( false !== $ idx ) { // Legacy incorrect name check.
1089- if ( ! $ this ->is_composer_v2 () ) {
1090- WP_CLI ::warning ( sprintf ( "Found package '%s' misnamed '%s' in '%s'. " , $ package ->getPrettyName (), $ installed_package_keys [ $ idx ], $ this ->get_composer_json_path () ) );
1091- }
10921084 $ installed_packages [] = $ package ;
10931085 }
10941086 }
@@ -1240,12 +1232,11 @@ private function create_default_composer_json( $composer_path ) {
12401232 *
12411233 * @param PackageInterface $package
12421234 * @param Composer $composer
1243- * @param string $phpVersion
1244- * @param bool $minorOnly
1235+ * @param bool $minor_only
12451236 *
1246- * @return PackageInterface|null
1237+ * @return PackageInterface|false
12471238 */
1248- private function find_latest_package ( PackageInterface $ package , Composer $ composer , $ php_version , $ minor_only = false ) {
1239+ private function find_latest_package ( PackageInterface $ package , Composer $ composer , $ minor_only = false ) {
12491240 // Find the latest version allowed in this pool/repository set.
12501241 $ name = $ package ->getPrettyName ();
12511242 $ version_selector = $ this ->get_version_selector ( $ composer );
@@ -1266,30 +1257,20 @@ private function find_latest_package( PackageInterface $package, Composer $compo
12661257 $ target_version = '^ ' . $ package ->getVersion ();
12671258 }
12681259
1269- if ( $ this ->is_composer_v2 () ) {
1270- return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ best_stability );
1271- }
1272-
1273- return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ php_version , $ best_stability );
1260+ return $ version_selector ->findBestCandidate ( $ name , $ target_version , $ best_stability );
12741261 }
12751262
12761263 /**
12771264 * @return VersionSelector
12781265 */
12791266 private function get_version_selector ( Composer $ composer ) {
12801267 if ( ! $ this ->version_selector ) {
1281- if ( $ this ->is_composer_v2 () ) {
1282- $ repository_set = new Repository \RepositorySet (
1283- $ composer ->getPackage ()->getMinimumStability (),
1284- $ composer ->getPackage ()->getStabilityFlags ()
1285- );
1286- $ repository_set ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1287- $ this ->version_selector = new VersionSelector ( $ repository_set );
1288- } else {
1289- $ pool = new Pool ( $ composer ->getPackage ()->getMinimumStability (), $ composer ->getPackage ()->getStabilityFlags () );
1290- $ pool ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1291- $ this ->version_selector = new VersionSelector ( $ pool );
1292- }
1268+ $ repository_set = new Repository \RepositorySet (
1269+ $ composer ->getPackage ()->getMinimumStability (),
1270+ $ composer ->getPackage ()->getStabilityFlags ()
1271+ );
1272+ $ repository_set ->addRepository ( new CompositeRepository ( $ composer ->getRepositoryManager ()->getRepositories () ) );
1273+ $ this ->version_selector = new VersionSelector ( $ repository_set );
12931274 }
12941275
12951276 return $ this ->version_selector ;
@@ -1323,7 +1304,7 @@ private function check_github_package_name( $package_name, $version = '', $insec
13231304 $ raw_content_url = "https://raw.githubusercontent.com/ {$ package_name }/ {$ this ->get_raw_git_version ( $ version )}/composer.json " ;
13241305
13251306 $ response = Utils \http_request ( 'GET ' , $ raw_content_url , null /*data*/ , $ headers , $ options );
1326- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1307+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
13271308 // Could not get composer.json. Possibly private so warn and return best guess from input (always xxx/xxx).
13281309 WP_CLI ::warning (
13291310 sprintf (
@@ -1470,7 +1451,7 @@ private function get_github_latest_release_tag( $package_name, $insecure ) {
14701451 $ url = "https://api.github.com/repos/ {$ package_name }/releases/latest " ;
14711452 $ options = [ 'insecure ' => $ insecure ];
14721453 $ response = Utils \http_request ( 'GET ' , $ url , null , [], $ options );
1473- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1454+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
14741455 WP_CLI ::warning ( 'Could not guess stable version from GitHub repository, falling back to master branch ' );
14751456 return 'master ' ;
14761457 }
@@ -1610,15 +1591,6 @@ static function () use (
16101591 );
16111592 }
16121593
1613- /**
1614- * Check whether we are dealing with Composer version 2.0.0+.
1615- *
1616- * @return bool
1617- */
1618- private function is_composer_v2 () {
1619- return version_compare ( Composer::getVersion (), '2.0.0 ' , '>= ' );
1620- }
1621-
16221594 /**
16231595 * Try to retrieve default branch via GitHub API.
16241596 *
@@ -1639,7 +1611,7 @@ private function get_github_default_branch( $package_name, $insecure = false ) {
16391611
16401612 $ github_api_repo_url = "https://api.github.com/repos/ {$ package_name }" ;
16411613 $ response = Utils \http_request ( 'GET ' , $ github_api_repo_url , null /*data*/ , $ headers , $ options );
1642- if ( 20 !== (int ) substr ( $ response ->status_code , 0 , 2 ) ) {
1614+ if ( 20 !== (int ) substr ( ( string ) $ response ->status_code , 0 , 2 ) ) {
16431615 WP_CLI ::warning (
16441616 sprintf (
16451617 "Couldn't fetch default branch for package '%s' (HTTP code %d). Presuming default branch is 'master'. " ,
0 commit comments