Skip to content
Snippets Groups Projects

Fix CS

Open Florian Weber requested to merge issue/composer_deploy-3245516:3245516-cs into 8.x-1.x
3 files
+ 41
33
Compare changes
  • Side-by-side
  • Inline
Files
3
<?php
/**
* @file
* Contains \Drupal\composer_deploy\ComposerDeployHandler.
*/
namespace Drupal\composer_deploy;
use DrupalFinder\DrupalFinderComposerRuntime;
use Symfony\Component\Filesystem\Path;
/**
* Load package metadata from composers installed.json file.
*
* @internal
*/
class ComposerDeployHandler {
protected $packages = [];
/**
* List of package prefixes.
* Installed composer packages.
*
* @var string[]
* @var array
*/
protected $prefixes = ['drupal'];
protected array $packages = [];
/**
* @var \DrupalFinder\DrupalFinder
* List of package prefixes.
*
* @var string[]
*/
protected $drupalFinder;
public function __construct(DrupalFinderComposerRuntime $drupalFinder) {
$this->drupalFinder = $drupalFinder;
protected array $prefixes = ['drupal'];
public function __construct(protected DrupalFinderComposerRuntime $drupalFinder) {
$packages = json_decode(file_get_contents($this->drupalFinder->getVendorDir() . '/composer/installed.json'), TRUE);
// Composer 2.0 compatibility.
// @see https://getcomposer.org/upgrade/UPGRADE-2.0.md
@@ -40,9 +35,11 @@ class ComposerDeployHandler {
}
/**
* Lookup package metadata by project name.
*
* @deprecated. Use \Drupal\composer_deploy\ComposerDeployHandler::getPackageByPath instead.
*/
public function getPackage($projectName) {
public function getPackage(string $projectName): ?array {
foreach ($this->packages as $package) {
foreach ($this->prefixes as $prefix) {
if ($package['name'] == $prefix . '/' . $projectName) {
@@ -50,10 +47,13 @@ class ComposerDeployHandler {
}
}
}
return FALSE;
return NULL;
}
public function getPackageByPath($path) {
/**
* Lookup package metadata by path.
*/
public function getPackageByPath(string $path): ?array {
foreach ($this->packages as $package) {
if (isset($package['install-path'])) {
$packagePath = $this->drupalFinder->getVendorDir() . '/composer/' . $package['install-path'];
@@ -62,15 +62,16 @@ class ComposerDeployHandler {
}
}
}
return FALSE;
return NULL;
}
/**
* Set the package prefixes to check against.
*
* @param string[] $prefixes
* Composer vendor prefixes.
*/
public function setPrefixes(array $prefixes) {
public function setPrefixes(array $prefixes): void {
$this->prefixes = $prefixes;
}
Loading