diff --git a/core/modules/automatic_updates/automatic_updates.install b/core/modules/automatic_updates/automatic_updates.install index f4059c8203..c16b2fb3c0 100644 --- a/core/modules/automatic_updates/automatic_updates.install +++ b/core/modules/automatic_updates/automatic_updates.install @@ -2,7 +2,7 @@ /** * @file - * Automatic updates install file. + * Contains install and update functions for Automatic Updates. */ use Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface; diff --git a/core/modules/automatic_updates/automatic_updates.module b/core/modules/automatic_updates/automatic_updates.module index 1b23b96d3e..12574bf49f 100644 --- a/core/modules/automatic_updates/automatic_updates.module +++ b/core/modules/automatic_updates/automatic_updates.module @@ -2,7 +2,7 @@ /** * @file - * Contains automatic_updates.module.. + * Provides hook implementations for Automatic Updates. */ use Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface; diff --git a/core/modules/automatic_updates/automatic_updates.services.yml b/core/modules/automatic_updates/automatic_updates.services.yml index c2fe5a973e..0e902f8506 100644 --- a/core/modules/automatic_updates/automatic_updates.services.yml +++ b/core/modules/automatic_updates/automatic_updates.services.yml @@ -4,14 +4,11 @@ services: arguments: ['automatic_updates'] automatic_updates.disk_space_checker: class: Drupal\automatic_updates\ReadinessChecker\DiskSpace - arguments: - - '@app.root' + arguments: ['%app.root%'] tags: - { name: readiness_checker, category: error} automatic_updates.readiness_checker: class: Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManager - arguments: - - '@keyvalue' - - '@config.factory' + arguments: ['@keyvalue', '@config.factory'] tags: - { name: service_collector, tag: readiness_checker, call: addChecker } diff --git a/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php b/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php index d49d0d4af8..0976e7bb80 100644 --- a/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php +++ b/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Class ReadinessCheckerController. + * A controller for running Readiness Checkers. */ class ReadinessCheckerController extends ControllerBase { @@ -23,7 +23,7 @@ class ReadinessCheckerController extends ControllerBase { * ReadinessCheckerController constructor. * * @param \Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface $checker - * The readiness checker. + * The readiness checker manager. * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. */ @@ -46,7 +46,7 @@ public static function create(ContainerInterface $container) { * Run the readiness checkers. * * @return \Symfony\Component\HttpFoundation\RedirectResponse - * A redirect + * A redirect response object. */ public function run() { $messages = []; diff --git a/core/modules/automatic_updates/src/Form/SettingsForm.php b/core/modules/automatic_updates/src/Form/SettingsForm.php index bef89782ae..dc3e8bab83 100644 --- a/core/modules/automatic_updates/src/Form/SettingsForm.php +++ b/core/modules/automatic_updates/src/Form/SettingsForm.php @@ -8,18 +8,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Settings form for automatic updates. + * Settings form for Automatic Updates. */ class SettingsForm extends ConfigFormBase { /** - * The readiness checker. + * The readiness checker manager. * * @var \Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface */ protected $checker; /** - * The data formatter. + * The date formatter. * * @var \Drupal\Core\Datetime\DateFormatterInterface */ diff --git a/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php b/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php index 984031e030..82d86eef5e 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php @@ -5,7 +5,7 @@ use Drupal\Component\FileSystem\FileSystem as FileSystemComponent; /** - * Disk space checker. + * The disk space readiness checker. */ class DiskSpace extends Filesystem { @@ -29,36 +29,37 @@ protected function doCheck() { /** * Check if the filesystem has sufficient disk space. * - * @return array + * @return \Drupal\Core\StringTranslation\TranslatableMarkup[] * An array of translatable strings if there is not sufficient space. */ protected function diskSpaceCheck() { $messages = []; + $minimum_megabytes = static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR; if (!$this->areSameLogicalDisk($this->getRootPath(), $this->getVendorPath())) { if (disk_free_space($this->getRootPath()) < static::MINIMUM_DISK_SPACE) { $messages[] = $this->t('Drupal root filesystem "@root" has insufficient space. There must be at least @space megabytes free.', [ '@root' => $this->getRootPath(), - '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR, + '@space' => $minimum_megabytes, ]); } if (is_dir($this->getVendorPath()) && disk_free_space($this->getVendorPath()) < static::MINIMUM_DISK_SPACE) { $messages[] = $this->t('Vendor filesystem "@vendor" has insufficient space. There must be at least @space megabytes free.', [ '@vendor' => $this->getVendorPath(), - '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR, + '@space' => $minimum_megabytes, ]); } } elseif (disk_free_space($this->getRootPath()) < static::MINIMUM_DISK_SPACE) { $messages[] = $this->t('Logical disk "@root" has insufficient space. There must be at least @space megabytes free.', [ '@root' => $this->getRootPath(), - '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR, + '@space' => $minimum_megabytes, ]); } $temp = FileSystemComponent::getOsTemporaryDirectory(); if (disk_free_space($temp) < static::MINIMUM_DISK_SPACE) { $messages[] = $this->t('Directory "@temp" has insufficient space. There must be at least @space megabytes free.', [ '@temp' => $temp, - '@space' => static::MINIMUM_DISK_SPACE / static::MEGABYTE_DIVISOR, + '@space' => $minimum_megabytes, ]); } return $messages; diff --git a/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php b/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php index de0914ff2a..48eb4b87c8 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php @@ -30,8 +30,8 @@ abstract class Filesystem implements ReadinessCheckerInterface { * @param string $app_root * The app root. */ - public function __construct($app_root) { - $this->rootPath = (string) $app_root; + public function __construct(string $app_root) { + $this->rootPath = $app_root; } /** @@ -90,7 +90,7 @@ protected function getVendorPath() { * @return bool * TRUE if same file system, FALSE otherwise. */ - protected function areSameLogicalDisk($root, $vendor) { + protected function areSameLogicalDisk(string $root, string $vendor) { $root_statistics = stat($root); $vendor_statistics = stat($vendor); return $root_statistics && $vendor_statistics && $root_statistics['dev'] === $vendor_statistics['dev']; diff --git a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManager.php b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManager.php index f6cfab74af..c69f841de6 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManager.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManager.php @@ -50,7 +50,7 @@ public function __construct(KeyValueFactoryInterface $key_value, ConfigFactoryIn /** * {@inheritdoc} */ - public function addChecker(ReadinessCheckerInterface $checker, $category = 'warning', $priority = 0) { + public function addChecker(ReadinessCheckerInterface $checker, string $category = 'warning', $priority = 0) { if (!in_array($category, $this->getCategories(), TRUE)) { throw new \InvalidArgumentException(sprintf('Readiness checker category "%s" is invalid. Use "%s" instead.', $category, implode('" or "', $this->getCategories()))); } @@ -61,11 +61,12 @@ public function addChecker(ReadinessCheckerInterface $checker, $category = 'warn /** * {@inheritdoc} */ - public function run($category) { - $messages = []; + public function run(string $category) { if (!$this->isEnabled()) { - return $messages; + return []; } + $messages = []; + if (!isset($this->getSortedCheckers()[$category])) { // @todd Adding only 1 checker so will error for "warning". // throw new \InvalidArgumentException(sprintf('No readiness checkers exist of category "%s"', $category)); diff --git a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php index 09523eafac..b656943f30 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php @@ -34,7 +34,7 @@ interface ReadinessCheckerManagerInterface { * * @return $this */ - public function addChecker(ReadinessCheckerInterface $checker, $category = 'warning', $priority = 0); + public function addChecker(ReadinessCheckerInterface $checker, string $category = 'warning', $priority = 0); /** * Run checks. @@ -45,7 +45,7 @@ public function addChecker(ReadinessCheckerInterface $checker, $category = 'warn * @return array * An array of translatable strings. */ - public function run($category); + public function run(string $category); /** * Get results of most recent run. @@ -75,10 +75,10 @@ public function timestamp(); public function isEnabled(); /** - * Get the categories of checkers. + * Get the checker categories. * - * @return array - * The categories of checkers. + * @return string[] + * The checkers categories. */ public function getCategories(); diff --git a/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php b/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php index a3b499947f..7efc53affe 100644 --- a/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php +++ b/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php @@ -17,26 +17,24 @@ class DiskSpaceTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = [ - 'automatic_updates', - ]; + protected static $modules = ['automatic_updates']; /** * Tests the functionality of disk space readiness checks. */ public function testDiskSpace() { // No disk space issues. - $disk_space = new DiskSpace($this->container->get('app.root')); + $disk_space = new DiskSpace($this->container->getParameter('app.root')); $messages = $disk_space->run(); $this->assertEmpty($messages); // Out of space. - $disk_space = new TestDiskSpace($this->container->get('app.root')); + $disk_space = new TestDiskSpace($this->container->getParameter('app.root')); $messages = $disk_space->run(); $this->assertCount(2, $messages); // Out of space not the same logical disk. - $disk_space = new TestDiskSpaceNonSameDisk($this->container->get('app.root')); + $disk_space = new TestDiskSpaceNonSameDisk($this->container->getParameter('app.root')); $messages = $disk_space->run(); $this->assertCount(3, $messages); } @@ -63,7 +61,7 @@ class TestDiskSpaceNonSameDisk extends TestDiskSpace { /** * {@inheritdoc} */ - protected function areSameLogicalDisk($root, $vendor) { + protected function areSameLogicalDisk(string $root, string $vendor) { return FALSE; }