function VendorHardeningPlugin::findBinOverlap

Same name in other branches
  1. 9 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::findBinOverlap()
  2. 8.9.x composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::findBinOverlap()
  3. 10 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::findBinOverlap()

Find bin files which are inside cleanup directories.

Parameters

string[] $binaries: 'Bin' configuration from the package we're cleaning up.

string[] $clean_paths: The paths we're cleaning up.

Return value

string[] Bin files to remove, with the file as both the key and the value.

1 call to VendorHardeningPlugin::findBinOverlap()
VendorHardeningPlugin::removeBinBeforeCleanup in composer/Plugin/VendorHardening/VendorHardeningPlugin.php
Remove bin config for packages that would have the bin file removed.

File

composer/Plugin/VendorHardening/VendorHardeningPlugin.php, line 213

Class

VendorHardeningPlugin
A Composer plugin to clean out your project's vendor directory.

Namespace

Drupal\Composer\Plugin\VendorHardening

Code

protected function findBinOverlap(array $binaries, array $clean_paths) : array {
    // Make a filesystem model to explore. This is a keyed array that looks like
    // all the places that will be removed by cleanup. 'tests/src' becomes
    // $filesystem['tests']['src'] = TRUE;
    $filesystem = [];
    foreach ($clean_paths as $clean_path) {
        $clean_pieces = explode("/", $clean_path);
        // phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable
        $current =& $filesystem;
        foreach ($clean_pieces as $clean_piece) {
            $current =& $current[$clean_piece];
        }
        $current = TRUE;
    }
    // Explore the filesystem with our bin config.
    $unset_these_binaries = [];
    foreach ($binaries as $binary) {
        $binary_pieces = explode('/', $binary);
        $current =& $filesystem;
        foreach ($binary_pieces as $binary_piece) {
            if (!isset($current[$binary_piece])) {
                break;
            }
            else {
                // Value of TRUE means we're at the end of the path.
                if ($current[$binary_piece] === TRUE) {
                    $unset_these_binaries[$binary] = $binary;
                    break;
                }
            }
            $current =& $filesystem[$binary_piece];
        }
    }
    return $unset_these_binaries;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.