Skip to content

Commit c083570

Browse files
MC-5465: Addressing code sniff and mess detector reports
1 parent 12af12c commit c083570

File tree

17 files changed

+776
-517
lines changed

17 files changed

+776
-517
lines changed

docs/class_descriptions.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ Extends the native [RequireCommand](https://getcomposer.org/apidoc/master/Compos
6464
- **`setApplication()`**
6565
- Overrides the command's name to `require` after the command registry is checked but before the command is actually added to the registry. This allows the command to replace the native `RequireCommand` instance that is normally associated with the `composer require` CLI command
6666
- **`execute()`**
67-
- Wraps the native `RequireCommand::execute()` function with the Magento project update code if a Magento product package is found in the command's parameters
67+
- Wraps the native `RequireCommand::execute()` function with the Magento project update code
6868
- **`runUpdate()`**
6969
- Calls [MagentoRootUpdater::runUpdate()](#magentorootupdater) after processing CLI options
70+
- **`parseMagentoRequirement()`**
71+
- Parses the CLI command arguments for a magento/product requirement
7072

7173
#### [**Commands\UpdatePluginNamespaceCommands**](../src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php)
7274

@@ -132,6 +134,8 @@ This class manages the plugin's self-installation inside the `var` directory to
132134
- Called by `composer magento-update-plugin install` and the Magento module setup classes ([InstallData](#installdatarecurringdataupgradedata), [RecurringData](#installdatarecurringdataupgradedata), [UpgradeData](#installdatarecurringdataupgradedata))
133135
- **`updateSetupWizardPlugin()`**
134136
- Installs the plugin inside `var/vendor` where it can be found by the `composer require` command run by the Web Setup Wizard's validation check. This is accomplished by creating a dummy project directory with a `composer.json` file that requires only the plugin, installing it, then copying the resulting `vendor` directory to `var/vendor`
137+
- **`getTempDir()`**
138+
- Creates a temporary directory inside the `var` directory to use for the dummy plugin project in `updateSetupWizardPlugin()`
135139
- **`deletePath()`**
136140
- Recursively deletes a file or directory and all its contents
137141
- **`copyAndReplace()`**
@@ -155,15 +159,27 @@ This is accomplished by comparing `composer.json` fields between the original Ma
155159
- Entry point into the resolution functionality
156160
- Calls the relevant resolve function for each `composer.json` field that can be updated
157161
- **`findResolution()`**
158-
- For an individual field value, compare the original Magento value to the target Magento value, and if a delta is found, check if the user's installation has a customized value for the field. If the user has changed the value, resolve the conflict according to the CLI command options: use the user's custom value, override with the target Magento value, or interactively ask the user which of the two values should be used
162+
- For an individual field value, compare the original Magento value to the target Magento value, and if a delta is found, check if the user's installation has a customized value for the field then apply the appropriate resolution
163+
- **`prettify()`**
164+
- Formats a field value to be human-readable if a preset pretty value is not present
165+
- **`solveIfConflict()`**
166+
- If the user has a field value that conflicts with an expected delta, resolve the conflict according to the CLI command options: use the user's custom value, override with the target Magento value, or interactively ask the user which of the two values should be used
159167
- **`resolveLinkSection()`**
160168
- For a given `composer.json` section that consists of links to package versions/constraints (such as the `require` and `conflict` sections), call `findLinkResolution()` for each package constraint found in either the original Magento root or the target Magento root
169+
- **`resolveLink()`**
170+
- Helper function to call `findResolution()` for a particular package for use by `resolveLinkSection()`
171+
- **`getConstraintValues()`**
172+
- Helper function to get the raw and pretty forms of a link for comparison
173+
- **`applyLinkChanges()`**
174+
- Adjust the json values for a link section according to the resolutions calculated by `resolveLinkSection()`
161175
- **`resolveArraySection()`**
162176
- For a given `composer.json` section that consists of data that is not package links (such as the `"autoload"` or `"extra"` sections), call `resolveNestedArray()` and accept the new values if changes were made
163177
- **`resolveNestedArray()`**
164178
- Recursively processes changes to a `composer.json` value that could be a nested array, calling `findResolution()` for each "leaf" value found in either the original Magento root or the target Magento root
165-
- **`findLinkResolution()`**
166-
- Helper function to call `findResolution()` for a particular package for use by `resolveLinkSection()`
179+
- **`resolveFlatArray()`**
180+
- Process changes to the non-associative portion of an array field value, treating it as an unordered set
181+
- **`resolveAssociativeArray()`**
182+
- Process changes to the associative portion of an array field value that could contain nested arrays
167183
- **`getLinkOrderOverride()`**
168184
- Determine the order to use for a link section when the user's order disagrees with the target Magento section order
169185
- **`buildLinkOrderComparator()`**
@@ -190,10 +206,12 @@ This class contains methods to retrieve Composer [Package](https://getcomposer.o
190206
- Returns the existing root project package, including all user customizations
191207
- **`fetchMageRootFromRepo()`**
192208
- Given a Magento edition and version constraint, fetch the best-fit Magento root project package from the Composer repository
193-
- **`parseOriginalVersionAndEditionFromLock()`**
209+
- **`parseVersionAndEditionFromLock()`**
194210
- Inspect the `composer.lock` file for the currently-installed Magento product package and parse out the edition and version for use by `getOriginalRootPackage()`
195-
- **`getRootLocker()`**
196-
- Helper function to get the [Locker](https://getcomposer.org/apidoc/master/Composer/Package/Locker.html) object for the `composer.lock` file in the project root directory. If the current working directory is `var` (which is the case for the Web Setup Wizard), instead use the `composer.lock` file in the parent directory
211+
- **`getTargetLabel()`**
212+
- Gets the formatted label for the target Magento version
213+
- **`getOriginalLabel()`**
214+
- Gets the formatted label for the originally-installed Magento version
197215

198216
***
199217

@@ -222,7 +240,13 @@ Common package-related utility functions.
222240
- Extracts the package type (`product` or `project`) from a Magento package name
223241
- **`getMagentoProductEdition()`**
224242
- Extracts the package edition from a Magento product package name
243+
- **`getEditionLabel()`**
244+
- Translates package edition into the marketing edition label
225245
- **`findRequire()`**
226246
- Searches the `"require"` section of a [Composer](https://getcomposer.org/apidoc/master/Composer/Composer.html) object for a package link that fits the supplied name or matcher
227247
- **`isConstraintStrict()`**
228248
- Checks if a version constraint is strict or if it allows multiple versions (such as `~1.0` or `>= 1.5.3`)
249+
- **`getLockedProduct()`**
250+
- Gets the installed magento/product package from the composer.lock file if it exists
251+
- **`getRootLocker()`**
252+
- Helper function to get the [Locker](https://getcomposer.org/apidoc/master/Composer/Package/Locker.html) object for the `composer.lock` file in the project root directory. If the current working directory is `var` (which is the case for the Web Setup Wizard), instead use the `composer.lock` file in the parent directory

docs/process_flows.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ There are four paths through the plugin code that cover two main pieces of funct
3030
2. Composer recognizes `require` as the command passed to the executable and finds `MageRootRequireCommand` as the command object registered under that name
3131
3. Composer calls `MageRootRequireCommand::execute()`
3232
4. `MageRootRequireCommand::execute()` backs up the user's `composer.json` file through [ExtendableRequireCommand::parseComposerJsonFile()](class_descriptions.md#extendablerequirecommand)
33-
5. `MageRootRequireCommand::execute()` checks the `composer require` arguments for a `magento/product` package, and if it finds one it calls `MageRootRequireCommand::runUpdate()`
34-
6. `MageRootRequireCommand::runUpdate()` calls [MagentoRootUpdater::runUpdate()](class_descriptions.md#magentorootupdater)
35-
7. `MageRootRequireCommand::runUpdate()` calls [DeltaResolver::resolveRootDeltas()](class_descriptions.md#deltaresolver)
36-
8. `DeltaResolver::resolveRootDeltas()` uses [RootPackageRetriever](class_descriptions.md#rootpackageretriever) to obtain the Composer [Package](https://getcomposer.org/apidoc/master/Composer/Package/Package.html) objects for the root `composer.json` files from the default installation of the existing edition and version, the target edition and version supplied to the `composer require` call, and the user's current installation including any customizations they have made
37-
9. `DeltaResolver::resolveRootDeltas()` iterates over the fields in `composer.json` to determine any values that need to be updated to match the root `composer.json` file of the new Magento edition/version
33+
5. `MageRootRequireCommand::execute()` calls `MageRootRequireCommand::runUpdate()`
34+
6. `MageRootRequireCommand::runUpdate()` calls `MageRootRequireCommand::parseMageRequirement()` to check the `composer require` arguments for a `magento/product` package
35+
7. If a `magento/product` package is found in the command arguments, it calls [MagentoRootUpdater::runUpdate()](class_descriptions.md#magentorootupdater)
36+
8. `MagentoRootUpdater::runUpdate()` calls [DeltaResolver::resolveRootDeltas()](class_descriptions.md#deltaresolver)
37+
9. `DeltaResolver::resolveRootDeltas()` uses [RootPackageRetriever](class_descriptions.md#rootpackageretriever) to obtain the Composer [Package](https://getcomposer.org/apidoc/master/Composer/Package/Package.html) objects for the root `composer.json` files from the default installation of the existing edition and version, the target edition and version supplied to the `composer require` call, and the user's current installation including any customizations they have made
38+
10. `DeltaResolver::resolveRootDeltas()` iterates over the fields in `composer.json` to determine any values that need to be updated to match the root `composer.json` file of the new Magento edition/version
3839
1. To find these values, it compares the values for each field in the default project for the installed edition/version with the project for the target edition/version (`DeltaResolver::findResolution()`)
3940
2. If a value has changed in the target, it checks that field in the user's customized root `composer.json` file to see if it has been overwritten with a custom value
4041
3. If the user customized the value, the conflict will be resolved according to the specified resolution strategy: use the expected Magento value, use the user's custom value, or prompt the user to specify which value should be used
41-
10. If `resolveRootDeltas()` found values that need to change, `MageRootRequireCommand::execute()` calls `MagentoRootUpdater::writeUpdatedComposerJson()` to apply those changes
42-
11. `MageRootRequireCommand::execute()` calls the native `RequireCommand::execute()` function, which will now use the updated root `composer.json` file if the plugin made changes
43-
12. If the `RequireCommand::execute()` call fails after the plugin makes changes, `MageRootRequireCommand::execute()` calls `ExtendableRequireCommand::revertMageComposerFile()` to restore the `composer.json` file to its original state
42+
11. If `resolveRootDeltas()` found values that need to change, `MageRootRequireCommand::runUpdate()` calls `MagentoRootUpdater::writeUpdatedComposerJson()` to apply those changes
43+
12. `MageRootRequireCommand::execute()` calls the native `RequireCommand::execute()` function, which will now use the updated root `composer.json` file if the plugin made changes
44+
13. If the `RequireCommand::execute()` call fails after the plugin makes changes, `MageRootRequireCommand::execute()` calls `ExtendableRequireCommand::revertMageComposerFile()` to restore the `composer.json` file to its original state
4445

4546
***
4647

src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/AccessibleRootPackageLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
// @codingStandardsIgnoreFile
8+
79
namespace Magento\ComposerRootUpdatePlugin\ComposerReimplementation;
810

911
use Composer\Package\BasePackage;
@@ -28,8 +30,9 @@ class AccessibleRootPackageLoader
2830
* @param string $reqVersion
2931
* @param string $minimumStability
3032
* @return array
33+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
3134
*/
32-
public static function extractStabilityFlags($reqName, $reqVersion, $minimumStability)
35+
public function extractStabilityFlags($reqName, $reqVersion, $minimumStability)
3336
{
3437
$stabilityFlags = [];
3538
$stabilityMap = BasePackage::$stabilities;

src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
// @codingStandardsIgnoreFile
8+
79
namespace Magento\ComposerRootUpdatePlugin\ComposerReimplementation;
810

911
use Composer\Command\InitCommand;
@@ -144,6 +146,9 @@ protected function parseComposerJsonFile($input)
144146
*
145147
* @return array
146148
* @throws \Exception
149+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
150+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
151+
* @SuppressWarnings(PHPMD.NPathComplexity)
147152
*/
148153
protected function getRequirementsInteractive()
149154
{

0 commit comments

Comments
 (0)