From 68d32b2eba184abca458dc577134ecd321d3f8fb Mon Sep 17 00:00:00 2001 From: Adam G-H <32250-phenaproxima@users.noreply.drupalcode.org> Date: Wed, 15 Feb 2023 19:16:43 +0000 Subject: [PATCH] Issue #3321474 by phenaproxima, tedbow: Adopt PHP 8.1-only capabilities such as constructor property promotion + drop BC layers --- automatic_updates.routing.yml | 33 - automatic_updates.services.yml | 13 - .../automatic_updates_extensions.services.yml | 1 - .../src/ExtensionUpdater.php | 21 - .../src/Form/UpdateReady.php | 2 +- ...tomaticUpdatesExtensionsKernelTestBase.php | 3 - package_manager/package_manager.services.yml | 16 +- package_manager/src/ComposerInspector.php | 10 +- package_manager/src/ComposerUtility.php | 2 +- .../src/Event/ExcludedPathsTrait.php | 24 - package_manager/src/Event/PreApplyEvent.php | 11 +- package_manager/src/Event/PreCreateEvent.php | 9 +- package_manager/src/Event/StageEvent.php | 10 +- .../src/Event/StatusCheckEvent.php | 6 +- .../EventSubscriber/UpdateDataSubscriber.php | 14 +- package_manager/src/ExecutableFinder.php | 12 +- package_manager/src/FailureMarker.php | 10 +- package_manager/src/FileSyncerFactory.php | 41 +- .../src/PackageManagerUninstallValidator.php | 2 - package_manager/src/Path.php | 820 ------------------ .../src/PathExcluder/GitExcluder.php | 12 +- .../src/PathExcluder/PathExclusionsTrait.php | 24 +- .../SiteConfigurationExcluder.php | 12 +- .../src/PathExcluder/SiteFilesExcluder.php | 22 +- .../PathExcluder/SqliteDatabaseExcluder.php | 10 +- package_manager/src/PathLocator.php | 45 +- package_manager/src/ProcessFactory.php | 22 +- package_manager/src/ProjectInfo.php | 10 +- package_manager/src/Stage.php | 154 +--- package_manager/src/StatusCheckTrait.php | 15 +- package_manager/src/UnusedConfigFactory.php | 82 -- package_manager/src/ValidationResult.php | 26 +- .../Validator/ComposerExecutableValidator.php | 50 +- .../Validator/ComposerJsonExistsValidator.php | 16 +- .../ComposerMinimumStabilityValidator.php | 20 +- .../Validator/ComposerPatchesValidator.php | 14 +- .../Validator/ComposerPluginsValidator.php | 24 +- .../Validator/ComposerSettingsValidator.php | 24 +- .../src/Validator/DiskSpaceValidator.php | 16 +- .../Validator/DuplicateInfoFileValidator.php | 12 +- .../Validator/EnvironmentSupportValidator.php | 2 +- .../src/Validator/LockFileValidator.php | 26 +- .../src/Validator/MultisiteValidator.php | 16 +- .../OverwriteExistingPackagesValidator.php | 12 +- .../src/Validator/PendingUpdatesValidator.php | 26 +- .../PreOperationStageValidatorInterface.php | 25 - .../src/Validator/SettingsValidator.php | 11 - .../Validator/StageNotInActiveValidator.php | 13 +- .../src/Validator/StagedDBUpdateValidator.php | 39 +- .../src/Validator/SymlinkValidator.php | 48 +- .../Validator/WritableFileSystemValidator.php | 16 +- .../src/MockPathLocator.php | 2 +- .../src/ApiController.php | 7 +- .../Kernel/PackageManagerKernelTestBase.php | 3 - .../Kernel/PathExcluder/GitExcluderTest.php | 2 +- .../SiteConfigurationExcluderTest.php | 2 +- .../SqliteDatabaseExcluderTest.php | 2 +- .../tests/src/Kernel/StageEventsTest.php | 21 - .../tests/src/Kernel/StageTest.php | 47 - .../tests/src/Unit/PathLocatorTest.php | 19 - .../Unit/StageNotInActiveValidatorTest.php | 2 +- src/Controller/StatusCheckController.php | 47 +- src/Controller/UpdateController.php | 86 +- src/CronUpdater.php | 59 +- src/Event/ReadinessCheckEvent.php | 82 -- src/EventSubscriber/ConfigSubscriber.php | 13 +- src/Form/UpdateReady.php | 59 +- src/Form/UpdaterForm.php | 77 +- src/ReleaseChooser.php | 12 +- src/StatusCheckMailer.php | 37 +- src/Updater.php | 21 - src/Validation/AdminStatusCheckMessages.php | 87 +- src/Validation/ReadinessValidationManager.php | 73 -- src/Validation/StatusCheckRequirements.php | 27 +- src/Validation/StatusChecker.php | 55 +- src/Validator/CronFrequencyValidator.php | 68 +- src/Validator/CronServerValidator.php | 26 +- src/Validator/RequestedUpdateValidator.php | 11 - .../ScaffoldFilePermissionsValidator.php | 12 +- .../StagedDatabaseUpdateValidator.php | 16 +- src/Validator/StagedProjectsValidator.php | 11 - src/Validator/VersionPolicyValidator.php | 12 +- tests/src/Functional/DeprecatedRoutesTest.php | 66 -- tests/src/Functional/PreUpdateTest.php | 4 +- .../Functional/UpdateCompleteMessageTest.php | 2 +- tests/src/Functional/UpdateErrorTest.php | 2 +- tests/src/Functional/UpdateFailedTest.php | 4 +- tests/src/Functional/UpdateWarningTest.php | 2 +- tests/src/Kernel/ReadinessCheckTest.php | 52 -- .../CronFrequencyValidatorTest.php | 1 - 90 files changed, 275 insertions(+), 2760 deletions(-) delete mode 100644 package_manager/src/Path.php delete mode 100644 package_manager/src/UnusedConfigFactory.php delete mode 100644 package_manager/src/Validator/PreOperationStageValidatorInterface.php delete mode 100644 src/Event/ReadinessCheckEvent.php delete mode 100644 src/Validation/ReadinessValidationManager.php delete mode 100644 tests/src/Functional/DeprecatedRoutesTest.php delete mode 100644 tests/src/Kernel/ReadinessCheckTest.php diff --git a/automatic_updates.routing.yml b/automatic_updates.routing.yml index 059a5631f8..e3f0cb67b6 100644 --- a/automatic_updates.routing.yml +++ b/automatic_updates.routing.yml @@ -33,36 +33,3 @@ automatic_updates.cron.post_apply: _controller: 'automatic_updates.cron_updater:handlePostApply' requirements: _access_system_cron: 'TRUE' - -# These routes are deprecated and will be removed in the next major version of -# Automatic Updates. They redirect to existing routes from the core Update -# module, which are overridden by Automatic Updates. -# @see \Drupal\automatic_updates\Routing\RouteSubscriber::alterRoutes() -automatic_updates.report_update: - path: '/admin/reports/updates/automatic-update' - defaults: - _controller: '\Drupal\automatic_updates\Controller\UpdateController::redirectDeprecatedRoute' - requirements: - _access: 'TRUE' -automatic_updates.module_update: - path: '/admin/modules/automatic-update' - defaults: - _controller: '\Drupal\automatic_updates\Controller\UpdateController::redirectDeprecatedRoute' - requirements: - _access: 'TRUE' -automatic_updates.theme_update: - path: '/admin/theme/automatic-update' - defaults: - _controller: '\Drupal\automatic_updates\Controller\UpdateController::redirectDeprecatedRoute' - requirements: - _access: 'TRUE' -automatic_updates.update_readiness: - path: '/admin/automatic_updates/readiness' - defaults: - _controller: '\Drupal\automatic_updates\Controller\StatusCheckController::runReadiness' - _title: 'Update readiness checking' - requirements: - _permission: 'administer software updates' - options: - _maintenance_access: TRUE - _automatic_updates_status_messages: skip diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml index 0e00751f89..8c27147e6b 100644 --- a/automatic_updates.services.yml +++ b/automatic_updates.services.yml @@ -20,15 +20,9 @@ services: - '@config.factory' - '@plugin.manager.mail' - '@language_manager' - automatic_updates.readiness_validation_manager: - class: Drupal\automatic_updates\Validation\ReadinessValidationManager - arguments: - - '@automatic_updates.status_checker' - deprecated: The "%service_id%" service is deprecated in automatic_updates:8.x-2.5 and is removed from automatic_updates:3.0.0. Use the automatic_updates.status_checker service instead. See https://www.drupal.org/node/3316086. automatic_updates.updater: class: Drupal\automatic_updates\Updater arguments: - - '@config.factory' - '@package_manager.path_locator' - '@package_manager.beginner' - '@package_manager.stager' @@ -45,7 +39,6 @@ services: class: Drupal\automatic_updates\CronUpdater arguments: - '@automatic_updates.release_chooser' - - '@logger.factory' - '@plugin.manager.mail' - '@automatic_updates.status_check_mailer' - '@state' @@ -64,14 +57,10 @@ services: - ['setLogger', ['@logger.channel.automatic_updates']] automatic_updates.requested_update_validator: class: Drupal\automatic_updates\Validator\RequestedUpdateValidator - arguments: - - '@string_translation' tags: - { name: event_subscriber } automatic_updates.staged_projects_validator: class: Drupal\automatic_updates\Validator\StagedProjectsValidator - arguments: - - '@string_translation' tags: - { name: event_subscriber } automatic_updates.release_chooser: @@ -85,7 +74,6 @@ services: - '@module_handler' - '@state' - '@datetime.time' - - '@string_translation' - '@automatic_updates.cron_updater' - '@lock' tags: @@ -94,7 +82,6 @@ services: class: Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator arguments: - '@package_manager.validator.staged_database_updates' - - '@string_translation' tags: - { name: event_subscriber } automatic_updates.validator.version_policy: diff --git a/automatic_updates_extensions/automatic_updates_extensions.services.yml b/automatic_updates_extensions/automatic_updates_extensions.services.yml index 95de366d61..12e84a9ade 100644 --- a/automatic_updates_extensions/automatic_updates_extensions.services.yml +++ b/automatic_updates_extensions/automatic_updates_extensions.services.yml @@ -2,7 +2,6 @@ services: automatic_updates_extensions.updater: class: Drupal\automatic_updates_extensions\ExtensionUpdater arguments: - - '@config.factory' - '@package_manager.path_locator' - '@package_manager.beginner' - '@package_manager.stager' diff --git a/automatic_updates_extensions/src/ExtensionUpdater.php b/automatic_updates_extensions/src/ExtensionUpdater.php index 8468f7bc6d..99031f8b30 100644 --- a/automatic_updates_extensions/src/ExtensionUpdater.php +++ b/automatic_updates_extensions/src/ExtensionUpdater.php @@ -5,24 +5,12 @@ declare(strict_types = 1); namespace Drupal\automatic_updates_extensions; use Drupal\automatic_updates\Exception\UpdateException; -use Drupal\Component\Datetime\TimeInterface; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\Exception\ApplyFailedException; -use Drupal\package_manager\FailureMarker; use Drupal\package_manager\LegacyVersionUtility; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\StageValidationException; -use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; -use Drupal\package_manager\UnusedConfigFactory; -use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; -use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; -use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; -use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates for modules and themes. @@ -33,15 +21,6 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; */ class ExtensionUpdater extends Stage { - /** - * {@inheritdoc} - * - * @todo Remove this in https://www.drupal.org/i/3303167 - */ - public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { - parent::__construct(new UnusedConfigFactory(), $path_locator, $beginner, $stager, $committer, $file_system, $event_dispatcher, $temp_store_factory, $time, $path_factory, $failure_marker); - } - /** * Begins the update. * diff --git a/automatic_updates_extensions/src/Form/UpdateReady.php b/automatic_updates_extensions/src/Form/UpdateReady.php index 2fb4e99f74..587514e45a 100644 --- a/automatic_updates_extensions/src/Form/UpdateReady.php +++ b/automatic_updates_extensions/src/Form/UpdateReady.php @@ -120,7 +120,7 @@ final class UpdateReady extends UpdateFormBase { try { $this->updater->claim($stage_id); } - catch (StageOwnershipException $e) { + catch (StageOwnershipException) { $this->messenger()->addError($this->t('Cannot continue the update because another Composer operation is currently in progress.')); return $form; } diff --git a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php index fcc0b6d08f..56b168d79f 100644 --- a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php +++ b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\automatic_updates_extensions\Kernel; use Drupal\automatic_updates\Exception\UpdateException; use Drupal\automatic_updates_extensions\ExtensionUpdater; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\package_manager\UnusedConfigFactory; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; use Drupal\Tests\package_manager\Kernel\TestStageTrait; use Drupal\Tests\package_manager\Kernel\TestStageValidationException; @@ -112,8 +111,6 @@ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdates */ protected function createExtensionUpdater(): TestExtensionUpdater { return new TestExtensionUpdater( - // @todo Remove this in https://www.drupal.org/i/3303167 - new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/package_manager.services.yml b/package_manager/package_manager.services.yml index cf43ca76a2..f82eebc342 100644 --- a/package_manager/package_manager.services.yml +++ b/package_manager/package_manager.services.yml @@ -14,12 +14,12 @@ services: public: false Drupal\package_manager\ExecutableFinder: arguments: - $config_factory: '@config.factory' + $configFactory: '@config.factory' autowire: true public: false Drupal\package_manager\FileSyncerFactory: arguments: - $config_factory: '@config.factory' + $configFactory: '@config.factory' autowire: true public: false PhpTuf\ComposerStager\Infrastructure\Service\Finder\ExecutableFinderInterface: @@ -70,7 +70,6 @@ services: arguments: - '@PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface' - '@module_handler' - - '@string_translation' - '@PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface' - '@PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface' tags: @@ -79,7 +78,6 @@ services: class: Drupal\package_manager\Validator\DiskSpaceValidator arguments: - '@package_manager.path_locator' - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.pending_updates: @@ -87,7 +85,6 @@ services: arguments: - '%app.root%' - '@update.post_update_registry' - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.lock_file: @@ -95,20 +92,17 @@ services: arguments: - '@state' - '@package_manager.path_locator' - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.file_system: class: Drupal\package_manager\Validator\WritableFileSystemValidator arguments: - '@package_manager.path_locator' - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.composer_settings: class: Drupal\package_manager\Validator\ComposerSettingsValidator arguments: - - '@string_translation' - '@package_manager.composer_inspector' - '@package_manager.path_locator' tags: @@ -124,7 +118,6 @@ services: class: Drupal\package_manager\Validator\MultisiteValidator arguments: - '@package_manager.path_locator' - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.symlink: @@ -160,7 +153,6 @@ services: class: Drupal\package_manager\Validator\ComposerJsonExistsValidator arguments: - '@package_manager.path_locator' - - '@string_translation' tags: - { name: event_subscriber } package_manager.test_site_excluder: @@ -179,7 +171,7 @@ services: class: Drupal\package_manager\PathExcluder\SiteFilesExcluder arguments: $path_locator: '@package_manager.path_locator' - $stream_wrapper_manager: '@stream_wrapper_manager' + $streamWrapperManager: '@stream_wrapper_manager' tags: - { name: event_subscriber } autowire: true @@ -226,8 +218,6 @@ services: lazy: true package_manager.validator.settings: class: Drupal\package_manager\Validator\SettingsValidator - arguments: - - '@string_translation' tags: - { name: event_subscriber } package_manager.validator.composer_plugins: diff --git a/package_manager/src/ComposerInspector.php b/package_manager/src/ComposerInspector.php index 2c41504880..a41c14083e 100644 --- a/package_manager/src/ComposerInspector.php +++ b/package_manager/src/ComposerInspector.php @@ -18,13 +18,6 @@ use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface; */ final class ComposerInspector { - /** - * The Composer runner service from Composer Stager. - * - * @var \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface - */ - protected ComposerRunnerInterface $runner; - /** * The JSON process output callback. * @@ -38,8 +31,7 @@ final class ComposerInspector { * @param \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface $runner * The Composer runner service from Composer Stager. */ - public function __construct(ComposerRunnerInterface $runner) { - $this->runner = $runner; + public function __construct(private ComposerRunnerInterface $runner) { $this->jsonCallback = new JsonProcessOutputCallback(); } diff --git a/package_manager/src/ComposerUtility.php b/package_manager/src/ComposerUtility.php index 7fa924c39e..d85ab5ecb5 100644 --- a/package_manager/src/ComposerUtility.php +++ b/package_manager/src/ComposerUtility.php @@ -334,7 +334,7 @@ class ComposerUtility { try { $version_parser->parseConstraints($version); } - catch (\UnexpectedValueException $e) { + catch (\UnexpectedValueException) { return FALSE; } diff --git a/package_manager/src/Event/ExcludedPathsTrait.php b/package_manager/src/Event/ExcludedPathsTrait.php index d7ffc408b0..8e850b0af3 100644 --- a/package_manager/src/Event/ExcludedPathsTrait.php +++ b/package_manager/src/Event/ExcludedPathsTrait.php @@ -16,30 +16,6 @@ trait ExcludedPathsTrait { */ protected $excludedPaths = []; - /** - * Adds a path to exclude from the current operation. - * - * If called on an instance of \Drupal\package_manager\Event\PreCreateEvent, - * excluded paths will not be copied into the stage directory when the stage - * is created. If called on an instance of - * \Drupal\package_manager\Event\PreApplyEvent, excluded paths will not be - * deleted from the active directory when staged changes are applied. So, - * to ensure that a given path is never staged, but also preserved in the - * active directory, it should be passed to this method on both PreCreateEvent - * and PreApplyEvent. See - * \Drupal\package_manager\EventSubscriber\ExcludedPathsSubscriber for an - * example. - * - * @param string $path - * The path to exclude, relative to the project root. - * - * @see \Drupal\package_manager\PathExcluder\SiteConfigurationExcluder - */ - public function excludePath(string $path): void { - @trigger_error(__METHOD__ . '() is deprecated in automatic_updates:8.x-2.5 and removed in automatic_updates:3.0.0. Use ' . CollectIgnoredPathsEvent::class . ' instead. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $this->excludedPaths[] = $path; - } - /** * Returns the paths to exclude from the current operation. * diff --git a/package_manager/src/Event/PreApplyEvent.php b/package_manager/src/Event/PreApplyEvent.php index 7260ea56ea..1c616f3f16 100644 --- a/package_manager/src/Event/PreApplyEvent.php +++ b/package_manager/src/Event/PreApplyEvent.php @@ -19,13 +19,12 @@ class PreApplyEvent extends PreOperationStageEvent { * @param \Drupal\package_manager\Stage $stage * The stage which fired this event. * @param string[] $ignored_paths - * The list of ignored paths. + * The list of ignored paths. These will not be copied from the stage + * directory to the active directory, nor be deleted from the active + * directory if they exist, when the stage directory is copied back into + * the active directory. */ - public function __construct(Stage $stage, array $ignored_paths = NULL) { - if ($ignored_paths === NULL) { - @trigger_error('Calling ' . __METHOD__ . '() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $ignored_paths = []; - } + public function __construct(Stage $stage, array $ignored_paths) { parent::__construct($stage); $this->excludedPaths = $ignored_paths; } diff --git a/package_manager/src/Event/PreCreateEvent.php b/package_manager/src/Event/PreCreateEvent.php index 59113b0e6d..9957606fe7 100644 --- a/package_manager/src/Event/PreCreateEvent.php +++ b/package_manager/src/Event/PreCreateEvent.php @@ -19,13 +19,10 @@ class PreCreateEvent extends PreOperationStageEvent { * @param \Drupal\package_manager\Stage $stage * The stage which fired this event. * @param string[] $ignored_paths - * The list of ignored paths. + * The list of ignored paths. These will not be copied into the stage + * directory when it is created. */ - public function __construct(Stage $stage, array $ignored_paths = NULL) { - if ($ignored_paths === NULL) { - @trigger_error('Calling ' . __METHOD__ . '() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $ignored_paths = []; - } + public function __construct(Stage $stage, array $ignored_paths) { parent::__construct($stage); $this->excludedPaths = $ignored_paths; } diff --git a/package_manager/src/Event/StageEvent.php b/package_manager/src/Event/StageEvent.php index 10c28251b5..5ce5111552 100644 --- a/package_manager/src/Event/StageEvent.php +++ b/package_manager/src/Event/StageEvent.php @@ -12,21 +12,13 @@ use Symfony\Contracts\EventDispatcher\Event; */ abstract class StageEvent extends Event { - /** - * The stage which fired this event. - * - * @var \Drupal\package_manager\Stage - */ - protected $stage; - /** * Constructs a StageEvent object. * * @param \Drupal\package_manager\Stage $stage * The stage which fired this event. */ - public function __construct(Stage $stage) { - $this->stage = $stage; + public function __construct(protected readonly Stage $stage) { } /** diff --git a/package_manager/src/Event/StatusCheckEvent.php b/package_manager/src/Event/StatusCheckEvent.php index b4f3600357..8ad7641648 100644 --- a/package_manager/src/Event/StatusCheckEvent.php +++ b/package_manager/src/Event/StatusCheckEvent.php @@ -26,11 +26,7 @@ class StatusCheckEvent extends PreOperationStageEvent { * @param string[] $ignored_paths * The list of ignored paths. */ - public function __construct(Stage $stage, array $ignored_paths = NULL) { - if ($ignored_paths === NULL) { - @trigger_error('Calling ' . __METHOD__ . '() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $ignored_paths = []; - } + public function __construct(Stage $stage, array $ignored_paths) { parent::__construct($stage); $this->excludedPaths = $ignored_paths; } diff --git a/package_manager/src/EventSubscriber/UpdateDataSubscriber.php b/package_manager/src/EventSubscriber/UpdateDataSubscriber.php index b08bc07d95..918b97a5cb 100644 --- a/package_manager/src/EventSubscriber/UpdateDataSubscriber.php +++ b/package_manager/src/EventSubscriber/UpdateDataSubscriber.php @@ -19,20 +19,12 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; final class UpdateDataSubscriber implements EventSubscriberInterface { /** - * The update manager service. + * Constructs an UpdateDataSubscriber object. * - * @var \Drupal\update\UpdateManagerInterface - */ - protected $updateManager; - - /** - * Constructs an UpdateRefreshSubscriber object. - * - * @param \Drupal\update\UpdateManagerInterface $update_manager + * @param \Drupal\update\UpdateManagerInterface $updateManager * The update manager service. */ - public function __construct(UpdateManagerInterface $update_manager) { - $this->updateManager = $update_manager; + public function __construct(protected UpdateManagerInterface $updateManager) { } /** diff --git a/package_manager/src/ExecutableFinder.php b/package_manager/src/ExecutableFinder.php index 0e30826529..d7ec3a7852 100644 --- a/package_manager/src/ExecutableFinder.php +++ b/package_manager/src/ExecutableFinder.php @@ -26,24 +26,16 @@ final class ExecutableFinder implements ExecutableFinderInterface { */ private $decorated; - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - private $configFactory; - /** * Constructs an ExecutableFinder object. * * @param \Symfony\Component\Process\ExecutableFinder $symfony_executable_finder * The Symfony executable finder. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. */ - public function __construct(SymfonyExecutableFinder $symfony_executable_finder, ConfigFactoryInterface $config_factory) { + public function __construct(SymfonyExecutableFinder $symfony_executable_finder, private ConfigFactoryInterface $configFactory) { $this->decorated = new StagerExecutableFinder($symfony_executable_finder); - $this->configFactory = $config_factory; } /** diff --git a/package_manager/src/FailureMarker.php b/package_manager/src/FailureMarker.php index 076bb81043..7447ae0fea 100644 --- a/package_manager/src/FailureMarker.php +++ b/package_manager/src/FailureMarker.php @@ -19,21 +19,13 @@ use Drupal\package_manager\Exception\ApplyFailedException; */ final class FailureMarker { - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a FailureMarker object. * * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(PathLocator $pathLocator) { - $this->pathLocator = $pathLocator; + public function __construct(private PathLocator $pathLocator) { } /** diff --git a/package_manager/src/FileSyncerFactory.php b/package_manager/src/FileSyncerFactory.php index e23fffddc6..aa6c384359 100644 --- a/package_manager/src/FileSyncerFactory.php +++ b/package_manager/src/FileSyncerFactory.php @@ -26,46 +26,27 @@ final class FileSyncerFactory { * * @var \PhpTuf\ComposerStager\Infrastructure\Factory\FileSyncer\FileSyncerFactory */ - protected $decorated; - - /** - * The PHP file syncer service. - * - * @var \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\PhpFileSyncer - */ - protected $phpFileSyncer; - - /** - * The rsync file syncer service. - * - * @var \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\RsyncFileSyncer - */ - protected $rsyncFileSyncer; - - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; + private $decorated; /** * Constructs a FileCopierFactory object. * * @param \Symfony\Component\Process\ExecutableFinder $executable_finder * The Symfony executable finder. - * @param \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\PhpFileSyncer $php_file_syncer + * @param \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\PhpFileSyncer $phpFileSyncer * The PHP file syncer service. - * @param \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\RsyncFileSyncer $rsync_file_syncer + * @param \PhpTuf\ComposerStager\Infrastructure\Service\FileSyncer\RsyncFileSyncer $rsyncFileSyncer * The rsync file syncer service. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. */ - public function __construct(ExecutableFinder $executable_finder, PhpFileSyncer $php_file_syncer, RsyncFileSyncer $rsync_file_syncer, ConfigFactoryInterface $config_factory) { - $this->decorated = new StagerFileSyncerFactory($executable_finder, $php_file_syncer, $rsync_file_syncer); - $this->phpFileSyncer = $php_file_syncer; - $this->rsyncFileSyncer = $rsync_file_syncer; - $this->configFactory = $config_factory; + public function __construct( + ExecutableFinder $executable_finder, + private PhpFileSyncer $phpFileSyncer, + private RsyncFileSyncer $rsyncFileSyncer, + private ConfigFactoryInterface $configFactory, + ) { + $this->decorated = new StagerFileSyncerFactory($executable_finder, $phpFileSyncer, $rsyncFileSyncer); } /** diff --git a/package_manager/src/PackageManagerUninstallValidator.php b/package_manager/src/PackageManagerUninstallValidator.php index 4c9f74acef..e0a754684f 100644 --- a/package_manager/src/PackageManagerUninstallValidator.php +++ b/package_manager/src/PackageManagerUninstallValidator.php @@ -28,8 +28,6 @@ final class PackageManagerUninstallValidator implements ModuleUninstallValidator */ public function validate($module) { $stage = new Stage( - // @todo Remove this in https://www.drupal.org/i/3303167 - new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/src/Path.php b/package_manager/src/Path.php deleted file mode 100644 index b019f3bffd..0000000000 --- a/package_manager/src/Path.php +++ /dev/null @@ -1,820 +0,0 @@ -<?php -// phpcs:ignoreFile -// cspell:disable - -/** - * \Symfony\Component\Filesystem\Path::canonicalize() is only available in Symfony >=5, which Drupal 10 requires, but not Drupal 9. - * @internal - * @todo Remove this in https://www.drupal.org/i/3321474. - */ - -namespace Drupal\package_manager; - -/** - * Contains utility methods for handling path strings. - * - * The methods in this class are able to deal with both UNIX and Windows paths - * with both forward and backward slashes. All methods return normalized parts - * containing only forward slashes and no excess "." and ".." segments. - * - * @author Bernhard Schussek <bschussek@gmail.com> - * @author Thomas Schulz <mail@king2500.net> - * @author Théo Fidry <theo.fidry@gmail.com> - */ -final class Path { - /** - * The number of buffer entries that triggers a cleanup operation. - */ - private const CLEANUP_THRESHOLD = 1250; - - /** - * The buffer size after the cleanup operation. - */ - private const CLEANUP_SIZE = 1000; - - /** - * Buffers input/output of {@link canonicalize()}. - * - * @var array<string, string> - */ - private static $buffer = []; - - /** - * @var int - */ - private static $bufferSize = 0; - - /** - * Canonicalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Furthermore, all "." and ".." segments are removed as far as possible. - * ".." segments at the beginning of relative paths are not removed. - * - * ```php - * echo Path::canonicalize("\symfony\puli\..\css\style.css"); - * // => /symfony/css/style.css - * - * echo Path::canonicalize("../css/./style.css"); - * // => ../css/style.css - * ``` - * - * This method is able to deal with both UNIX and Windows paths. - */ - public static function canonicalize(string $path): string { - if ('' === $path) { - return ''; - } - - // This method is called by many other methods in this class. Buffer - // the canonicalized paths to make up for the severe performance - // decrease. - if (isset(self::$buffer[$path])) { - return self::$buffer[$path]; - } - - // Replace "~" with user's home directory. - if ('~' === $path[0]) { - $path = self::getHomeDirectory() . mb_substr($path, 1); - } - - $path = self::normalize($path); - - [$root, $pathWithoutRoot] = self::split($path); - - $canonicalParts = self::findCanonicalParts($root, $pathWithoutRoot); - - // Add the root directory again. - self::$buffer[$path] = $canonicalPath = $root . implode('/', $canonicalParts); - ++self::$bufferSize; - - // Clean up regularly to prevent memory leaks. - if (self::$bufferSize > self::CLEANUP_THRESHOLD) { - self::$buffer = \array_slice(self::$buffer, -self::CLEANUP_SIZE, NULL, TRUE); - self::$bufferSize = self::CLEANUP_SIZE; - } - - return $canonicalPath; - } - - /** - * Normalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Contrary to {@link canonicalize()}, this method does not remove invalid - * or dot path segments. Consequently, it is much more efficient and should - * be used whenever the given path is known to be a valid, absolute system - * path. - * - * This method is able to deal with both UNIX and Windows paths. - */ - public static function normalize(string $path): string { - return str_replace('\\', '/', $path); - } - - /** - * Returns the directory part of the path. - * - * This method is similar to PHP's dirname(), but handles various cases - * where dirname() returns a weird result: - * - * - dirname() does not accept backslashes on UNIX - * - dirname("C:/symfony") returns "C:", not "C:/" - * - dirname("C:/") returns ".", not "C:/" - * - dirname("C:") returns ".", not "C:/" - * - dirname("symfony") returns ".", not "" - * - dirname() does not canonicalize the result - * - * This method fixes these shortcomings and behaves like dirname() - * otherwise. - * - * The result is a canonical path. - * - * @return string The canonical directory part. Returns the root directory - * if the root directory is passed. Returns an empty string - * if a relative path is passed that contains no slashes. - * Returns an empty string if an empty string is passed. - */ - public static function getDirectory(string $path): string { - if ('' === $path) { - return ''; - } - - $path = self::canonicalize($path); - - // Maintain scheme. - if (FALSE !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) { - $scheme = mb_substr($path, 0, $schemeSeparatorPosition + 3); - $path = mb_substr($path, $schemeSeparatorPosition + 3); - } - else { - $scheme = ''; - } - - if (FALSE === ($dirSeparatorPosition = strrpos($path, '/'))) { - return ''; - } - - // Directory equals root directory "/". - if (0 === $dirSeparatorPosition) { - return $scheme . '/'; - } - - // Directory equals Windows root "C:/". - if (2 === $dirSeparatorPosition && ctype_alpha($path[0]) && ':' === $path[1]) { - return $scheme . mb_substr($path, 0, 3); - } - - return $scheme . mb_substr($path, 0, $dirSeparatorPosition); - } - - /** - * Returns canonical path of the user's home directory. - * - * Supported operating systems: - * - * - UNIX - * - Windows8 and upper - * - * If your operation system or environment isn't supported, an exception is thrown. - * - * The result is a canonical path. - * - * @throws \RuntimeException If your operation system or environment isn't supported - */ - public static function getHomeDirectory(): string { - // For UNIX support. - if (getenv('HOME')) { - return self::canonicalize(getenv('HOME')); - } - - // For >= Windows8 support. - if (getenv('HOMEDRIVE') && getenv('HOMEPATH')) { - return self::canonicalize(getenv('HOMEDRIVE') . getenv('HOMEPATH')); - } - - throw new \RuntimeException("Cannot find the home directory path: Your environment or operation system isn't supported."); - } - - /** - * Returns the root directory of a path. - * - * The result is a canonical path. - * - * @return string The canonical root directory. Returns an empty string if - * the given path is relative or empty. - */ - public static function getRoot(string $path): string { - if ('' === $path) { - return ''; - } - - // Maintain scheme. - if (FALSE !== ($schemeSeparatorPosition = strpos($path, '://'))) { - $scheme = substr($path, 0, $schemeSeparatorPosition + 3); - $path = substr($path, $schemeSeparatorPosition + 3); - } - else { - $scheme = ''; - } - - $firstCharacter = $path[0]; - - // UNIX root "/" or "\" (Windows style) - if ('/' === $firstCharacter || '\\' === $firstCharacter) { - return $scheme . '/'; - } - - $length = mb_strlen($path); - - // Windows root. - if ($length > 1 && ':' === $path[1] && ctype_alpha($firstCharacter)) { - // Special case: "C:". - if (2 === $length) { - return $scheme . $path . '/'; - } - - // Normal case: "C:/ or "C:\". - if ('/' === $path[2] || '\\' === $path[2]) { - return $scheme . $firstCharacter . $path[1] . '/'; - } - } - - return ''; - } - - /** - * Returns the file name without the extension from a file path. - * - * @param string|null $extension - * if specified, only that extension is cut - * off (may contain leading dot) - */ - public static function getFilenameWithoutExtension(string $path, string $extension = NULL) { - if ('' === $path) { - return ''; - } - - if (NULL !== $extension) { - // Remove extension and trailing dot. - return rtrim(basename($path, $extension), '.'); - } - - return pathinfo($path, \PATHINFO_FILENAME); - } - - /** - * Returns the extension from a file path (without leading dot). - * - * @param bool $forceLowerCase - * forces the extension to be lower-case. - */ - public static function getExtension(string $path, bool $forceLowerCase = FALSE): string { - if ('' === $path) { - return ''; - } - - $extension = pathinfo($path, \PATHINFO_EXTENSION); - - if ($forceLowerCase) { - $extension = self::toLower($extension); - } - - return $extension; - } - - /** - * Returns whether the path has an (or the specified) extension. - * - * @param string $path - * the path string. - * @param string|string[]|null $extensions - * if null or not provided, checks if - * an extension exists, otherwise - * checks for the specified extension - * or array of extensions (with or - * without leading dot) - * @param bool $ignoreCase - * whether to ignore case-sensitivity. - */ - public static function hasExtension(string $path, $extensions = NULL, bool $ignoreCase = FALSE): bool { - if ('' === $path) { - return FALSE; - } - - $actualExtension = self::getExtension($path, $ignoreCase); - - // Only check if path has any extension. - if ([] === $extensions || NULL === $extensions) { - return '' !== $actualExtension; - } - - if (\is_string($extensions)) { - $extensions = [$extensions]; - } - - foreach ($extensions as $key => $extension) { - if ($ignoreCase) { - $extension = self::toLower($extension); - } - - // Remove leading '.' in extensions array. - $extensions[$key] = ltrim($extension, '.'); - } - - return \in_array($actualExtension, $extensions, TRUE); - } - - /** - * Changes the extension of a path string. - * - * @param string $path - * The path string with filename.ext to change. - * @param string $extension - * new extension (with or without leading dot) - * - * @return string the path string with new file extension - */ - public static function changeExtension(string $path, string $extension): string { - if ('' === $path) { - return ''; - } - - $actualExtension = self::getExtension($path); - $extension = ltrim($extension, '.'); - - // No extension for paths. - if ('/' === mb_substr($path, -1)) { - return $path; - } - - // No actual extension in path. - if (empty($actualExtension)) { - return $path . ('.' === mb_substr($path, -1) ? '' : '.') . $extension; - } - - return mb_substr($path, 0, -mb_strlen($actualExtension)) . $extension; - } - - /** - * - */ - public static function isAbsolute(string $path): bool { - if ('' === $path) { - return FALSE; - } - - // Strip scheme. - if (FALSE !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) { - $path = mb_substr($path, $schemeSeparatorPosition + 3); - } - - $firstCharacter = $path[0]; - - // UNIX root "/" or "\" (Windows style) - if ('/' === $firstCharacter || '\\' === $firstCharacter) { - return TRUE; - } - - // Windows root. - if (mb_strlen($path) > 1 && ctype_alpha($firstCharacter) && ':' === $path[1]) { - // Special case: "C:". - if (2 === mb_strlen($path)) { - return TRUE; - } - - // Normal case: "C:/ or "C:\". - if ('/' === $path[2] || '\\' === $path[2]) { - return TRUE; - } - } - - return FALSE; - } - - /** - * - */ - public static function isRelative(string $path): bool { - return !self::isAbsolute($path); - } - - /** - * Turns a relative path into an absolute path in canonical form. - * - * Usually, the relative path is appended to the given base path. Dot - * segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * echo Path::makeAbsolute("../style.css", "/symfony/puli/css"); - * // => /symfony/puli/style.css - * ``` - * - * If an absolute path is passed, that path is returned unless its root - * directory is different than the one of the base path. In that case, an - * exception is thrown. - * - * ```php - * Path::makeAbsolute("/style.css", "/symfony/puli/css"); - * // => /style.css - * - * Path::makeAbsolute("C:/style.css", "C:/symfony/puli/css"); - * // => C:/style.css - * - * Path::makeAbsolute("C:/style.css", "/symfony/puli/css"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @param string $basePath - * an absolute base path. - * - * @throws \InvalidArgumentException if the base path is not absolute or if - * the given path is an absolute path with - * a different root than the base path - */ - public static function makeAbsolute(string $path, string $basePath): string { - if ('' === $basePath) { - throw new \InvalidArgumentException(sprintf('The base path must be a non-empty string. Got: "%s".', $basePath)); - } - - if (!self::isAbsolute($basePath)) { - throw new \InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath)); - } - - if (self::isAbsolute($path)) { - return self::canonicalize($path); - } - - if (FALSE !== ($schemeSeparatorPosition = mb_strpos($basePath, '://'))) { - $scheme = mb_substr($basePath, 0, $schemeSeparatorPosition + 3); - $basePath = mb_substr($basePath, $schemeSeparatorPosition + 3); - } - else { - $scheme = ''; - } - - return $scheme . self::canonicalize(rtrim($basePath, '/\\') . '/' . $path); - } - - /** - * Turns a path into a relative path. - * - * The relative path is created relative to the given base path: - * - * ```php - * echo Path::makeRelative("/symfony/style.css", "/symfony/puli"); - * // => ../style.css - * ``` - * - * If a relative path is passed and the base path is absolute, the relative - * path is returned unchanged: - * - * ```php - * Path::makeRelative("style.css", "/symfony/puli/css"); - * // => style.css - * ``` - * - * If both paths are relative, the relative path is created with the - * assumption that both paths are relative to the same directory: - * - * ```php - * Path::makeRelative("style.css", "symfony/puli/css"); - * // => ../../../style.css - * ``` - * - * If both paths are absolute, their root directory must be the same, - * otherwise an exception is thrown: - * - * ```php - * Path::makeRelative("C:/symfony/style.css", "/symfony/puli"); - * // InvalidArgumentException - * ``` - * - * If the passed path is absolute, but the base path is not, an exception - * is thrown as well: - * - * ```php - * Path::makeRelative("/symfony/style.css", "symfony/puli"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @throws \InvalidArgumentException if the base path is not absolute or if - * the given path has a different root - * than the base path - */ - public static function makeRelative(string $path, string $basePath): string { - $path = self::canonicalize($path); - $basePath = self::canonicalize($basePath); - - [$root, $relativePath] = self::split($path); - [$baseRoot, $relativeBasePath] = self::split($basePath); - - // If the base path is given as absolute path and the path is already - // relative, consider it to be relative to the given absolute path - // already. - if ('' === $root && '' !== $baseRoot) { - // If base path is already in its root. - if ('' === $relativeBasePath) { - $relativePath = ltrim($relativePath, './\\'); - } - - return $relativePath; - } - - // If the passed path is absolute, but the base path is not, we - // cannot generate a relative path. - if ('' !== $root && '' === $baseRoot) { - throw new \InvalidArgumentException(sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath)); - } - - // Fail if the roots of the two paths are different. - if ($baseRoot && $root !== $baseRoot) { - throw new \InvalidArgumentException(sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot)); - } - - if ('' === $relativeBasePath) { - return $relativePath; - } - - // Build a "../../" prefix with as many "../" parts as necessary. - $parts = explode('/', $relativePath); - $baseParts = explode('/', $relativeBasePath); - $dotDotPrefix = ''; - - // Once we found a non-matching part in the prefix, we need to add - // "../" parts for all remaining parts. - $match = TRUE; - - foreach ($baseParts as $index => $basePart) { - if ($match && isset($parts[$index]) && $basePart === $parts[$index]) { - unset($parts[$index]); - - continue; - } - - $match = FALSE; - $dotDotPrefix .= '../'; - } - - return rtrim($dotDotPrefix . implode('/', $parts), '/'); - } - - /** - * Returns whether the given path is on the local filesystem. - */ - public static function isLocal(string $path): bool { - return '' !== $path && FALSE === mb_strpos($path, '://'); - } - - /** - * Returns the longest common base path in canonical form of a set of paths or - * `null` if the paths are on different Windows partitions. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * $basePath = Path::getLongestCommonBasePath([ - * '/symfony/css/style.css', - * '/symfony/css/..' - * ]); - * // => /symfony - * ``` - * - * The root is returned if no common base path can be found: - * - * ```php - * $basePath = Path::getLongestCommonBasePath([ - * '/symfony/css/style.css', - * '/puli/css/..' - * ]); - * // => / - * ``` - * - * If the paths are located on different Windows partitions, `null` is - * returned. - * - * ```php - * $basePath = Path::getLongestCommonBasePath([ - * 'C:/symfony/css/style.css', - * 'D:/symfony/css/..' - * ]); - * // => null - * ``` - */ - public static function getLongestCommonBasePath(string ...$paths): ?string { - [$bpRoot, $basePath] = self::split(self::canonicalize(reset($paths))); - - for (next($paths); NULL !== key($paths) && '' !== $basePath; next($paths)) { - [$root, $path] = self::split(self::canonicalize(current($paths))); - - // If we deal with different roots (e.g. C:/ vs. D:/), it's time - // to quit. - if ($root !== $bpRoot) { - return NULL; - } - - // Make the base path shorter until it fits into path. - while (TRUE) { - if ('.' === $basePath) { - // No more base paths. - $basePath = ''; - - // Next path. - continue 2; - } - - // Prevent false positives for common prefixes - // see isBasePath() - if (0 === mb_strpos($path . '/', $basePath . '/')) { - // Next path. - continue 2; - } - - $basePath = \dirname($basePath); - } - } - - return $bpRoot . $basePath; - } - - /** - * Joins two or more path strings into a canonical path. - */ - public static function join(string ...$paths): string { - $finalPath = NULL; - $wasScheme = FALSE; - - foreach ($paths as $path) { - if ('' === $path) { - continue; - } - - if (NULL === $finalPath) { - // For first part we keep slashes, like '/top', 'C:\' or 'phar://'. - $finalPath = $path; - $wasScheme = (FALSE !== mb_strpos($path, '://')); - continue; - } - - // Only add slash if previous part didn't end with '/' or '\'. - if (!\in_array(mb_substr($finalPath, -1), ['/', '\\'])) { - $finalPath .= '/'; - } - - // If first part included a scheme like 'phar://' we allow \current part to start with '/', otherwise trim. - $finalPath .= $wasScheme ? $path : ltrim($path, '/'); - $wasScheme = FALSE; - } - - if (NULL === $finalPath) { - return ''; - } - - return self::canonicalize($finalPath); - } - - /** - * Returns whether a path is a base path of another path. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * Path::isBasePath('/symfony', '/symfony/css'); - * // => true - * - * Path::isBasePath('/symfony', '/symfony'); - * // => true - * - * Path::isBasePath('/symfony', '/symfony/..'); - * // => false - * - * Path::isBasePath('/symfony', '/puli'); - * // => false - * ``` - */ - public static function isBasePath(string $basePath, string $ofPath): bool { - $basePath = self::canonicalize($basePath); - $ofPath = self::canonicalize($ofPath); - - // Append slashes to prevent false positives when two paths have - // a common prefix, for example /base/foo and /base/foobar. - // Don't append a slash for the root "/", because then that root - // won't be discovered as common prefix ("//" is not a prefix of - // "/foobar/"). - return 0 === mb_strpos($ofPath . '/', rtrim($basePath, '/') . '/'); - } - - /** - * @return nonemptystring[] - */ - private static function findCanonicalParts(string $root, string $pathWithoutRoot): array { - $parts = explode('/', $pathWithoutRoot); - - $canonicalParts = []; - - // Collapse "." and "..", if possible. - foreach ($parts as $part) { - if ('.' === $part || '' === $part) { - continue; - } - - // Collapse ".." with the previous part, if one exists - // Don't collapse ".." if the previous part is also "..". - if ('..' === $part && \count($canonicalParts) > 0 && '..' !== $canonicalParts[\count($canonicalParts) - 1]) { - array_pop($canonicalParts); - - continue; - } - - // Only add ".." prefixes for relative paths. - if ('..' !== $part || '' === $root) { - $canonicalParts[] = $part; - } - } - - return $canonicalParts; - } - - /** - * Splits a canonical path into its root directory and the remainder. - * - * If the path has no root directory, an empty root directory will be - * returned. - * - * If the root directory is a Windows style partition, the resulting root - * will always contain a trailing slash. - * - * list ($root, $path) = Path::split("C:/symfony") - * // => ["C:/", "symfony"] - * - * list ($root, $path) = Path::split("C:") - * // => ["C:/", ""] - * - * @return array{string, string} an array with the root directory and the remaining relative path - */ - private static function split(string $path): array { - if ('' === $path) { - return ['', '']; - } - - // Remember scheme as part of the root, if any. - if (FALSE !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) { - $root = mb_substr($path, 0, $schemeSeparatorPosition + 3); - $path = mb_substr($path, $schemeSeparatorPosition + 3); - } - else { - $root = ''; - } - - $length = mb_strlen($path); - - // Remove and remember root directory. - if (0 === mb_strpos($path, '/')) { - $root .= '/'; - $path = $length > 1 ? mb_substr($path, 1) : ''; - } - elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) { - if (2 === $length) { - // Windows special case: "C:". - $root .= $path . '/'; - $path = ''; - } - elseif ('/' === $path[2]) { - // Windows normal case: "C:/".. - $root .= mb_substr($path, 0, 3); - $path = $length > 3 ? mb_substr($path, 3) : ''; - } - } - - return [$root, $path]; - } - - /** - * - */ - private static function toLower(string $string): string { - if (FALSE !== $encoding = mb_detect_encoding($string)) { - return mb_strtolower($string, $encoding); - } - - return strtolower($string, $encoding); - } - - /** - * - */ - private function __construct() { - } - -} diff --git a/package_manager/src/PathExcluder/GitExcluder.php b/package_manager/src/PathExcluder/GitExcluder.php index f19c6e4870..807d780659 100644 --- a/package_manager/src/PathExcluder/GitExcluder.php +++ b/package_manager/src/PathExcluder/GitExcluder.php @@ -22,24 +22,16 @@ final class GitExcluder implements EventSubscriberInterface { use PathExclusionsTrait; - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - protected $fileSystem; - /** * Constructs a GitExcluder object. * * @param \Drupal\package_manager\PathLocator $path_locator * The path locator service. - * @param \Drupal\Core\File\FileSystemInterface $file_system + * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system service. */ - public function __construct(PathLocator $path_locator, FileSystemInterface $file_system) { + public function __construct(PathLocator $path_locator, protected FileSystemInterface $fileSystem) { $this->pathLocator = $path_locator; - $this->fileSystem = $file_system; } /** diff --git a/package_manager/src/PathExcluder/PathExclusionsTrait.php b/package_manager/src/PathExcluder/PathExclusionsTrait.php index 001b6cb978..f64729f351 100644 --- a/package_manager/src/PathExcluder/PathExclusionsTrait.php +++ b/package_manager/src/PathExcluder/PathExclusionsTrait.php @@ -5,7 +5,6 @@ declare(strict_types = 1); namespace Drupal\package_manager\PathExcluder; use Drupal\package_manager\Event\CollectIgnoredPathsEvent; -use Drupal\package_manager\Event\StageEvent; /** * Contains methods for excluding paths from stage operations. @@ -31,7 +30,7 @@ trait PathExclusionsTrait { * The paths to exclude. These should be relative to the web root, and will * be made relative to the project root. */ - protected function excludeInWebRoot(StageEvent $event, array $paths): void { + protected function excludeInWebRoot(CollectIgnoredPathsEvent $event, array $paths): void { $web_root = $this->pathLocator->getWebRoot(); if ($web_root) { $web_root .= '/'; @@ -39,15 +38,7 @@ trait PathExclusionsTrait { foreach ($paths as $path) { // Make the path relative to the project root by prefixing the web root. - $path = $web_root . $path; - - if ($event instanceof CollectIgnoredPathsEvent) { - $event->add([$path]); - } - else { - @trigger_error('Passing ' . get_class($event) . ' to ' . __METHOD__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $event->excludePath($web_root . $path); - } + $event->add([$web_root . $path]); } } @@ -61,7 +52,7 @@ trait PathExclusionsTrait { * root; relative paths will be assumed to already be relative to the * project root, and excluded as given. */ - protected function excludeInProjectRoot(StageEvent $event, array $paths): void { + protected function excludeInProjectRoot(CollectIgnoredPathsEvent $event, array $paths): void { $project_root = $this->pathLocator->getProjectRoot(); foreach ($paths as $path) { @@ -74,14 +65,7 @@ trait PathExclusionsTrait { // Make absolute paths relative to the project root. $path = str_replace($project_root, '', $path); $path = ltrim($path, '/'); - - if ($event instanceof CollectIgnoredPathsEvent) { - $event->add([$path]); - } - else { - @trigger_error('Passing ' . get_class($event) . ' to ' . __METHOD__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.', E_USER_DEPRECATED); - $event->excludePath($path); - } + $event->add([$path]); } } diff --git a/package_manager/src/PathExcluder/SiteConfigurationExcluder.php b/package_manager/src/PathExcluder/SiteConfigurationExcluder.php index 23e848a7da..cae826d567 100644 --- a/package_manager/src/PathExcluder/SiteConfigurationExcluder.php +++ b/package_manager/src/PathExcluder/SiteConfigurationExcluder.php @@ -20,23 +20,15 @@ class SiteConfigurationExcluder implements EventSubscriberInterface { use PathExclusionsTrait; - /** - * The current site path, relative to the Drupal root. - * - * @var string - */ - protected $sitePath; - /** * Constructs an ExcludedPathsSubscriber. * - * @param string $site_path + * @param string $sitePath * The current site path, relative to the Drupal root. * @param \Drupal\package_manager\PathLocator $path_locator * The path locator service. */ - public function __construct(string $site_path, PathLocator $path_locator) { - $this->sitePath = $site_path; + public function __construct(protected string $sitePath, PathLocator $path_locator) { $this->pathLocator = $path_locator; } diff --git a/package_manager/src/PathExcluder/SiteFilesExcluder.php b/package_manager/src/PathExcluder/SiteFilesExcluder.php index 41be60c32d..dea85eed53 100644 --- a/package_manager/src/PathExcluder/SiteFilesExcluder.php +++ b/package_manager/src/PathExcluder/SiteFilesExcluder.php @@ -23,34 +23,18 @@ final class SiteFilesExcluder implements EventSubscriberInterface { use PathExclusionsTrait; - /** - * The stream wrapper manager service. - * - * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface - */ - protected $streamWrapperManager; - - /** - * The Symfony file system service. - * - * @var \Symfony\Component\Filesystem\Filesystem - */ - protected $fileSystem; - /** * Constructs a SiteFilesExcluder object. * * @param \Drupal\package_manager\PathLocator $path_locator * The path locator service. - * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager + * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $streamWrapperManager * The stream wrapper manager service. - * @param \Symfony\Component\Filesystem\Filesystem $file_system + * @param \Symfony\Component\Filesystem\Filesystem $fileSystem * The Symfony file system service. */ - public function __construct(PathLocator $path_locator, StreamWrapperManagerInterface $stream_wrapper_manager, Filesystem $file_system) { + public function __construct(PathLocator $path_locator, protected StreamWrapperManagerInterface $streamWrapperManager, protected Filesystem $fileSystem) { $this->pathLocator = $path_locator; - $this->streamWrapperManager = $stream_wrapper_manager; - $this->fileSystem = $file_system; } /** diff --git a/package_manager/src/PathExcluder/SqliteDatabaseExcluder.php b/package_manager/src/PathExcluder/SqliteDatabaseExcluder.php index 275b6a8efa..9afa102fa3 100644 --- a/package_manager/src/PathExcluder/SqliteDatabaseExcluder.php +++ b/package_manager/src/PathExcluder/SqliteDatabaseExcluder.php @@ -21,13 +21,6 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface { use PathExclusionsTrait; - /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $database; - /** * Constructs a SqliteDatabaseExcluder object. * @@ -36,9 +29,8 @@ class SqliteDatabaseExcluder implements EventSubscriberInterface { * @param \Drupal\Core\Database\Connection $database * The database connection. */ - public function __construct(PathLocator $path_locator, Connection $database) { + public function __construct(PathLocator $path_locator, protected Connection $database) { $this->pathLocator = $path_locator; - $this->database = $database; } /** diff --git a/package_manager/src/PathLocator.php b/package_manager/src/PathLocator.php index 20d2b8ee90..9b73513e2a 100644 --- a/package_manager/src/PathLocator.php +++ b/package_manager/src/PathLocator.php @@ -13,50 +13,21 @@ use Drupal\Core\File\FileSystemInterface; */ class PathLocator { - /** - * The absolute path of the running Drupal code base. - * - * @var string - */ - protected $appRoot; - - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - protected $fileSystem; - /** * Constructs a PathLocator object. * - * @param string $app_root + * @param string $appRoot * The absolute path of the running Drupal code base. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. - * @param \Drupal\Core\File\FileSystemInterface $file_system + * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system service. */ - public function __construct(string $app_root, ConfigFactoryInterface $config_factory = NULL, FileSystemInterface $file_system = NULL) { - $this->appRoot = $app_root; - if (empty($config_factory)) { - @trigger_error('Calling ' . __METHOD__ . '() without the $config_factory argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED); - $config_factory = \Drupal::configFactory(); - } - $this->configFactory = $config_factory; - if (empty($file_system)) { - @trigger_error('Calling ' . __METHOD__ . '() without the $file_system argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED); - $file_system = \Drupal::service('file_system'); - } - $this->fileSystem = $file_system; - } + public function __construct( + protected string $appRoot, + protected ConfigFactoryInterface $configFactory, + protected FileSystemInterface $fileSystem, + ) {} /** * Returns the absolute path of the project root. diff --git a/package_manager/src/ProcessFactory.php b/package_manager/src/ProcessFactory.php index cd6fda76b5..a52244d70f 100644 --- a/package_manager/src/ProcessFactory.php +++ b/package_manager/src/ProcessFactory.php @@ -29,32 +29,16 @@ final class ProcessFactory implements ProcessFactoryInterface { */ private $decorated; - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - private $fileSystem; - - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - private $configFactory; - /** * Constructs a ProcessFactory object. * - * @param \Drupal\Core\File\FileSystemInterface $file_system + * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system service. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. */ - public function __construct(FileSystemInterface $file_system, ConfigFactoryInterface $config_factory) { + public function __construct(private FileSystemInterface $fileSystem, private ConfigFactoryInterface $configFactory) { $this->decorated = new StagerProcessFactory(); - $this->fileSystem = $file_system; - $this->configFactory = $config_factory; } /** diff --git a/package_manager/src/ProjectInfo.php b/package_manager/src/ProjectInfo.php index f47a1013e5..fc267c5e8e 100644 --- a/package_manager/src/ProjectInfo.php +++ b/package_manager/src/ProjectInfo.php @@ -21,21 +21,13 @@ use Drupal\update\UpdateManagerInterface; */ final class ProjectInfo { - /** - * The project name. - * - * @var string - */ - protected $name; - /** * Constructs a ProjectInfo object. * * @param string $name * The project name. */ - public function __construct(string $name) { - $this->name = $name; + public function __construct(protected string $name) { } /** diff --git a/package_manager/src/Stage.php b/package_manager/src/Stage.php index 13f3488b2e..966008f2b1 100644 --- a/package_manager/src/Stage.php +++ b/package_manager/src/Stage.php @@ -6,7 +6,6 @@ namespace Drupal\package_manager; use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Utility\Crypt; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -32,7 +31,6 @@ use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; -use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactory; use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; use PhpTuf\ComposerStager\Infrastructure\Value\PathList\PathList; use Psr\Log\LoggerAwareInterface; @@ -74,14 +72,14 @@ class Stage implements LoggerAwareInterface { * * @var string */ - protected const TEMPSTORE_LOCK_KEY = 'lock'; + final protected const TEMPSTORE_LOCK_KEY = 'lock'; /** * The tempstore key under which to store arbitrary metadata for this stage. * * @var string */ - protected const TEMPSTORE_METADATA_KEY = 'metadata'; + final protected const TEMPSTORE_METADATA_KEY = 'metadata'; /** * The tempstore key under which to store the path of stage root directory. @@ -122,83 +120,6 @@ class Stage implements LoggerAwareInterface { */ private const TEMPSTORE_DESTROYED_STAGES_INFO_PREFIX = 'TEMPSTORE_DESTROYED_STAGES_INFO'; - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - - /** - * The beginner service. - * - * @var \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface - */ - protected $beginner; - - /** - * The stager service. - * - * @var \PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface - */ - protected $stager; - - /** - * The committer service. - * - * @var \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface - */ - protected $committer; - - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - protected $fileSystem; - - /** - * The event dispatcher service. - * - * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * The shared temp store factory. - * - * @var \Drupal\Core\TempStore\SharedTempStoreFactory - */ - protected $tempStoreFactory; - - /** - * The shared temp store. - * - * @var \Drupal\Core\TempStore\SharedTempStore - */ - protected $tempStore; - - /** - * The time service. - * - * @var \Drupal\Component\Datetime\TimeInterface - */ - protected $time; - - /** - * The path factory service. - * - * @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface - */ - protected $pathFactory; - /** * The lock info for the stage. * @@ -208,19 +129,10 @@ class Stage implements LoggerAwareInterface { */ private $lock; - /** - * The failure marker service. - * - * @var \Drupal\package_manager\FailureMarker - */ - protected $failureMarker; - /** * Constructs a new Stage object. * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory service. - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. * @param \PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface $beginner * The beginner service. @@ -228,55 +140,33 @@ class Stage implements LoggerAwareInterface { * The stager service. * @param \PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface $committer * The committer service. - * @param \Drupal\Core\File\FileSystemInterface $file_system + * @param \Drupal\Core\File\FileSystemInterface $fileSystem * The file system service. - * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher + * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher * The event dispatcher service. - * @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory + * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempStoreFactory * The shared tempstore factory. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. - * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory * The path factory service. - * @param \Drupal\package_manager\FailureMarker $failure_marker + * @param \Drupal\package_manager\FailureMarker $failureMarker * The failure marker service. */ - public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { - $this->configFactory = $config_factory; - $this->pathLocator = $path_locator; - $this->beginner = $beginner; - $this->stager = $stager; - $this->committer = $committer; - $this->fileSystem = $file_system; - $this->eventDispatcher = $event_dispatcher; - $this->time = $time; - $this->tempStoreFactory = $temp_store_factory; - $this->tempStore = $temp_store_factory->get('package_manager_stage'); - if (!$config_factory instanceof UnusedConfigFactory) { - // @todo Remove this in https://www.drupal.org/i/3303167 - @trigger_error('Calling ' . __METHOD__ . '() with the $config_factory argument is deprecated in automatic_updates:8.x-2.6 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3325718.', E_USER_DEPRECATED); - } - if (empty($path_factory)) { - @trigger_error('Calling ' . __METHOD__ . '() without the $path_factory argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3310706.', E_USER_DEPRECATED); - $path_factory = new PathFactory(); - } - $this->pathFactory = $path_factory; - if (empty($failure_marker)) { - @trigger_error('Calling ' . __METHOD__ . '() without the $failure_marker argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3311257.', E_USER_DEPRECATED); - $failure_marker = \Drupal::service('package_manager.failure_marker'); - } - $this->failureMarker = $failure_marker; + public function __construct( + protected PathLocator $pathLocator, + protected BeginnerInterface $beginner, + protected StagerInterface $stager, + protected CommitterInterface $committer, + protected FileSystemInterface $fileSystem, + protected EventDispatcherInterface $eventDispatcher, + protected SharedTempStoreFactory $tempStoreFactory, + protected TimeInterface $time, + protected PathFactoryInterface $pathFactory, + protected FailureMarker $failureMarker, + ) { + $this->tempStore = $tempStoreFactory->get('package_manager_stage'); $this->setLogger(new NullLogger()); - if (self::TEMPSTORE_METADATA_KEY !== static::TEMPSTORE_METADATA_KEY) { - @trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_METADATA_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED); - \Drupal::logger('package_manager') - ->error(__CLASS__ . '::TEMPSTORE_METADATA_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.'); - } - if (self::TEMPSTORE_LOCK_KEY !== static::TEMPSTORE_LOCK_KEY) { - @trigger_error('Overriding ' . __CLASS__ . '::TEMPSTORE_LOCK_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.', E_USER_DEPRECATED); - \Drupal::logger('package_manager') - ->error(__CLASS__ . '::TEMPSTORE_LOCK_KEY is overridden by ' . static::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.'); - } } /** @@ -583,7 +473,7 @@ class Stage implements LoggerAwareInterface { $this->fileSystem->chmod($path, 0777); }); } - catch (FileException $e) { + catch (FileException) { // Deliberately swallow the exception so that the stage will be marked // as available and the post-destroy event will be fired, even if the // stage directory can't actually be deleted. The file system service diff --git a/package_manager/src/StatusCheckTrait.php b/package_manager/src/StatusCheckTrait.php index 07fe3d8f93..94f25d6754 100644 --- a/package_manager/src/StatusCheckTrait.php +++ b/package_manager/src/StatusCheckTrait.php @@ -4,7 +4,6 @@ declare(strict_types = 1); namespace Drupal\package_manager; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\StatusCheckEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -26,15 +25,12 @@ trait StatusCheckTrait { * The stage to run the status check for. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * (optional) The event dispatcher service. - * @param bool $do_readiness_check - * (optional) Whether to also Rerun readiness checks for the stage - * (deprecated). Defaults to FALSE. * * @return \Drupal\package_manager\ValidationResult[] * The results of the status check. If a readiness check was also done, * its results will be included. */ - protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array { + protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL): array { $event_dispatcher ??= \Drupal::service('event_dispatcher'); try { $ignored_paths = new CollectIgnoredPathsEvent($stage); @@ -47,14 +43,7 @@ trait StatusCheckTrait { $event = new StatusCheckEvent($stage, $ignored_paths->getAll()); $event_dispatcher->dispatch($event); - $results = $event->getResults(); - - if ($do_readiness_check && class_exists(ReadinessCheckEvent::class) && $event_dispatcher->hasListeners(ReadinessCheckEvent::class)) { - $event = new ReadinessCheckEvent($stage); - $event_dispatcher->dispatch($event); - $results = array_merge($results, $event->getResults()); - } - return $results; + return $event->getResults(); } } diff --git a/package_manager/src/UnusedConfigFactory.php b/package_manager/src/UnusedConfigFactory.php deleted file mode 100644 index 1493bdc0f0..0000000000 --- a/package_manager/src/UnusedConfigFactory.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\package_manager; - -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Config\ConfigFactoryOverrideInterface; - -/** - * Dummy Class. - * - * @internal - * - * @todo Remove this in https://www.drupal.org/i/3303167 - */ -final class UnusedConfigFactory implements ConfigFactoryInterface { - - /** - * {@inheritdoc} - */ - public function get($name) { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function getEditable($name) { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function loadMultiple(array $names) { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function reset($name = NULL) { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function rename($old_name, $new_name) { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function getCacheKeys() { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function clearStaticCache() { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function listAll($prefix = '') { - throw new \LogicException(); - } - - /** - * {@inheritdoc} - */ - public function addOverride(ConfigFactoryOverrideInterface $config_factory_override) { - throw new \LogicException(); - } - -} diff --git a/package_manager/src/ValidationResult.php b/package_manager/src/ValidationResult.php index 0d3a110793..d6e2a16b63 100644 --- a/package_manager/src/ValidationResult.php +++ b/package_manager/src/ValidationResult.php @@ -12,27 +12,6 @@ use Drupal\system\SystemManager; */ final class ValidationResult { - /** - * A succinct summary of the results. - * - * @var \Drupal\Core\StringTranslation\TranslatableMarkup - */ - protected $summary; - - /** - * The error messages. - * - * @var \Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] - */ - protected $messages; - - /** - * The severity of the result. - * - * @var int - */ - protected $severity; - /** * Creates a ValidationResult object. * @@ -44,16 +23,13 @@ final class ValidationResult { * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary * The errors summary. */ - private function __construct(int $severity, array $messages, ?TranslatableMarkup $summary = NULL) { + private function __construct(protected int $severity, protected array $messages, protected ?TranslatableMarkup $summary = NULL) { if (empty($messages)) { throw new \InvalidArgumentException('At least one message is required.'); } if (count($messages) > 1 && !$summary) { throw new \InvalidArgumentException('If more than one message is provided, a summary is required.'); } - $this->summary = $summary; - $this->messages = $messages; - $this->severity = $severity; } /** diff --git a/package_manager/src/Validator/ComposerExecutableValidator.php b/package_manager/src/Validator/ComposerExecutableValidator.php index a89cd8705f..9156c2d414 100644 --- a/package_manager/src/Validator/ComposerExecutableValidator.php +++ b/package_manager/src/Validator/ComposerExecutableValidator.php @@ -11,7 +11,6 @@ use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\StatusCheckEvent; use PhpTuf\ComposerStager\Domain\Exception\ExceptionInterface; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; @@ -40,55 +39,24 @@ class ComposerExecutableValidator implements EventSubscriberInterface { */ public const MINIMUM_COMPOSER_VERSION_CONSTRAINT = '~2.2.12 || ^2.3.5'; - /** - * The Composer runner. - * - * @var \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface - */ - protected $composer; - - /** - * The "Composer is available" precondition service. - * - * @var \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface - */ - protected $composerIsAvailable; - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The path factory service. - * - * @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface - */ - protected $pathFactory; - /** * Constructs a ComposerExecutableValidator object. * * @param \PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface $composer * The Composer runner. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - * @param \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface $composer_is_available + * @param \PhpTuf\ComposerStager\Domain\Service\Precondition\ComposerIsAvailableInterface $composerIsAvailable * The "Composer is available" precondition service. - * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory * The path factory service. */ - public function __construct(ComposerRunnerInterface $composer, ModuleHandlerInterface $module_handler, TranslationInterface $translation, ComposerIsAvailableInterface $composer_is_available, PathFactoryInterface $path_factory) { - $this->composer = $composer; - $this->moduleHandler = $module_handler; - $this->setStringTranslation($translation); - $this->composerIsAvailable = $composer_is_available; - $this->pathFactory = $path_factory; - } + public function __construct( + protected ComposerRunnerInterface $composer, + protected ModuleHandlerInterface $moduleHandler, + protected ComposerIsAvailableInterface $composerIsAvailable, + protected PathFactoryInterface $pathFactory, + ) {} /** * {@inheritdoc} diff --git a/package_manager/src/Validator/ComposerJsonExistsValidator.php b/package_manager/src/Validator/ComposerJsonExistsValidator.php index c10fe88fde..d5fdf9a89f 100644 --- a/package_manager/src/Validator/ComposerJsonExistsValidator.php +++ b/package_manager/src/Validator/ComposerJsonExistsValidator.php @@ -5,7 +5,6 @@ declare(strict_types = 1); namespace Drupal\package_manager\Validator; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\package_manager\Event\PreCreateEvent; @@ -25,24 +24,13 @@ final class ComposerJsonExistsValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a ComposerJsonExistsValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. */ - public function __construct(PathLocator $path_locator, TranslationInterface $translation) { - $this->pathLocator = $path_locator; - $this->setStringTranslation($translation); + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/ComposerMinimumStabilityValidator.php b/package_manager/src/Validator/ComposerMinimumStabilityValidator.php index aad401503d..b5ab5d3da7 100644 --- a/package_manager/src/Validator/ComposerMinimumStabilityValidator.php +++ b/package_manager/src/Validator/ComposerMinimumStabilityValidator.php @@ -24,31 +24,15 @@ final class ComposerMinimumStabilityValidator implements EventSubscriberInterfac use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected PathLocator $pathLocator; - - /** - * The Composer inspector service. - * - * @var \Drupal\package_manager\ComposerInspector - */ - protected ComposerInspector $inspector; - /** * Constructs a ComposerMinimumStabilityValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. * @param \Drupal\package_manager\ComposerInspector $inspector * The Composer inspector service. */ - public function __construct(PathLocator $path_locator, ComposerInspector $inspector) { - $this->pathLocator = $path_locator; - $this->inspector = $inspector; + public function __construct(protected PathLocator $pathLocator, protected ComposerInspector $inspector) { } /** diff --git a/package_manager/src/Validator/ComposerPatchesValidator.php b/package_manager/src/Validator/ComposerPatchesValidator.php index efcbee12b7..2623fbe938 100644 --- a/package_manager/src/Validator/ComposerPatchesValidator.php +++ b/package_manager/src/Validator/ComposerPatchesValidator.php @@ -45,21 +45,13 @@ final class ComposerPatchesValidator implements EventSubscriberInterface { */ private const PLUGIN_NAME = 'cweagans/composer-patches'; - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - private ModuleHandlerInterface $moduleHandler; - /** * Constructs a ComposerPatchesValidator object. * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler service. */ - public function __construct(ModuleHandlerInterface $module_handler) { - $this->moduleHandler = $module_handler; + public function __construct(private ModuleHandlerInterface $moduleHandler) { } /** @@ -77,7 +69,7 @@ final class ComposerPatchesValidator implements EventSubscriberInterface { [$plugin_installed_in_stage, $is_stage_root_requirement, $stage_configuration_ok] = $this->computePatcherStatus($stage->getStageComposer()); $has_staged_update = TRUE; } - catch (\LogicException $e) { + catch (\LogicException) { // No staged update exists. $has_staged_update = FALSE; } diff --git a/package_manager/src/Validator/ComposerPluginsValidator.php b/package_manager/src/Validator/ComposerPluginsValidator.php index c8a99e14e1..13a5772f78 100644 --- a/package_manager/src/Validator/ComposerPluginsValidator.php +++ b/package_manager/src/Validator/ComposerPluginsValidator.php @@ -99,20 +99,6 @@ final class ComposerPluginsValidator implements EventSubscriberInterface { */ protected array $additionalTrustedComposerPlugins; - /** - * The Composer inspector service. - * - * @var \Drupal\package_manager\ComposerInspector - */ - protected ComposerInspector $inspector; - - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected PathLocator $pathLocator; - /** * Constructs a new ComposerPluginsValidator. * @@ -120,17 +106,19 @@ final class ComposerPluginsValidator implements EventSubscriberInterface { * The config factory. * @param \Drupal\package_manager\ComposerInspector $inspector * The Composer inspector service. - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(ConfigFactoryInterface $config_factory, ComposerInspector $inspector, PathLocator $path_locator) { + public function __construct( + ConfigFactoryInterface $config_factory, + protected ComposerInspector $inspector, + protected PathLocator $pathLocator, + ) { $settings = $config_factory->get('package_manager.settings'); $this->additionalTrustedComposerPlugins = array_map( [__CLASS__, 'normalizePackageName'], $settings->get('additional_trusted_composer_plugins') ); - $this->inspector = $inspector; - $this->pathLocator = $path_locator; } /** diff --git a/package_manager/src/Validator/ComposerSettingsValidator.php b/package_manager/src/Validator/ComposerSettingsValidator.php index 87f09566f2..6c934f5244 100644 --- a/package_manager/src/Validator/ComposerSettingsValidator.php +++ b/package_manager/src/Validator/ComposerSettingsValidator.php @@ -5,7 +5,6 @@ declare(strict_types = 1); namespace Drupal\package_manager\Validator; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -26,34 +25,15 @@ final class ComposerSettingsValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The Composer inspector service. - * - * @var \Drupal\package_manager\ComposerInspector - */ - protected ComposerInspector $inspector; - - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected PathLocator $pathLocator; - /** * Constructs a ComposerSettingsValidator object. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. * @param \Drupal\package_manager\ComposerInspector $inspector * The Composer inspector service. - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(TranslationInterface $translation, ComposerInspector $inspector, PathLocator $path_locator) { - $this->setStringTranslation($translation); - $this->inspector = $inspector; - $this->pathLocator = $path_locator; + public function __construct(protected ComposerInspector $inspector, protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/DiskSpaceValidator.php b/package_manager/src/Validator/DiskSpaceValidator.php index 80c35cb8df..a2f36e2a63 100644 --- a/package_manager/src/Validator/DiskSpaceValidator.php +++ b/package_manager/src/Validator/DiskSpaceValidator.php @@ -10,7 +10,6 @@ use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\Component\FileSystem\FileSystem; use Drupal\Component\Utility\Bytes; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -27,24 +26,13 @@ class DiskSpaceValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a DiskSpaceValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. */ - public function __construct(PathLocator $path_locator, TranslationInterface $translation) { - $this->pathLocator = $path_locator; - $this->setStringTranslation($translation); + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/DuplicateInfoFileValidator.php b/package_manager/src/Validator/DuplicateInfoFileValidator.php index 100cbb33e3..a55141943b 100644 --- a/package_manager/src/Validator/DuplicateInfoFileValidator.php +++ b/package_manager/src/Validator/DuplicateInfoFileValidator.php @@ -22,21 +22,13 @@ class DuplicateInfoFileValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a DuplicateInfoFileValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(PathLocator $path_locator) { - $this->pathLocator = $path_locator; + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/EnvironmentSupportValidator.php b/package_manager/src/Validator/EnvironmentSupportValidator.php index d1338bb308..206403a68a 100644 --- a/package_manager/src/Validator/EnvironmentSupportValidator.php +++ b/package_manager/src/Validator/EnvironmentSupportValidator.php @@ -52,7 +52,7 @@ final class EnvironmentSupportValidator implements EventSubscriberInterface { $message = Link::fromTextAndUrl($message, Url::fromUri($help_url)) ->toString(); } - catch (\InvalidArgumentException $e) { + catch (\InvalidArgumentException) { // No need to do anything here. The message just won't be a link. } $event->addError([$message]); diff --git a/package_manager/src/Validator/LockFileValidator.php b/package_manager/src/Validator/LockFileValidator.php index ff723bb58d..61f45ff470 100644 --- a/package_manager/src/Validator/LockFileValidator.php +++ b/package_manager/src/Validator/LockFileValidator.php @@ -6,7 +6,6 @@ namespace Drupal\package_manager\Validator; use Drupal\Core\State\StateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PostDestroyEvent; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -35,34 +34,15 @@ final class LockFileValidator implements EventSubscriberInterface { */ protected const STATE_KEY = 'package_manager.lock_hash'; - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a LockFileValidator object. * * @param \Drupal\Core\State\StateInterface $state * The state service. - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. */ - public function __construct(StateInterface $state, PathLocator $path_locator, TranslationInterface $translation) { - $this->state = $state; - $this->pathLocator = $path_locator; - $this->setStringTranslation($translation); + public function __construct(protected StateInterface $state, protected PathLocator $pathLocator) { } /** @@ -84,7 +64,7 @@ final class LockFileValidator implements EventSubscriberInterface { try { return hash_file('sha256', $file); } - catch (\Throwable $exception) { + catch (\Throwable) { return FALSE; } } diff --git a/package_manager/src/Validator/MultisiteValidator.php b/package_manager/src/Validator/MultisiteValidator.php index 968c2cf59f..614a701b25 100644 --- a/package_manager/src/Validator/MultisiteValidator.php +++ b/package_manager/src/Validator/MultisiteValidator.php @@ -5,7 +5,6 @@ declare(strict_types = 1); namespace Drupal\package_manager\Validator; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; @@ -25,24 +24,13 @@ final class MultisiteValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a new MultisiteValidator. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. */ - public function __construct(PathLocator $path_locator, TranslationInterface $translation) { - $this->pathLocator = $path_locator; - $this->setStringTranslation($translation); + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php index f1ce2d9177..f98bde0a88 100644 --- a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php +++ b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php @@ -39,21 +39,13 @@ final class OverwriteExistingPackagesValidator implements EventSubscriberInterfa use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a OverwriteExistingPackagesValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(PathLocator $path_locator) { - $this->pathLocator = $path_locator; + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/PendingUpdatesValidator.php b/package_manager/src/Validator/PendingUpdatesValidator.php index 507157b9af..86dc2dd6bc 100644 --- a/package_manager/src/Validator/PendingUpdatesValidator.php +++ b/package_manager/src/Validator/PendingUpdatesValidator.php @@ -8,7 +8,6 @@ use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Update\UpdateRegistry; use Drupal\Core\Url; use Drupal\package_manager\Event\StatusCheckEvent; @@ -26,34 +25,15 @@ final class PendingUpdatesValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The Drupal root. - * - * @var string - */ - protected $appRoot; - - /** - * The update registry service. - * - * @var \Drupal\Core\Update\UpdateRegistry - */ - protected $updateRegistry; - /** * Constructs an PendingUpdatesValidator object. * - * @param string $app_root + * @param string $appRoot * The Drupal root. - * @param \Drupal\Core\Update\UpdateRegistry $update_registry + * @param \Drupal\Core\Update\UpdateRegistry $updateRegistry * The update registry service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. */ - public function __construct(string $app_root, UpdateRegistry $update_registry, TranslationInterface $translation) { - $this->appRoot = $app_root; - $this->updateRegistry = $update_registry; - $this->setStringTranslation($translation); + public function __construct(protected string $appRoot, protected UpdateRegistry $updateRegistry) { } /** diff --git a/package_manager/src/Validator/PreOperationStageValidatorInterface.php b/package_manager/src/Validator/PreOperationStageValidatorInterface.php deleted file mode 100644 index d1ea0bd601..0000000000 --- a/package_manager/src/Validator/PreOperationStageValidatorInterface.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\package_manager\Validator; - -@trigger_error(__NAMESPACE__ . '\PreOperationStageValidatorInterface is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED); - -use Drupal\package_manager\Event\PreOperationStageEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * Defines an interface for classes that validate a stage before an operation. - */ -interface PreOperationStageValidatorInterface extends EventSubscriberInterface { - - /** - * Validates a stage before an operation. - * - * @param \Drupal\package_manager\Event\PreOperationStageEvent $event - * The stage event. - */ - public function validateStagePreOperation(PreOperationStageEvent $event): void; - -} diff --git a/package_manager/src/Validator/SettingsValidator.php b/package_manager/src/Validator/SettingsValidator.php index 697b0201fd..e0608f5629 100644 --- a/package_manager/src/Validator/SettingsValidator.php +++ b/package_manager/src/Validator/SettingsValidator.php @@ -6,7 +6,6 @@ namespace Drupal\package_manager\Validator; use Drupal\Core\Site\Settings; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; @@ -25,16 +24,6 @@ final class SettingsValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * Constructs a SettingsValidator object. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. - */ - public function __construct(TranslationInterface $translation) { - $this->setStringTranslation($translation); - } - /** * {@inheritdoc} */ diff --git a/package_manager/src/Validator/StageNotInActiveValidator.php b/package_manager/src/Validator/StageNotInActiveValidator.php index 6ff2f51443..abc602e8fc 100644 --- a/package_manager/src/Validator/StageNotInActiveValidator.php +++ b/package_manager/src/Validator/StageNotInActiveValidator.php @@ -20,23 +20,16 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * class. */ class StageNotInActiveValidator implements EventSubscriberInterface { - use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; + use StringTranslationTrait; /** * Constructs a new StageNotInActiveValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(PathLocator $path_locator) { - $this->pathLocator = $path_locator; + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/src/Validator/StagedDBUpdateValidator.php b/package_manager/src/Validator/StagedDBUpdateValidator.php index 5dadab5188..cc5c023624 100644 --- a/package_manager/src/Validator/StagedDBUpdateValidator.php +++ b/package_manager/src/Validator/StagedDBUpdateValidator.php @@ -24,42 +24,21 @@ class StagedDBUpdateValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - - /** - * The module list service. - * - * @var \Drupal\Core\Extension\ModuleExtensionList - */ - protected $moduleList; - - /** - * The theme list service. - * - * @var \Drupal\Core\Extension\ThemeExtensionList - */ - protected $themeList; - /** * Constructs a StagedDBUpdateValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\Extension\ModuleExtensionList $module_list + * @param \Drupal\Core\Extension\ModuleExtensionList $moduleList * The module list service. - * @param \Drupal\Core\Extension\ThemeExtensionList $theme_list + * @param \Drupal\Core\Extension\ThemeExtensionList $themeList * The theme list service. */ - public function __construct(PathLocator $path_locator, ModuleExtensionList $module_list, ThemeExtensionList $theme_list) { - $this->pathLocator = $path_locator; - $this->moduleList = $module_list; - $this->themeList = $theme_list; - } + public function __construct( + protected PathLocator $pathLocator, + protected ModuleExtensionList $moduleList, + protected ThemeExtensionList $themeList, + ) {} /** * Checks that the staged update does not have changes to its install files. @@ -71,7 +50,7 @@ class StagedDBUpdateValidator implements EventSubscriberInterface { try { $stage_dir = $event->getStage()->getStageDirectory(); } - catch (\LogicException $e) { + catch (\LogicException) { // Stage directory can't be determined, so there's nothing to validate. return; } diff --git a/package_manager/src/Validator/SymlinkValidator.php b/package_manager/src/Validator/SymlinkValidator.php index 8ecad5a87e..9e52a0e3aa 100644 --- a/package_manager/src/Validator/SymlinkValidator.php +++ b/package_manager/src/Validator/SymlinkValidator.php @@ -33,52 +33,24 @@ class SymlinkValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - - /** - * The Composer Stager precondition that this validator wraps. - * - * @var \PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface - */ - protected $precondition; - - /** - * The path factory service. - * - * @var \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface - */ - protected $pathFactory; - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * Constructs a SymlinkValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. * @param \PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface $precondition * The Composer Stager precondition that this validator wraps. - * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $path_factory + * @param \PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface $pathFactory * The path factory service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler service. */ - public function __construct(PathLocator $path_locator, CodebaseContainsNoSymlinksInterface $precondition, PathFactoryInterface $path_factory, ModuleHandlerInterface $module_handler) { - $this->pathLocator = $path_locator; - $this->precondition = $precondition; - $this->pathFactory = $path_factory; - $this->moduleHandler = $module_handler; - } + public function __construct( + protected PathLocator $pathLocator, + protected CodebaseContainsNoSymlinksInterface $precondition, + protected PathFactoryInterface $pathFactory, + protected ModuleHandlerInterface $moduleHandler, + ) {} /** * {@inheritdoc} @@ -94,7 +66,7 @@ class SymlinkValidator implements EventSubscriberInterface { try { $stage_dir = $event->getStage()->getStageDirectory(); } - catch (\LogicException $e) { + catch (\LogicException) { $stage_dir = __DIR__; } $stage_dir = $this->pathFactory->create($stage_dir); diff --git a/package_manager/src/Validator/WritableFileSystemValidator.php b/package_manager/src/Validator/WritableFileSystemValidator.php index 96c7af0259..3b14ccad7b 100644 --- a/package_manager/src/Validator/WritableFileSystemValidator.php +++ b/package_manager/src/Validator/WritableFileSystemValidator.php @@ -4,7 +4,6 @@ declare(strict_types = 1); namespace Drupal\package_manager\Validator; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; @@ -25,24 +24,13 @@ class WritableFileSystemValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a WritableFileSystemValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. */ - public function __construct(PathLocator $path_locator, TranslationInterface $translation) { - $this->pathLocator = $path_locator; - $this->setStringTranslation($translation); + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/package_manager/tests/modules/package_manager_bypass/src/MockPathLocator.php b/package_manager/tests/modules/package_manager_bypass/src/MockPathLocator.php index cc90fd6b39..5a9d1517f2 100644 --- a/package_manager/tests/modules/package_manager_bypass/src/MockPathLocator.php +++ b/package_manager/tests/modules/package_manager_bypass/src/MockPathLocator.php @@ -6,7 +6,7 @@ namespace Drupal\package_manager_bypass; use Drupal\Core\State\StateInterface; use Drupal\package_manager\PathLocator as BasePathLocator; -use Drupal\package_manager\Path; +use Symfony\Component\Filesystem\Path; /** * Mock path locator: allows specifying paths instead of discovering paths. diff --git a/package_manager/tests/modules/package_manager_test_api/src/ApiController.php b/package_manager/tests/modules/package_manager_test_api/src/ApiController.php index 57bec8bf1b..fb2ce00e26 100644 --- a/package_manager/tests/modules/package_manager_test_api/src/ApiController.php +++ b/package_manager/tests/modules/package_manager_test_api/src/ApiController.php @@ -8,7 +8,6 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; -use Drupal\package_manager\UnusedConfigFactory; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -58,8 +57,6 @@ class ApiController extends ControllerBase { */ public static function create(ContainerInterface $container) { $stage = new Stage( - // @todo Remove this in https://www.drupal.org/i/3303167 - new UnusedConfigFactory(), $container->get('package_manager.path_locator'), $container->get('package_manager.beginner'), $container->get('package_manager.stager'), @@ -67,7 +64,9 @@ class ApiController extends ControllerBase { $container->get('file_system'), $container->get('event_dispatcher'), $container->get('tempstore.shared'), - $container->get('datetime.time') + $container->get('datetime.time'), + $container->get('PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface'), + $container->get('package_manager.failure_marker') ); return new static( $stage, diff --git a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php index e277e02eba..6635bf52c6 100644 --- a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php +++ b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php @@ -12,7 +12,6 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\StatusCheckTrait; -use Drupal\package_manager\UnusedConfigFactory; use Drupal\package_manager\Validator\DiskSpaceValidator; use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\Stage; @@ -128,8 +127,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { */ protected function createStage(): TestStage { return new TestStage( - // @todo Remove this in https://www.drupal.org/i/3303167 - new UnusedConfigFactory(), $this->container->get('package_manager.path_locator'), $this->container->get('package_manager.beginner'), $this->container->get('package_manager.stager'), diff --git a/package_manager/tests/src/Kernel/PathExcluder/GitExcluderTest.php b/package_manager/tests/src/Kernel/PathExcluder/GitExcluderTest.php index 4c60627ebf..bd88ba0ac5 100644 --- a/package_manager/tests/src/Kernel/PathExcluder/GitExcluderTest.php +++ b/package_manager/tests/src/Kernel/PathExcluder/GitExcluderTest.php @@ -57,7 +57,7 @@ class GitExcluderTest extends PackageManagerKernelTestBase { $this->fileSystem = $this->prophesize(FileSystemInterface::class); $container->getDefinition('package_manager.git_excluder') - ->setArgument('$file_system', $this->fileSystem->reveal()); + ->setArgument('$fileSystem', $this->fileSystem->reveal()); } /** diff --git a/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php b/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php index 6d6ae88214..84be9bf664 100644 --- a/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php +++ b/package_manager/tests/src/Kernel/PathExcluder/SiteConfigurationExcluderTest.php @@ -101,6 +101,6 @@ class TestSiteConfigurationExcluder extends SiteConfigurationExcluder { /** * {@inheritdoc} */ - public $sitePath; + public string $sitePath; } diff --git a/package_manager/tests/src/Kernel/PathExcluder/SqliteDatabaseExcluderTest.php b/package_manager/tests/src/Kernel/PathExcluder/SqliteDatabaseExcluderTest.php index ab29e39c9b..29446c815e 100644 --- a/package_manager/tests/src/Kernel/PathExcluder/SqliteDatabaseExcluderTest.php +++ b/package_manager/tests/src/Kernel/PathExcluder/SqliteDatabaseExcluderTest.php @@ -182,6 +182,6 @@ class TestSqliteDatabaseExcluder extends SqliteDatabaseExcluder { /** * {@inheritdoc} */ - public $database; + public Connection $database; } diff --git a/package_manager/tests/src/Kernel/StageEventsTest.php b/package_manager/tests/src/Kernel/StageEventsTest.php index 21abdab105..ec26fee40c 100644 --- a/package_manager/tests/src/Kernel/StageEventsTest.php +++ b/package_manager/tests/src/Kernel/StageEventsTest.php @@ -5,8 +5,6 @@ declare(strict_types = 1); namespace Drupal\Tests\package_manager\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\package_manager\Event\CollectIgnoredPathsEvent; -use Drupal\package_manager\Event\ExcludedPathsTrait; use Drupal\package_manager\Event\PostApplyEvent; use Drupal\package_manager\Event\PostCreateEvent; use Drupal\package_manager\Event\PostDestroyEvent; @@ -17,7 +15,6 @@ use Drupal\package_manager\Event\PreDestroyEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Event\StageEvent; -use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\ValidationResult; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -176,24 +173,6 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc $this->stage->require(['drupal/core:9.8.2'], ['drupal/core-dev:9.8.2']); } - /** - * @group legacy - */ - public function testDeprecations(): void { - $stage = $this->createStage(); - $this->expectDeprecation('Calling ' . StatusCheckEvent::class . '::__construct() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.'); - $this->expectDeprecation(ExcludedPathsTrait::class . '::excludePath() is deprecated in automatic_updates:8.x-2.5 and removed in automatic_updates:3.0.0. Use ' . CollectIgnoredPathsEvent::class . ' instead. See https://www.drupal.org/node/3317862.'); - (new StatusCheckEvent($stage))->excludePath('/junk/drawer'); - - $this->expectDeprecation('Calling ' . PreCreateEvent::class . '::__construct() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.'); - $this->expectDeprecation(ExcludedPathsTrait::class . '::excludePath() is deprecated in automatic_updates:8.x-2.5 and removed in automatic_updates:3.0.0. Use ' . CollectIgnoredPathsEvent::class . ' instead. See https://www.drupal.org/node/3317862.'); - (new PreCreateEvent($stage))->excludePath('/junk/drawer'); - - $this->expectDeprecation('Calling ' . PreApplyEvent::class . '::__construct() without the $ignored_paths argument is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3317862.'); - $this->expectDeprecation(ExcludedPathsTrait::class . '::excludePath() is deprecated in automatic_updates:8.x-2.5 and removed in automatic_updates:3.0.0. Use ' . CollectIgnoredPathsEvent::class . ' instead. See https://www.drupal.org/node/3317862.'); - (new PreApplyEvent($stage))->excludePath('/junk/drawer'); - } - /** * Tests exception is thrown if error is not added before stopPropagation(). */ diff --git a/package_manager/tests/src/Kernel/StageTest.php b/package_manager/tests/src/Kernel/StageTest.php index e68d564783..0264834b9a 100644 --- a/package_manager/tests/src/Kernel/StageTest.php +++ b/package_manager/tests/src/Kernel/StageTest.php @@ -8,7 +8,6 @@ use Drupal\Component\Datetime\Time; use Drupal\Component\FileSystem\FileSystem; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Extension\ModuleUninstallValidatorException; -use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\package_manager\Event\CollectIgnoredPathsEvent; use Drupal\package_manager\Event\PostApplyEvent; @@ -17,7 +16,6 @@ use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageException; -use Drupal\package_manager\Stage; use Drupal\package_manager_bypass\LoggingCommitter; use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; @@ -509,37 +507,6 @@ class StageTest extends PackageManagerKernelTestBase { $stage->claim($stage_id); } - /** - * Tests enforcing that certain services must be passed to the constructor. - * - * @group legacy - */ - public function testConstructorDeprecations(): void { - $logger = new TestLogger(); - $this->container->get('logger.factory') - ->get('package_manager') - ->addLogger($logger); - - $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() with the $config_factory argument is deprecated in automatic_updates:8.x-2.6 and will be removed in automatic_updates:3.0.0. See https://www.drupal.org/node/3325718.'); - $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() without the $path_factory argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3310706.'); - $this->expectDeprecation('Calling Drupal\package_manager\Stage::__construct() without the $failure_marker argument is deprecated in automatic_updates:8.x-2.3 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3311257.'); - $this->expectDeprecation('Overriding Drupal\package_manager\Stage::TEMPSTORE_METADATA_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.'); - $this->expectDeprecation('Overriding Drupal\package_manager\Stage::TEMPSTORE_LOCK_KEY is deprecated in automatic_updates:8.x-2.5 and will not be possible in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3317450.'); - new TestStageOverriddenConstants( - $this->container->get('config.factory'), - $this->container->get('package_manager.path_locator'), - $this->container->get('package_manager.beginner'), - $this->container->get('package_manager.stager'), - $this->container->get('package_manager.committer'), - $this->container->get('file_system'), - $this->container->get('event_dispatcher'), - $this->container->get('tempstore.shared'), - $this->container->get('datetime.time') - ); - $this->assertTrue($logger->hasRecord('Drupal\package_manager\Stage::TEMPSTORE_METADATA_KEY is overridden by ' . TestStageOverriddenConstants::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.', (string) RfcLogLevel::ERROR)); - $this->assertTrue($logger->hasRecord('Drupal\package_manager\Stage::TEMPSTORE_LOCK_KEY is overridden by ' . TestStageOverriddenConstants::class . '. This is deprecated because it can cause errors or other unexpected behavior. It is strongly recommended to stop overriding this constant. See https://www.drupal.org/node/3317450 for more information.', (string) RfcLogLevel::ERROR)); - } - /** * Tests running apply and post-apply in the same request. */ @@ -682,17 +649,3 @@ class TestTime extends Time { } } - -class TestStageOverriddenConstants extends Stage { - - /** - * {@inheritdoc} - */ - protected const TEMPSTORE_LOCK_KEY = 'overridden_lock'; - - /** - * {@inheritdoc} - */ - protected const TEMPSTORE_METADATA_KEY = 'overridden_metadata'; - -} diff --git a/package_manager/tests/src/Unit/PathLocatorTest.php b/package_manager/tests/src/Unit/PathLocatorTest.php index 4f4bc6ff92..0cafee88e0 100644 --- a/package_manager/tests/src/Unit/PathLocatorTest.php +++ b/package_manager/tests/src/Unit/PathLocatorTest.php @@ -4,7 +4,6 @@ declare(strict_types = 1); namespace Drupal\Tests\package_manager\Unit; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\File\FileSystemInterface; use Drupal\package_manager\PathLocator; use Drupal\Tests\UnitTestCase; @@ -121,22 +120,4 @@ class PathLocatorTest extends UnitTestCase { $this->assertSame($expected_web_root, $path_locator->getWebRoot()); } - /** - * Tests that deprecations are raised for missing constructor arguments. - * - * @group legacy - */ - public function testConstructorDeprecations(): void { - $container = new ContainerBuilder(); - $container->set('config.factory', $this->getConfigFactoryStub()); - $container->set('file_system', $this->createMock(FileSystemInterface::class)); - \Drupal::setContainer($container); - - $this->expectDeprecation('Calling ' . PathLocator::class . '::__construct() without the $config_factory argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.'); - new PathLocator('/path/to/drupal', NULL, $container->get('file_system')); - - $this->expectDeprecation('Calling ' . PathLocator::class . '::__construct() without the $file_system argument is deprecated in automatic_updates:8.x-2.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.'); - new PathLocator('/path/to/drupal', $container->get('config.factory')); - } - } diff --git a/package_manager/tests/src/Unit/StageNotInActiveValidatorTest.php b/package_manager/tests/src/Unit/StageNotInActiveValidatorTest.php index a96e16986e..219d3f5907 100644 --- a/package_manager/tests/src/Unit/StageNotInActiveValidatorTest.php +++ b/package_manager/tests/src/Unit/StageNotInActiveValidatorTest.php @@ -5,13 +5,13 @@ declare(strict_types = 1); namespace Drupal\Tests\package_manager\Unit; use Drupal\package_manager\Event\PreCreateEvent; -use Drupal\package_manager\Path; use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; use Drupal\package_manager\ValidationResult; use Drupal\package_manager\Validator\StageNotInActiveValidator; use Drupal\Tests\package_manager\Traits\ValidationTestTrait; use Drupal\Tests\UnitTestCase; +use Symfony\Component\Filesystem\Path; /** * @coversDefaultClass \Drupal\package_manager\Validator\StageNotInActiveValidator diff --git a/src/Controller/StatusCheckController.php b/src/Controller/StatusCheckController.php index 2d6953b882..1a0c693ca9 100644 --- a/src/Controller/StatusCheckController.php +++ b/src/Controller/StatusCheckController.php @@ -7,12 +7,9 @@ namespace Drupal\automatic_updates\Controller; use Drupal\automatic_updates\Validation\ValidationResultDisplayTrait; use Drupal\automatic_updates\Validation\StatusChecker; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\Core\Url; use Drupal\system\SystemManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; /** * A controller for running status checks. @@ -24,24 +21,13 @@ final class StatusCheckController extends ControllerBase { use ValidationResultDisplayTrait; - /** - * The status checker service. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - protected $statusChecker; - /** * Constructs a StatusCheckController object. * - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker + * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker * The status checker service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation service. */ - public function __construct(StatusChecker $status_checker, TranslationInterface $string_translation) { - $this->statusChecker = $status_checker; - $this->setStringTranslation($string_translation); + public function __construct(protected StatusChecker $statusChecker) { } /** @@ -49,37 +35,10 @@ final class StatusCheckController extends ControllerBase { */ public static function create(ContainerInterface $container): self { return new static( - $container->get('automatic_updates.status_checker'), - $container->get('string_translation'), + $container->get('automatic_updates.status_checker') ); } - /** - * Redirects deprecated readiness check route. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - * A redirect response. - */ - public function runReadiness(Request $request): RedirectResponse { - $destination = Url::fromRoute('automatic_updates.status_check') - ->setAbsolute() - ->toString(); - - $message = $this->t('This page was accessed from @deprecated_url, which is deprecated and will not work in the next major version of Automatic Updates. Please use <a href=":correct_url">@correct_url</a> instead.', [ - '@deprecated_url' => $request->getUri(), - ':correct_url' => $destination, - '@correct_url' => $destination, - ]); - $this->messenger()->addStatus($message); - - // 308 is a permanent redirect regardless of HTTP method. - // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections - return new RedirectResponse($destination, 308); - } - /** * Run the status checks. * diff --git a/src/Controller/UpdateController.php b/src/Controller/UpdateController.php index 0afd669e91..bf8029dd98 100644 --- a/src/Controller/UpdateController.php +++ b/src/Controller/UpdateController.php @@ -9,7 +9,6 @@ use Drupal\automatic_updates\Validation\StatusChecker; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\State\StateInterface; use Drupal\Core\Url; use Drupal\package_manager\Validator\PendingUpdatesValidator; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,45 +23,21 @@ use Symfony\Component\HttpFoundation\Request; */ final class UpdateController extends ControllerBase { - /** - * The pending updates validator. - * - * @var \Drupal\package_manager\Validator\PendingUpdatesValidator - */ - protected $pendingUpdatesValidator; - - /** - * The current route match. - * - * @var \Drupal\Core\Routing\RouteMatchInterface - */ - protected $routeMatch; - - /** - * The status checker. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - protected $statusChecker; - /** * Constructs an UpdateController object. * - * @param \Drupal\package_manager\Validator\PendingUpdatesValidator $pending_updates_validator + * @param \Drupal\package_manager\Validator\PendingUpdatesValidator $pendingUpdatesValidator * The pending updates validator. - * @param \Drupal\Core\State\StateInterface $state - * The state service. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch * The current route match. - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker + * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker * The status checker service. */ - public function __construct(PendingUpdatesValidator $pending_updates_validator, StateInterface $state, RouteMatchInterface $route_match, StatusChecker $status_checker) { - $this->pendingUpdatesValidator = $pending_updates_validator; - $this->stateService = $state; - $this->routeMatch = $route_match; - $this->statusChecker = $status_checker; - } + public function __construct( + protected PendingUpdatesValidator $pendingUpdatesValidator, + protected RouteMatchInterface $routeMatch, + protected StatusChecker $statusChecker, + ) {} /** * {@inheritdoc} @@ -70,7 +45,6 @@ final class UpdateController extends ControllerBase { public static function create(ContainerInterface $container) { return new static( $container->get('package_manager.validator.pending_updates'), - $container->get('state'), $container->get('current_route_match'), $container->get('automatic_updates.status_checker') ); @@ -119,48 +93,4 @@ final class UpdateController extends ControllerBase { return new RedirectResponse($url->setAbsolute()->toString()); } - /** - * Redirects deprecated routes and sets an informative message. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - * A redirect response. - */ - public function redirectDeprecatedRoute(Request $request): RedirectResponse { - $route_name = $this->routeMatch->getRouteName(); - - switch ($route_name) { - case 'automatic_updates.module_update': - $destination = 'update.module_update'; - break; - - case 'automatic_updates.theme_update': - $destination = 'update.theme_update'; - break; - - case 'automatic_updates.report_update': - $destination = 'update.report_update'; - break; - - default: - throw new \InvalidArgumentException("Unknown route: '$route_name'"); - } - $destination = Url::fromRoute($destination) - ->setAbsolute() - ->toString(); - - $message = $this->t('This page was accessed from @deprecated_url, which is deprecated and will not work in the next major version of Automatic Updates. Please use <a href=":correct_url">@correct_url</a> instead.', [ - '@deprecated_url' => $request->getUri(), - ':correct_url' => $destination, - '@correct_url' => $destination, - ]); - $this->messenger()->addStatus($message); - - // 308 is a permanent redirect regardless of HTTP method. - // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections - return new RedirectResponse($destination, 308); - } - } diff --git a/src/CronUpdater.php b/src/CronUpdater.php index 3627019e3c..2612bb8418 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -4,14 +4,13 @@ declare(strict_types = 1); namespace Drupal\automatic_updates; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Mail\MailManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Url; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\ProjectInfo; -use Drupal\package_manager\UnusedConfigFactory; use Drupal\update\ProjectRelease; use GuzzleHttp\Psr7\Uri as GuzzleUri; use Symfony\Component\HttpFoundation\Response; @@ -48,61 +47,31 @@ class CronUpdater extends Updater { */ public const ALL = 'patch'; - /** - * The cron release chooser service. - * - * @var \Drupal\automatic_updates\ReleaseChooser - */ - protected $releaseChooser; - - /** - * The mail manager service. - * - * @var \Drupal\Core\Mail\MailManagerInterface - */ - protected $mailManager; - - /** - * The status check mailer service. - * - * @var \Drupal\automatic_updates\StatusCheckMailer - */ - protected $statusCheckMailer; - - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - /** * Constructs a CronUpdater object. * - * @param \Drupal\automatic_updates\ReleaseChooser $release_chooser + * @param \Drupal\automatic_updates\ReleaseChooser $releaseChooser * The cron release chooser service. - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory - * The logger channel factory. - * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager + * @param \Drupal\Core\Mail\MailManagerInterface $mailManager * The mail manager service. - * @param \Drupal\automatic_updates\StatusCheckMailer $status_check_mailer + * @param \Drupal\automatic_updates\StatusCheckMailer $statusCheckMailer * The status check mailer service. * @param \Drupal\Core\State\StateInterface $state * The state service. + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory + * The config factory service. * @param mixed ...$arguments * Additional arguments to pass to the parent constructor. */ - public function __construct(ReleaseChooser $release_chooser, LoggerChannelFactoryInterface $logger_factory, MailManagerInterface $mail_manager, StatusCheckMailer $status_check_mailer, StateInterface $state, ...$arguments) { - $config_factory = $arguments[0]; - $arguments[0] = new UnusedConfigFactory(); + public function __construct( + protected ReleaseChooser $releaseChooser, + protected MailManagerInterface $mailManager, + protected StatusCheckMailer $statusCheckMailer, + protected StateInterface $state, + protected ConfigFactoryInterface $configFactory, + mixed ...$arguments, + ) { parent::__construct(...$arguments); - // @todo Remove this in https://www.drupal.org/i/3303167 - $this->configFactory = $config_factory; - $this->releaseChooser = $release_chooser; - $this->logger = $logger_factory->get('automatic_updates'); - $this->mailManager = $mail_manager; - $this->statusCheckMailer = $status_check_mailer; - $this->state = $state; } /** diff --git a/src/Event/ReadinessCheckEvent.php b/src/Event/ReadinessCheckEvent.php deleted file mode 100644 index f68647fc53..0000000000 --- a/src/Event/ReadinessCheckEvent.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\automatic_updates\Event; - -use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\package_manager\Event\PreOperationStageEvent; -use Drupal\package_manager\Stage; -use Drupal\package_manager\ValidationResult; - -/** - * Event fired when checking if the site could perform an update. - * - * An update is not actually being started when this event is being fired. It - * should be used to notify site admins if the site is in a state which will - * not allow automatic updates to succeed. - * - * This event should only be dispatched from ReadinessValidationManager to - * allow caching of the results. - * - * @see \Drupal\automatic_updates\Validation\ReadinessValidationManager - */ -class ReadinessCheckEvent extends PreOperationStageEvent { - - /** - * The desired package versions to update to, keyed by package name. - * - * @var string[] - */ - protected $packageVersions; - - /** - * Constructs a ReadinessCheckEvent object. - * - * @param \Drupal\package_manager\Stage $stage - * The stage service. - * @param string[] $project_versions - * (optional) The versions of the packages to update to, keyed by package - * name. - */ - public function __construct(Stage $stage, array $project_versions = []) { - @trigger_error(__CLASS__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED); - parent::__construct($stage); - if ($project_versions) { - if (count($project_versions) !== 1 || !array_key_exists('drupal', $project_versions)) { - throw new \InvalidArgumentException("Currently only updates to Drupal core are supported."); - } - $core_packages = array_keys($this->getStage()->getActiveComposer()->getCorePackages()); - // Update all core packages to the same version. - $package_versions = array_fill(0, count($core_packages), $project_versions['drupal']); - $this->packageVersions = array_combine($core_packages, $package_versions); - } - else { - $this->packageVersions = []; - } - } - - /** - * Returns the desired package versions to update to. - * - * @return string[] - * The desired package versions to update to, keyed by package name. - */ - public function getPackageVersions(): array { - return $this->packageVersions; - } - - /** - * Adds warning information to the event. - * - * @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $messages - * The warning messages. - * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary - * (optional) The summary of warning messages. Required if there is more - * than one message. - */ - public function addWarning(array $messages, ?TranslatableMarkup $summary = NULL): void { - $this->results[] = ValidationResult::createWarning($messages, $summary); - } - -} diff --git a/src/EventSubscriber/ConfigSubscriber.php b/src/EventSubscriber/ConfigSubscriber.php index 911ace7d13..733d4026f3 100644 --- a/src/EventSubscriber/ConfigSubscriber.php +++ b/src/EventSubscriber/ConfigSubscriber.php @@ -24,21 +24,14 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ final class ConfigSubscriber implements EventSubscriberInterface { - /** - * The status checker service. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - protected $statusChecker; - /** * Constructs a ConfigSubscriber object. * - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker + * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker * The status checker service. */ - public function __construct(StatusChecker $status_checker) { - $this->statusChecker = $status_checker; + public function __construct(protected StatusChecker $statusChecker) { + $this->statusChecker = $statusChecker; } /** diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php index 45d37c6145..37bee5122f 100644 --- a/src/Form/UpdateReady.php +++ b/src/Form/UpdateReady.php @@ -28,65 +28,27 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; */ final class UpdateReady extends UpdateFormBase { - /** - * The updater service. - * - * @var \Drupal\automatic_updates\Updater - */ - protected $updater; - - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The module list service. - * - * @var \Drupal\Core\Extension\ModuleExtensionList - */ - protected $moduleList; - - /** - * The renderer service. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * The event dispatcher. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - /** * Constructs a new UpdateReady object. * * @param \Drupal\automatic_updates\Updater $updater * The updater service. - * @param \Drupal\Core\Messenger\MessengerInterface $messenger - * The messenger service. * @param \Drupal\Core\State\StateInterface $state * The state service. - * @param \Drupal\Core\Extension\ModuleExtensionList $module_list + * @param \Drupal\Core\Extension\ModuleExtensionList $moduleList * The module list service. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher * Event dispatcher service. */ - public function __construct(Updater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, RendererInterface $renderer, EventDispatcherInterface $event_dispatcher) { - $this->updater = $updater; - $this->setMessenger($messenger); - $this->state = $state; - $this->moduleList = $module_list; - $this->renderer = $renderer; - $this->eventDispatcher = $event_dispatcher; - } + public function __construct( + protected Updater $updater, + protected StateInterface $state, + protected ModuleExtensionList $moduleList, + protected RendererInterface $renderer, + protected EventDispatcherInterface $eventDispatcher, + ) {} /** * {@inheritdoc} @@ -101,7 +63,6 @@ final class UpdateReady extends UpdateFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('automatic_updates.updater'), - $container->get('messenger'), $container->get('state'), $container->get('extension.list.module'), $container->get('renderer'), @@ -131,7 +92,7 @@ final class UpdateReady extends UpdateFormBase { $staged_core_packages = $this->updater->getStageComposer() ->getCorePackages(); } - catch (\Throwable $exception) { + catch (\Throwable) { $messages[MessengerInterface::TYPE_ERROR][] = $this->t('There was an error loading the pending update. Press the <em>Cancel update</em> button to start over.'); } diff --git a/src/Form/UpdaterForm.php b/src/Form/UpdaterForm.php index 286416c238..4a569035ec 100644 --- a/src/Form/UpdaterForm.php +++ b/src/Form/UpdaterForm.php @@ -36,55 +36,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; */ final class UpdaterForm extends UpdateFormBase { - /** - * The updater service. - * - * @var \Drupal\automatic_updates\Updater - */ - protected $updater; - - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The event dispatcher service. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * The release chooser service. - * - * @var \Drupal\automatic_updates\ReleaseChooser - */ - protected $releaseChooser; - - /** - * The renderer service. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * Failure marker service. - * - * @var \Drupal\package_manager\FailureMarker - */ - protected $failureMarker; - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * Constructs a new UpdaterForm object. * @@ -92,26 +43,26 @@ final class UpdaterForm extends UpdateFormBase { * The state service. * @param \Drupal\automatic_updates\Updater $updater * The updater service. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher * The event dispatcher service. - * @param \Drupal\automatic_updates\ReleaseChooser $release_chooser + * @param \Drupal\automatic_updates\ReleaseChooser $releaseChooser * The release chooser service. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. - * @param \Drupal\package_manager\FailureMarker $failure_marker + * @param \Drupal\package_manager\FailureMarker $failureMarker * The failure marker service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler service. */ - public function __construct(StateInterface $state, Updater $updater, EventDispatcherInterface $event_dispatcher, ReleaseChooser $release_chooser, RendererInterface $renderer, FailureMarker $failure_marker, ModuleHandlerInterface $module_handler) { - $this->updater = $updater; - $this->state = $state; - $this->eventDispatcher = $event_dispatcher; - $this->releaseChooser = $release_chooser; - $this->renderer = $renderer; - $this->failureMarker = $failure_marker; - $this->moduleHandler = $module_handler; - } + public function __construct( + protected StateInterface $state, + protected Updater $updater, + protected EventDispatcherInterface $eventDispatcher, + protected ReleaseChooser $releaseChooser, + protected RendererInterface $renderer, + protected FailureMarker $failureMarker, + protected ModuleHandlerInterface $moduleHandler, + ) {} /** * {@inheritdoc} @@ -163,7 +114,7 @@ final class UpdaterForm extends UpdateFormBase { 'stage_id' => $stage_id, ]); } - catch (StageOwnershipException $e) { + catch (StageOwnershipException) { // We already know a stage exists, even if it's not ours, so we don't // have to do anything else here. } diff --git a/src/ReleaseChooser.php b/src/ReleaseChooser.php index aec7fdce97..04349da303 100644 --- a/src/ReleaseChooser.php +++ b/src/ReleaseChooser.php @@ -17,13 +17,6 @@ final class ReleaseChooser { use VersionParsingTrait; - /** - * The version policy validator service. - * - * @var \Drupal\automatic_updates\Validator\VersionPolicyValidator - */ - protected $versionPolicyValidator; - /** * The project information fetcher. * @@ -34,11 +27,10 @@ final class ReleaseChooser { /** * Constructs an ReleaseChooser object. * - * @param \Drupal\automatic_updates\Validator\VersionPolicyValidator $version_policy_validator + * @param \Drupal\automatic_updates\Validator\VersionPolicyValidator $versionPolicyValidator * The version validator. */ - public function __construct(VersionPolicyValidator $version_policy_validator) { - $this->versionPolicyValidator = $version_policy_validator; + public function __construct(protected VersionPolicyValidator $versionPolicyValidator) { $this->projectInfo = new ProjectInfo('drupal'); } diff --git a/src/StatusCheckMailer.php b/src/StatusCheckMailer.php index 80a036b6ec..c25adf3679 100644 --- a/src/StatusCheckMailer.php +++ b/src/StatusCheckMailer.php @@ -41,42 +41,21 @@ final class StatusCheckMailer { */ public const ERRORS_ONLY = 'errors_only'; - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected ConfigFactoryInterface $configFactory; - - /** - * The mail manager service. - * - * @var \Drupal\Core\Mail\MailManagerInterface - */ - protected MailManagerInterface $mailManager; - - /** - * The language manager service. - * - * @var \Drupal\Core\Language\LanguageManagerInterface - */ - protected LanguageManagerInterface $languageManager; - /** * Constructs a StatusCheckNotifier object. * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. - * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager + * @param \Drupal\Core\Mail\MailManagerInterface $mailManager * The mail manager service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager * The language manager service. */ - public function __construct(ConfigFactoryInterface $config_factory, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) { - $this->configFactory = $config_factory; - $this->mailManager = $mail_manager; - $this->languageManager = $language_manager; - } + public function __construct( + protected ConfigFactoryInterface $configFactory, + protected MailManagerInterface $mailManager, + protected LanguageManagerInterface $languageManager, + ) {} /** * Sends status check failure notifications if necessary. diff --git a/src/Updater.php b/src/Updater.php index 4880400eb7..7a73c0cae6 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -5,23 +5,11 @@ declare(strict_types = 1); namespace Drupal\automatic_updates; use Drupal\automatic_updates\Exception\UpdateException; -use Drupal\Component\Datetime\TimeInterface; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\File\FileSystemInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\Exception\StageValidationException; -use Drupal\package_manager\FailureMarker; -use Drupal\package_manager\PathLocator; use Drupal\package_manager\Stage; -use Drupal\package_manager\UnusedConfigFactory; -use PhpTuf\ComposerStager\Domain\Core\Beginner\BeginnerInterface; -use PhpTuf\ComposerStager\Domain\Core\Committer\CommitterInterface; -use PhpTuf\ComposerStager\Domain\Core\Stager\StagerInterface; -use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Defines a service to perform updates. @@ -33,15 +21,6 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; */ class Updater extends Stage { - /** - * {@inheritdoc} - * - * @todo Remove this in https://www.drupal.org/i/3303167 - */ - public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $temp_store_factory, TimeInterface $time, PathFactoryInterface $path_factory = NULL, FailureMarker $failure_marker = NULL) { - parent::__construct(new UnusedConfigFactory(), $path_locator, $beginner, $stager, $committer, $file_system, $event_dispatcher, $temp_store_factory, $time, $path_factory, $failure_marker); - } - /** * Begins the update. * diff --git a/src/Validation/AdminStatusCheckMessages.php b/src/Validation/AdminStatusCheckMessages.php index 43b9215f50..920059c402 100644 --- a/src/Validation/AdminStatusCheckMessages.php +++ b/src/Validation/AdminStatusCheckMessages.php @@ -15,7 +15,6 @@ use Drupal\Core\Routing\RedirectDestinationTrait; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\package_manager\ValidationResult; use Drupal\system\SystemManager; @@ -35,78 +34,30 @@ final class AdminStatusCheckMessages implements ContainerInjectionInterface { use RedirectDestinationTrait; use ValidationResultDisplayTrait; - /** - * The status checker service. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - protected $statusChecker; - - /** - * The admin context service. - * - * @var \Drupal\Core\Routing\AdminContext - */ - protected $adminContext; - - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountProxyInterface - */ - protected $currentUser; - - /** - * The current route match. - * - * @var \Drupal\Core\Routing\CurrentRouteMatch - */ - protected $currentRouteMatch; - - /** - * The cron updater service. - * - * @var \Drupal\automatic_updates\CronUpdater - */ - protected $cronUpdater; - - /** - * The renderer service. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - /** * Constructs an AdminStatusCheckMessages object. * - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker + * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker * The status checker service. - * @param \Drupal\Core\Messenger\MessengerInterface $messenger - * The messenger service. - * @param \Drupal\Core\Routing\AdminContext $admin_context + * @param \Drupal\Core\Routing\AdminContext $adminContext * The admin context service. - * @param \Drupal\Core\Session\AccountProxyInterface $current_user + * @param \Drupal\Core\Session\AccountProxyInterface $currentUser * The current user. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - * @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match + * @param \Drupal\Core\Routing\CurrentRouteMatch $currentRouteMatch * The current route match. - * @param \Drupal\automatic_updates\CronUpdater $cron_updater + * @param \Drupal\automatic_updates\CronUpdater $cronUpdater * The cron updater service. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. */ - public function __construct(StatusChecker $status_checker, MessengerInterface $messenger, AdminContext $admin_context, AccountProxyInterface $current_user, TranslationInterface $translation, CurrentRouteMatch $current_route_match, CronUpdater $cron_updater, RendererInterface $renderer) { - $this->statusChecker = $status_checker; - $this->setMessenger($messenger); - $this->adminContext = $admin_context; - $this->currentUser = $current_user; - $this->setStringTranslation($translation); - $this->currentRouteMatch = $current_route_match; - $this->cronUpdater = $cron_updater; - $this->renderer = $renderer; - } + public function __construct( + protected StatusChecker $statusChecker, + protected AdminContext $adminContext, + protected AccountProxyInterface $currentUser, + protected CurrentRouteMatch $currentRouteMatch, + protected CronUpdater $cronUpdater, + protected RendererInterface $renderer + ) {} /** * {@inheritdoc} @@ -114,10 +65,8 @@ final class AdminStatusCheckMessages implements ContainerInjectionInterface { public static function create(ContainerInterface $container): self { return new static( $container->get('automatic_updates.status_checker'), - $container->get('messenger'), $container->get('router.admin_context'), $container->get('current_user'), - $container->get('string_translation'), $container->get('current_route_match'), $container->get('automatic_updates.cron_updater'), $container->get('renderer') @@ -162,14 +111,8 @@ final class AdminStatusCheckMessages implements ContainerInjectionInterface { } if ($this->adminContext->isAdminRoute() && $this->currentUser->hasPermission('administer site configuration')) { - $route = $this->currentRouteMatch->getRouteObject(); - if ($route) { - if ($route->hasOption('_automatic_updates_readiness_messages')) { - @trigger_error('The _automatic_updates_readiness_messages route option is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use _automatic_updates_status_messages route option instead. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED); - $route->setOption('_automatic_updates_status_messages', $route->getOption('_automatic_updates_readiness_messages')); - } - return $route->getOption('_automatic_updates_status_messages') !== 'skip'; - } + return $this->currentRouteMatch->getRouteObject() + ?->getOption('_automatic_updates_status_messages') !== 'skip'; } return FALSE; } diff --git a/src/Validation/ReadinessValidationManager.php b/src/Validation/ReadinessValidationManager.php deleted file mode 100644 index 95728d9c9e..0000000000 --- a/src/Validation/ReadinessValidationManager.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\automatic_updates\Validation; - -/** - * Defines a manager to run readiness validation. - */ -final class ReadinessValidationManager { - - /** - * The decorated status checker service. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - private $statusChecker; - - /** - * Constructs a ReadinessValidationManager. - * - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker - * The decorated status checker service. - */ - public function __construct(StatusChecker $status_checker) { - $this->statusChecker = $status_checker; - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::run(). - */ - public function run(): self { - $this->statusChecker->run(); - return $this; - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::runIfNoStoredResults(). - */ - public function runIfNoStoredResults(): self { - $this->statusChecker->runIfNoStoredResults(); - return $this; - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::getResults(). - */ - public function getResults(?int $severity = NULL): ?array { - return $this->statusChecker->getResults($severity); - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::clearStoredResults(). - */ - public function clearStoredResults(): void { - $this->statusChecker->clearStoredResults(); - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::getLastRunTime(). - */ - public function getLastRunTime(): ?int { - return $this->statusChecker->getLastRunTime(); - } - - /** - * Wraps \Drupal\automatic_updates\Validation\StatusChecker::getSubscribedEvents(). - */ - public static function getSubscribedEvents() { - return StatusChecker::getSubscribedEvents(); - } - -} diff --git a/src/Validation/StatusCheckRequirements.php b/src/Validation/StatusCheckRequirements.php index d1504dfe61..e799f27b89 100644 --- a/src/Validation/StatusCheckRequirements.php +++ b/src/Validation/StatusCheckRequirements.php @@ -8,7 +8,6 @@ use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\system\SystemManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -27,34 +26,15 @@ final class StatusCheckRequirements implements ContainerInjectionInterface { use StringTranslationTrait; use ValidationResultDisplayTrait; - /** - * The status checker service. - * - * @var \Drupal\automatic_updates\Validation\StatusChecker - */ - protected $statusChecker; - - /** - * The date formatter service. - * - * @var \Drupal\Core\Datetime\DateFormatterInterface - */ - protected $dateFormatter; - /** * Constructs a StatusCheckRequirements object. * - * @param \Drupal\automatic_updates\Validation\StatusChecker $status_checker + * @param \Drupal\automatic_updates\Validation\StatusChecker $statusChecker * The status checker service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter + * @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter * The date formatter service. */ - public function __construct(StatusChecker $status_checker, TranslationInterface $translation, DateFormatterInterface $date_formatter) { - $this->statusChecker = $status_checker; - $this->setStringTranslation($translation); - $this->dateFormatter = $date_formatter; + public function __construct(protected StatusChecker $statusChecker, protected DateFormatterInterface $dateFormatter) { } /** @@ -63,7 +43,6 @@ final class StatusCheckRequirements implements ContainerInjectionInterface { public static function create(ContainerInterface $container): self { return new static( $container->get('automatic_updates.status_checker'), - $container->get('string_translation'), $container->get('date.formatter') ); } diff --git a/src/Validation/StatusChecker.php b/src/Validation/StatusChecker.php index 1330639e56..a8b4c5f966 100644 --- a/src/Validation/StatusChecker.php +++ b/src/Validation/StatusChecker.php @@ -27,41 +27,6 @@ final class StatusChecker implements EventSubscriberInterface { */ protected $keyValueExpirable; - /** - * The time service. - * - * @var \Drupal\Component\Datetime\TimeInterface - */ - protected $time; - - /** - * The event dispatcher service. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * The number of hours to store results. - * - * @var int - */ - protected $resultsTimeToLive; - - /** - * The updater service. - * - * @var \Drupal\automatic_updates\Updater - */ - protected $updater; - - /** - * The cron updater service. - * - * @var \Drupal\automatic_updates\CronUpdater - */ - protected $cronUpdater; - /** * Constructs a StatusChecker. * @@ -69,22 +34,24 @@ final class StatusChecker implements EventSubscriberInterface { * The key/value expirable factory. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher * The event dispatcher service. * @param \Drupal\automatic_updates\Updater $updater * The updater service. - * @param \Drupal\automatic_updates\CronUpdater $cron_updater + * @param \Drupal\automatic_updates\CronUpdater $cronUpdater * The cron updater service. - * @param int $results_time_to_live + * @param int $resultsTimeToLive * The number of hours to store results. */ - public function __construct(KeyValueExpirableFactoryInterface $key_value_expirable_factory, TimeInterface $time, EventDispatcherInterface $dispatcher, Updater $updater, CronUpdater $cron_updater, int $results_time_to_live) { + public function __construct( + KeyValueExpirableFactoryInterface $key_value_expirable_factory, + protected TimeInterface $time, + protected EventDispatcherInterface $eventDispatcher, + protected Updater $updater, + protected CronUpdater $cronUpdater, + protected int $resultsTimeToLive, + ) { $this->keyValueExpirable = $key_value_expirable_factory->get('automatic_updates'); - $this->time = $time; - $this->eventDispatcher = $dispatcher; - $this->updater = $updater; - $this->cronUpdater = $cron_updater; - $this->resultsTimeToLive = $results_time_to_live; } /** diff --git a/src/Validator/CronFrequencyValidator.php b/src/Validator/CronFrequencyValidator.php index 5eb1bf1ef6..622d688008 100644 --- a/src/Validator/CronFrequencyValidator.php +++ b/src/Validator/CronFrequencyValidator.php @@ -11,7 +11,6 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\package_manager\Event\StatusCheckEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -55,75 +54,30 @@ class CronFrequencyValidator implements EventSubscriberInterface { */ protected const SUGGESTED_INTERVAL = self::WARNING_INTERVAL / 3600; - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The time service. - * - * @var \Drupal\Component\Datetime\TimeInterface - */ - protected $time; - - /** - * The cron updater service. - * - * @var \Drupal\automatic_updates\CronUpdater - */ - protected $cronUpdater; - - /** - * The lock service. - * - * @var \Drupal\Core\Lock\LockBackendInterface - */ - protected $lock; - /** * CronFrequencyValidator constructor. * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler. * @param \Drupal\Core\State\StateInterface $state * The state service. * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - * @param \Drupal\automatic_updates\CronUpdater $cron_updater + * @param \Drupal\automatic_updates\CronUpdater $cronUpdater * The cron updater service. * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock service. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, TimeInterface $time, TranslationInterface $translation, CronUpdater $cron_updater, LockBackendInterface $lock) { - $this->configFactory = $config_factory; - $this->moduleHandler = $module_handler; - $this->state = $state; - $this->time = $time; - $this->setStringTranslation($translation); - $this->cronUpdater = $cron_updater; - $this->lock = $lock; - } + public function __construct( + protected ConfigFactoryInterface $configFactory, + protected ModuleHandlerInterface $moduleHandler, + protected StateInterface $state, + protected TimeInterface $time, + protected CronUpdater $cronUpdater, + protected LockBackendInterface $lock, + ) {} /** * Validates that cron runs frequently enough to perform automatic updates. diff --git a/src/Validator/CronServerValidator.php b/src/Validator/CronServerValidator.php index 4e4829db30..b7bfd67b1c 100644 --- a/src/Validator/CronServerValidator.php +++ b/src/Validator/CronServerValidator.php @@ -35,20 +35,6 @@ final class CronServerValidator implements EventSubscriberInterface { */ protected $request; - /** - * The config factory service. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * The type of interface between the web server and the PHP runtime. * @@ -64,15 +50,17 @@ final class CronServerValidator implements EventSubscriberInterface { * * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack service. - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The config factory service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler service. */ - public function __construct(RequestStack $request_stack, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { + public function __construct( + RequestStack $request_stack, + protected ConfigFactoryInterface $configFactory, + protected ModuleHandlerInterface $moduleHandler, + ) { $this->request = $request_stack->getCurrentRequest(); - $this->configFactory = $config_factory; - $this->moduleHandler = $module_handler; } /** diff --git a/src/Validator/RequestedUpdateValidator.php b/src/Validator/RequestedUpdateValidator.php index 55c1f8adf3..0ef3f355f5 100644 --- a/src/Validator/RequestedUpdateValidator.php +++ b/src/Validator/RequestedUpdateValidator.php @@ -7,7 +7,6 @@ namespace Drupal\automatic_updates\Validator; use Composer\Semver\Semver; use Drupal\automatic_updates\Updater; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -18,16 +17,6 @@ class RequestedUpdateValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * Constructs a RequestedUpdateValidator object. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - */ - public function __construct(TranslationInterface $translation) { - $this->setStringTranslation($translation); - } - /** * Validates that requested packages have been updated to the right version. * diff --git a/src/Validator/ScaffoldFilePermissionsValidator.php b/src/Validator/ScaffoldFilePermissionsValidator.php index 2e0ef7c14f..5a8dd2db66 100644 --- a/src/Validator/ScaffoldFilePermissionsValidator.php +++ b/src/Validator/ScaffoldFilePermissionsValidator.php @@ -26,21 +26,13 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface use StringTranslationTrait; - /** - * The path locator service. - * - * @var \Drupal\package_manager\PathLocator - */ - protected $pathLocator; - /** * Constructs a SiteDirectoryPermissionsValidator object. * - * @param \Drupal\package_manager\PathLocator $path_locator + * @param \Drupal\package_manager\PathLocator $pathLocator * The path locator service. */ - public function __construct(PathLocator $path_locator) { - $this->pathLocator = $path_locator; + public function __construct(protected PathLocator $pathLocator) { } /** diff --git a/src/Validator/StagedDatabaseUpdateValidator.php b/src/Validator/StagedDatabaseUpdateValidator.php index 7d89d208ab..f50234bcdf 100644 --- a/src/Validator/StagedDatabaseUpdateValidator.php +++ b/src/Validator/StagedDatabaseUpdateValidator.php @@ -6,7 +6,6 @@ namespace Drupal\automatic_updates\Validator; use Drupal\automatic_updates\CronUpdater; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Validator\StagedDBUpdateValidator; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -23,24 +22,13 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The Staged DB Update Validator service. - * - * @var \Drupal\package_manager\Validator\StagedDBUpdateValidator - */ - protected $stagedDBUpdateValidator; - /** * Constructs a StagedDatabaseUpdateValidator object. * - * @param \Drupal\package_manager\Validator\StagedDBUpdateValidator $staged_db_update_update_validator + * @param \Drupal\package_manager\Validator\StagedDBUpdateValidator $stagedDBUpdateValidator * The Staged DB Update Validator service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The string translation service. */ - public function __construct(StagedDBUpdateValidator $staged_db_update_update_validator, TranslationInterface $translation) { - $this->stagedDBUpdateValidator = $staged_db_update_update_validator; - $this->setStringTranslation($translation); + public function __construct(protected StagedDBUpdateValidator $stagedDBUpdateValidator) { } /** diff --git a/src/Validator/StagedProjectsValidator.php b/src/Validator/StagedProjectsValidator.php index def20086af..08faf9a2c5 100644 --- a/src/Validator/StagedProjectsValidator.php +++ b/src/Validator/StagedProjectsValidator.php @@ -8,7 +8,6 @@ use Composer\Package\PackageInterface; use Drupal\automatic_updates\Updater; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -23,16 +22,6 @@ final class StagedProjectsValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * Constructs a StagedProjectsValidation object. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation - * The translation service. - */ - public function __construct(TranslationInterface $translation) { - $this->setStringTranslation($translation); - } - /** * Validates the staged packages. * diff --git a/src/Validator/VersionPolicyValidator.php b/src/Validator/VersionPolicyValidator.php index 79ff6e15ac..cb4e31b692 100644 --- a/src/Validator/VersionPolicyValidator.php +++ b/src/Validator/VersionPolicyValidator.php @@ -36,21 +36,13 @@ final class VersionPolicyValidator implements EventSubscriberInterface { use StringTranslationTrait; - /** - * The class resolver service. - * - * @var \Drupal\Core\DependencyInjection\ClassResolverInterface - */ - private $classResolver; - /** * Constructs a VersionPolicyValidator object. * - * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver + * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $classResolver * The class resolver service. */ - public function __construct(ClassResolverInterface $class_resolver) { - $this->classResolver = $class_resolver; + public function __construct(private ClassResolverInterface $classResolver) { } /** diff --git a/tests/src/Functional/DeprecatedRoutesTest.php b/tests/src/Functional/DeprecatedRoutesTest.php deleted file mode 100644 index ff89fd57f4..0000000000 --- a/tests/src/Functional/DeprecatedRoutesTest.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\Tests\automatic_updates\Functional; - -use Drupal\Core\Url; - -/** - * @covers \Drupal\automatic_updates\Controller\UpdateController::redirectDeprecatedRoute - * @covers \Drupal\automatic_updates\Routing\RouteSubscriber - * @group automatic_updates - * @group legacy - * @internal - */ -class DeprecatedRoutesTest extends AutomaticUpdatesFunctionalTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['automatic_updates']; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * Tests that deprecated routes are redirected with an informative message. - */ - public function testDeprecatedRoutesAreRedirected(): void { - $account = $this->createUser([ - 'administer software updates', - 'administer site configuration', - ]); - $this->drupalLogin($account); - - $routes = [ - 'automatic_updates.module_update' => ['update.module_update', NULL], - 'automatic_updates.report_update' => ['update.report_update', NULL], - 'automatic_updates.theme_update' => ['update.theme_update', NULL], - 'automatic_updates.update_readiness' => ['automatic_updates.status_check', 'system.status'], - ]; - $assert_session = $this->assertSession(); - - foreach ($routes as $deprecated_route => [$redirect_route, $final_route]) { - $deprecated_url = Url::fromRoute($deprecated_route) - ->setAbsolute() - ->toString(); - $redirect_url = Url::fromRoute($redirect_route) - ->setAbsolute() - ->toString(); - if ($final_route) { - $final_url = Url::fromRoute($final_route) - ->setAbsolute() - ->toString(); - } - - $this->drupalGet($deprecated_url); - $assert_session->statusCodeEquals(200); - $assert_session->addressEquals($final_url ?? $redirect_url); - $assert_session->responseContains("This page was accessed from $deprecated_url, which is deprecated and will not work in the next major version of Automatic Updates. Please use <a href=\"$redirect_url\">$redirect_url</a> instead."); - } - } - -} diff --git a/tests/src/Functional/PreUpdateTest.php b/tests/src/Functional/PreUpdateTest.php index 14c1acbb9f..cbc59208d4 100644 --- a/tests/src/Functional/PreUpdateTest.php +++ b/tests/src/Functional/PreUpdateTest.php @@ -25,7 +25,7 @@ class PreUpdateTest extends UpdaterFormTestBase { $result = ValidationResult::createError([$message]); TestSubscriber1::setTestResult([$result], StatusCheckEvent::class); $this->checkForUpdates(); - $this->drupalGet('/admin/reports/updates/automatic-update'); + $this->drupalGet('/admin/reports/updates/update'); $assert_session->pageTextContains('No update available'); $assert_session->pageTextContains($message); } @@ -40,7 +40,7 @@ class PreUpdateTest extends UpdaterFormTestBase { ->set('allow_core_minor_updates', TRUE) ->save(); $this->checkForUpdates(); - $this->drupalGet('/admin/reports/updates/automatic-update'); + $this->drupalGet('/admin/reports/updates/update'); $assert_session = $this->assertSession(); $this->checkReleaseTable('#edit-next-minor-1', '.update-update-recommended', '9.8.0-beta1', FALSE, 'Latest version of Drupal 9.8 (next minor):'); $assert_session->pageTextContainsOnce('Currently installed: 9.7.0 (Up to date)'); diff --git a/tests/src/Functional/UpdateCompleteMessageTest.php b/tests/src/Functional/UpdateCompleteMessageTest.php index 332516f59d..40e9e7287d 100644 --- a/tests/src/Functional/UpdateCompleteMessageTest.php +++ b/tests/src/Functional/UpdateCompleteMessageTest.php @@ -44,7 +44,7 @@ class UpdateCompleteMessageTest extends UpdaterFormTestBase { $state->set('system.maintenance_mode', $maintenance_mode_on); $page = $this->getSession()->getPage(); - $this->drupalGet('/admin/modules/automatic-update'); + $this->drupalGet('/admin/modules/update'); $page->pressButton('Update to 9.8.1'); $this->checkForMetaRefresh(); // Confirm that the site was put into maintenance mode if needed. diff --git a/tests/src/Functional/UpdateErrorTest.php b/tests/src/Functional/UpdateErrorTest.php index f7e77c9583..f318e8492c 100644 --- a/tests/src/Functional/UpdateErrorTest.php +++ b/tests/src/Functional/UpdateErrorTest.php @@ -55,7 +55,7 @@ class UpdateErrorTest extends UpdaterFormTestBase { $page = $session->getPage(); $this->mockActiveCoreVersion('9.8.0'); $this->checkForUpdates(); - $this->drupalGet('/admin/modules/automatic-update'); + $this->drupalGet('/admin/modules/update'); $page->pressButton('Update to 9.8.1'); $this->checkForMetaRefresh(); $this->assertUpdateStagedTimes(1); diff --git a/tests/src/Functional/UpdateFailedTest.php b/tests/src/Functional/UpdateFailedTest.php index 028e1b143e..8258256741 100644 --- a/tests/src/Functional/UpdateFailedTest.php +++ b/tests/src/Functional/UpdateFailedTest.php @@ -24,7 +24,7 @@ class UpdateFailedTest extends UpdaterFormTestBase { $this->mockActiveCoreVersion('9.8.0'); $this->checkForUpdates(); - $this->drupalGet('/admin/modules/automatic-update'); + $this->drupalGet('/admin/modules/update'); $assert_session->pageTextNotContains(static::$errorsExplanation); $assert_session->pageTextNotContains(static::$warningsExplanation); $page->pressButton('Update to 9.8.1'); @@ -45,7 +45,7 @@ class UpdateFailedTest extends UpdaterFormTestBase { $assert_session->pageTextContains($failure_message); $assert_session->buttonNotExists('Continue'); // The same thing should be true if we try to start from the beginning. - $this->drupalGet('/admin/modules/automatic-update'); + $this->drupalGet('/admin/modules/update'); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($failure_message); $assert_session->buttonNotExists('Update'); diff --git a/tests/src/Functional/UpdateWarningTest.php b/tests/src/Functional/UpdateWarningTest.php index 0465782ce8..27da2f1228 100644 --- a/tests/src/Functional/UpdateWarningTest.php +++ b/tests/src/Functional/UpdateWarningTest.php @@ -23,7 +23,7 @@ class UpdateWarningTest extends UpdaterFormTestBase { $this->mockActiveCoreVersion('9.8.0'); $this->checkForUpdates(); - $this->drupalGet('/admin/modules/automatic-update'); + $this->drupalGet('/admin/modules/update'); $session->getPage()->pressButton('Update to 9.8.1'); $this->checkForMetaRefresh(); $this->assertUpdateStagedTimes(1); diff --git a/tests/src/Kernel/ReadinessCheckTest.php b/tests/src/Kernel/ReadinessCheckTest.php deleted file mode 100644 index 4238c25ba7..0000000000 --- a/tests/src/Kernel/ReadinessCheckTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -declare(strict_types = 1); - -namespace Drupal\Tests\automatic_updates\Kernel; - -use Drupal\automatic_updates\Event\ReadinessCheckEvent; -use Drupal\package_manager\StatusCheckTrait; - -/** - * Tests that running readiness checks raises deprecation notices. - * - * @group legacy - * @internal - */ -class ReadinessCheckTest extends AutomaticUpdatesKernelTestBase { - - use StatusCheckTrait; - - /** - * {@inheritdoc} - */ - protected static $modules = ['automatic_updates']; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - - $this->addEventTestListener(function () {}, ReadinessCheckEvent::class); - } - - /** - * Tests running readiness check via StatusCheckTrait. - */ - public function testStatusCheckTrait(): void { - $this->expectDeprecation(ReadinessCheckEvent::class . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.'); - $this->runStatusCheck($this->createStage(), $this->container->get('event_dispatcher'), TRUE); - } - - /** - * Tests running readiness checks using the readiness validation manager. - */ - public function testReadinessValidationManager(): void { - $this->expectDeprecation('The "automatic_updates.readiness_validation_manager" service is deprecated in automatic_updates:8.x-2.5 and is removed from automatic_updates:3.0.0. Use the automatic_updates.status_checker service instead. See https://www.drupal.org/node/3316086.'); - $this->expectDeprecation(ReadinessCheckEvent::class . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.'); - $this->container->get('automatic_updates.readiness_validation_manager') - ->run(); - } - -} diff --git a/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php b/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php index 318f12152c..762e326c2d 100644 --- a/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php @@ -49,7 +49,6 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { $this->container->get('module_handler'), $this->container->get('state'), $this->container->get('datetime.time'), - $this->container->get('string_translation'), $this->container->get('automatic_updates.cron_updater'), $this->container->get('lock') ) extends CronFrequencyValidator { -- GitLab