Skip to content
Snippets Groups Projects
Verified Commit 64fb3ff5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3438846 by mondrake: Add return typehints for classes that inherit from Composer

parent 28d407eb
No related branches found
No related tags found
No related merge requests found
<?php <?php
declare(strict_types=1);
namespace Drupal\Composer\Plugin\VendorHardening; namespace Drupal\Composer\Plugin\VendorHardening;
use Composer\Composer; use Composer\Composer;
...@@ -58,7 +60,7 @@ class VendorHardeningPlugin implements PluginInterface, EventSubscriberInterface ...@@ -58,7 +60,7 @@ class VendorHardeningPlugin implements PluginInterface, EventSubscriberInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function activate(Composer $composer, IOInterface $io) { public function activate(Composer $composer, IOInterface $io): void {
$this->composer = $composer; $this->composer = $composer;
$this->io = $io; $this->io = $io;
...@@ -69,19 +71,19 @@ public function activate(Composer $composer, IOInterface $io) { ...@@ -69,19 +71,19 @@ public function activate(Composer $composer, IOInterface $io) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function deactivate(Composer $composer, IOInterface $io) { public function deactivate(Composer $composer, IOInterface $io): void {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function uninstall(Composer $composer, IOInterface $io) { public function uninstall(Composer $composer, IOInterface $io): void {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function getSubscribedEvents() { public static function getSubscribedEvents(): array {
return [ return [
ScriptEvents::POST_AUTOLOAD_DUMP => 'onPostAutoloadDump', ScriptEvents::POST_AUTOLOAD_DUMP => 'onPostAutoloadDump',
ScriptEvents::POST_UPDATE_CMD => 'onPostCmd', ScriptEvents::POST_UPDATE_CMD => 'onPostCmd',
...@@ -99,7 +101,7 @@ public static function getSubscribedEvents() { ...@@ -99,7 +101,7 @@ public static function getSubscribedEvents() {
* @param \Composer\Script\Event $event * @param \Composer\Script\Event $event
* The Composer event. * The Composer event.
*/ */
public function onPostAutoloadDump(Event $event) { public function onPostAutoloadDump(Event $event): void {
$this->writeAccessRestrictionFiles($this->composer->getConfig()->get('vendor-dir')); $this->writeAccessRestrictionFiles($this->composer->getConfig()->get('vendor-dir'));
} }
...@@ -109,7 +111,7 @@ public function onPostAutoloadDump(Event $event) { ...@@ -109,7 +111,7 @@ public function onPostAutoloadDump(Event $event) {
* @param \Composer\Script\Event $event * @param \Composer\Script\Event $event
* The Composer event. * The Composer event.
*/ */
public function onPostCmd(Event $event) { public function onPostCmd(Event $event): void {
$this->cleanAllPackages(); $this->cleanAllPackages();
} }
...@@ -119,7 +121,7 @@ public function onPostCmd(Event $event) { ...@@ -119,7 +121,7 @@ public function onPostCmd(Event $event) {
* @param \Composer\Installer\PackageEvent $event * @param \Composer\Installer\PackageEvent $event
* The package event. * The package event.
*/ */
public function onPrePackageInstall(PackageEvent $event) { public function onPrePackageInstall(PackageEvent $event): void {
/** @var \Composer\Package\CompletePackage $package */ /** @var \Composer\Package\CompletePackage $package */
$package = $event->getOperation()->getPackage(); $package = $event->getOperation()->getPackage();
$this->removeBinBeforeCleanup($package); $this->removeBinBeforeCleanup($package);
...@@ -131,7 +133,7 @@ public function onPrePackageInstall(PackageEvent $event) { ...@@ -131,7 +133,7 @@ public function onPrePackageInstall(PackageEvent $event) {
* @param \Composer\Installer\PackageEvent $event * @param \Composer\Installer\PackageEvent $event
* The package event. * The package event.
*/ */
public function onPrePackageUpdate(PackageEvent $event) { public function onPrePackageUpdate(PackageEvent $event): void {
/** @var \Composer\Package\CompletePackage $package */ /** @var \Composer\Package\CompletePackage $package */
$package = $event->getOperation()->getTargetPackage(); $package = $event->getOperation()->getTargetPackage();
$this->removeBinBeforeCleanup($package); $this->removeBinBeforeCleanup($package);
...@@ -143,7 +145,7 @@ public function onPrePackageUpdate(PackageEvent $event) { ...@@ -143,7 +145,7 @@ public function onPrePackageUpdate(PackageEvent $event) {
* @param \Composer\Installer\PackageEvent $event * @param \Composer\Installer\PackageEvent $event
* The package event. * The package event.
*/ */
public function onPostPackageInstall(PackageEvent $event) { public function onPostPackageInstall(PackageEvent $event): void {
$this->cleanPackage($event->getOperation()->getPackage()); $this->cleanPackage($event->getOperation()->getPackage());
} }
...@@ -153,7 +155,7 @@ public function onPostPackageInstall(PackageEvent $event) { ...@@ -153,7 +155,7 @@ public function onPostPackageInstall(PackageEvent $event) {
* @param \Composer\Installer\PackageEvent $event * @param \Composer\Installer\PackageEvent $event
* The package event. * The package event.
*/ */
public function onPostPackageUpdate(PackageEvent $event) { public function onPostPackageUpdate(PackageEvent $event): void {
$this->cleanPackage($event->getOperation()->getTargetPackage()); $this->cleanPackage($event->getOperation()->getTargetPackage());
} }
...@@ -166,7 +168,7 @@ public function onPostPackageUpdate(PackageEvent $event) { ...@@ -166,7 +168,7 @@ public function onPostPackageUpdate(PackageEvent $event) {
* @param \Composer\Package\BasePackage $package * @param \Composer\Package\BasePackage $package
* The package we're cleaning up. * The package we're cleaning up.
*/ */
protected function removeBinBeforeCleanup(BasePackage $package) { protected function removeBinBeforeCleanup(BasePackage $package): void {
// We can process AliasPackage and Package objects, and they share the // We can process AliasPackage and Package objects, and they share the
// BasePackage parent class. However, since there is no common interface for // BasePackage parent class. However, since there is no common interface for
// these package types that allow for the setBinaries() method, and since // these package types that allow for the setBinaries() method, and since
...@@ -208,7 +210,7 @@ protected function removeBinBeforeCleanup(BasePackage $package) { ...@@ -208,7 +210,7 @@ protected function removeBinBeforeCleanup(BasePackage $package) {
* @return string[] * @return string[]
* Bin files to remove, with the file as both the key and the value. * Bin files to remove, with the file as both the key and the value.
*/ */
protected function findBinOverlap($binaries, $clean_paths) { protected function findBinOverlap(array $binaries, array $clean_paths): array {
// Make a filesystem model to explore. This is a keyed array that looks like // 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 // all the places that will be removed by cleanup. 'tests/src' becomes
// $filesystem['tests']['src'] = TRUE; // $filesystem['tests']['src'] = TRUE;
...@@ -250,7 +252,7 @@ protected function findBinOverlap($binaries, $clean_paths) { ...@@ -250,7 +252,7 @@ protected function findBinOverlap($binaries, $clean_paths) {
* @return \Composer\Package\PackageInterface[] * @return \Composer\Package\PackageInterface[]
* The list of installed packages. * The list of installed packages.
*/ */
protected function getInstalledPackages() { protected function getInstalledPackages(): array {
return $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); return $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
} }
...@@ -264,7 +266,7 @@ protected function getInstalledPackages() { ...@@ -264,7 +266,7 @@ protected function getInstalledPackages() {
* Path to the install path for the package, relative to the project. This * Path to the install path for the package, relative to the project. This
* accounts for changes made by composer/installers, if any. * accounts for changes made by composer/installers, if any.
*/ */
protected function getInstallPathForPackage(PackageInterface $package) { protected function getInstallPathForPackage(PackageInterface $package): string {
return $this->composer->getInstallationManager()->getInstallPath($package); return $this->composer->getInstallationManager()->getInstallPath($package);
} }
...@@ -273,7 +275,7 @@ protected function getInstallPathForPackage(PackageInterface $package) { ...@@ -273,7 +275,7 @@ protected function getInstallPathForPackage(PackageInterface $package) {
* *
* This applies in the context of a post-command event. * This applies in the context of a post-command event.
*/ */
public function cleanAllPackages() { public function cleanAllPackages(): void {
// Get a list of all the packages available after the update or install // Get a list of all the packages available after the update or install
// command. // command.
$installed_packages = []; $installed_packages = [];
...@@ -309,7 +311,7 @@ public function cleanAllPackages() { ...@@ -309,7 +311,7 @@ public function cleanAllPackages() {
* @param \Composer\Package\PackageInterface $package * @param \Composer\Package\PackageInterface $package
* The package to clean. * The package to clean.
*/ */
public function cleanPackage(PackageInterface $package) { public function cleanPackage(PackageInterface $package): void {
// Normalize package names to lower case. // Normalize package names to lower case.
$package_name = strtolower($package->getName()); $package_name = strtolower($package->getName());
if (isset($this->packagesAlreadyCleaned[$package_name])) { if (isset($this->packagesAlreadyCleaned[$package_name])) {
...@@ -332,7 +334,7 @@ public function cleanPackage(PackageInterface $package) { ...@@ -332,7 +334,7 @@ public function cleanPackage(PackageInterface $package) {
* @param string $paths_for_package * @param string $paths_for_package
* List of directories in $package_name to remove * List of directories in $package_name to remove
*/ */
protected function cleanPathsForPackage(PackageInterface $package, $paths_for_package) { protected function cleanPathsForPackage(PackageInterface $package, $paths_for_package): void {
// Whatever happens here, this package counts as cleaned so that we don't // Whatever happens here, this package counts as cleaned so that we don't
// process it more than once. // process it more than once.
$package_name = strtolower($package->getName()); $package_name = strtolower($package->getName());
...@@ -373,7 +375,7 @@ protected function cleanPathsForPackage(PackageInterface $package, $paths_for_pa ...@@ -373,7 +375,7 @@ protected function cleanPathsForPackage(PackageInterface $package, $paths_for_pa
* @param string $vendor_dir * @param string $vendor_dir
* Path to vendor directory. * Path to vendor directory.
*/ */
public function writeAccessRestrictionFiles($vendor_dir) { public function writeAccessRestrictionFiles(string $vendor_dir): void {
$this->io->writeError('<info>Hardening vendor directory with .htaccess and web.config files.</info>'); $this->io->writeError('<info>Hardening vendor directory with .htaccess and web.config files.</info>');
// Prevent access to vendor directory on Apache servers. // Prevent access to vendor directory on Apache servers.
FileSecurity::writeHtaccess($vendor_dir, TRUE); FileSecurity::writeHtaccess($vendor_dir, TRUE);
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
# Skip some dependencies' DebugClassLoader forward compatibility warnings. # Skip some dependencies' DebugClassLoader forward compatibility warnings.
%Method "Behat\\[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% %Method "Behat\\[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
%Method "Composer\\EventDispatcher\\EventSubscriberInterface::getSubscribedEvents\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
%Method "Composer\\Plugin\\PluginInterface::(activate|deactivate|uninstall)\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
%Method "Doctrine\\Common\\Annotations\\Reader::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% %Method "Doctrine\\Common\\Annotations\\Reader::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
%Method "Twig\\Extension\\ExtensionInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% %Method "Twig\\Extension\\ExtensionInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
%Method "Twig\\Loader\\FilesystemLoader::findTemplate\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% %Method "Twig\\Loader\\FilesystemLoader::findTemplate\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message%
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment