@@ -80,10 +80,13 @@ public function suggestComposerCommand($result, CommandData $commandData)
8080 }
8181
8282 /**
83+ * Fetches the generated composer.json from drupal-security-advisories.
84+ *
8385 * @return mixed
86+ *
8487 * @throws \Exception
8588 */
86- protected function fetchAdvisoryComposerJson (): mixed {
89+ protected function fetchAdvisoryComposerJson () {
8790 try {
8891 $ response_body = file_get_contents ('https://raw.githubusercontent.com/drupal-composer/drupal-security-advisories/8.x/composer.json ' );
8992 } catch (Exception $ e ) {
@@ -94,10 +97,13 @@ protected function fetchAdvisoryComposerJson(): mixed {
9497 }
9598
9699 /**
97- * @return mixed
100+ * Loads the contents of the local Drupal application's composer.lock file.
101+ *
102+ * @return array
103+ *
98104 * @throws \Exception
99105 */
100- protected function loadSiteComposerLock (): mixed {
106+ protected function loadSiteComposerLock () {
101107 $ composer_root = Drush::bootstrapManager ()->getComposerRoot ();
102108 $ composer_lock_file_name = getenv ('COMPOSER ' ) ? str_replace ('.json ' , '' ,
103109 getenv ('COMPOSER ' )) : 'composer ' ;
@@ -116,8 +122,11 @@ protected function loadSiteComposerLock(): mixed {
116122 }
117123
118124 /**
119- * @param $composer_lock_data
120- * @param $security_advisories_composer_json
125+ * Register all available security updates in $this->securityUpdates.
126+ * @param array $composer_lock_data
127+ * The contents of the local Drupal application's composer.lock file.
128+ * @param array $security_advisories_composer_json
129+ * The composer.json array from drupal-security-advisories.
121130 */
122131 protected function registerAllSecurityUpdates (
123132 $ composer_lock_data ,
@@ -130,9 +139,18 @@ protected function registerAllSecurityUpdates(
130139 }
131140
132141 /**
133- * @param $conflict_constraint
142+ * Determines if update is avaiable based on a conflict constraint.
143+ *
144+ * @param string $conflict_constraint
145+ * The constraint for the conflicting, insecure package version.
146+ * E.g., <1.0.0.
134147 * @param array $package
135- * @param $name
148+ * The package to be evaluated.
149+ * @param string $name
150+ * The human readable display name for the package.
151+ *
152+ * @return array
153+ * An associative array containing name, version, and min-version keys.
136154 */
137155 public static function determineUpdatesFromConstraint (
138156 $ conflict_constraint ,
@@ -147,7 +165,7 @@ public static function determineUpdatesFromConstraint(
147165 return [
148166 'name ' => $ name ,
149167 'version ' => $ package ['version ' ],
150- // Assume that conflict constraint of ^ 1.0.0 indicates that
168+ // Assume that conflict constraint of < 1.0.0 indicates that
151169 // 1.0.0 is the available, secure version.
152170 'min-version ' => $ min_version ,
153171 ];
@@ -159,27 +177,32 @@ public static function determineUpdatesFromConstraint(
159177 $ exact_version = $ conflict_constraint ;
160178 if (Comparator::equalTo ($ package ['version ' ],
161179 $ exact_version )) {
162- // $version_parts = explode('.', $package['version']);
163- $ version_parser = new VersionParser ();
164- $ constraints = $ version_parser ->parseConstraints ($ package ['version ' ]);
165- return [
166- 'name ' => $ name ,
167- 'version ' => $ package ['version ' ],
168- // Assume that conflict constraint of 1.0.0 indicates that
169- // 1.0.1 is the available, secure version.
170- 'min-version ' => $ exact_version ,
171- ];
180+ $ version_parts = explode ('. ' , $ package ['version ' ]);
181+ if (count ($ version_parts ) == 3 ) {
182+ $ version_parts [2 ]++;
183+ $ min_version = implode ('. ' , $ version_parts );
184+ return [
185+ 'name ' => $ name ,
186+ 'version ' => $ package ['version ' ],
187+ // Assume that conflict constraint of 1.0.0 indicates that
188+ // 1.0.1 is the available, secure version.
189+ 'min-version ' => $ min_version ,
190+ ];
191+ }
172192 }
173193 }
174- else {
175- return [];
176- }
194+ return [];
177195 }
178196
179197 /**
180- * @param $security_advisories_composer_json
181- * @param $name
182- * @param $package
198+ * Registers available security updates for a given package.
199+ *
200+ * @param array $security_advisories_composer_json
201+ * The composer.json array from drupal-security-advisories.
202+ * @param string $name
203+ * The human readable display name for the package.
204+ * @param array $package
205+ * The package to be evaluated.
183206 */
184207 protected function registerPackageSecurityUpdates (
185208 $ security_advisories_composer_json ,
0 commit comments