diff --git a/README.md b/README.md index 8edca5d..0a740a6 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,8 @@ The comment for the SiteAuditReportBase class must include the ### Custom Checks -Custom Checks should extend `SiteAuditCheckBase` and should live in the `YOURMODULE/src/Plugin/SiteAuditCheck/` directory. +Custom Checks should extend `SiteAuditCheckBase` and should live in the +`YOURMODULE/src/Plugin/SiteAuditCheck/` directory. The comment for the SiteAuditCheckBase class must include the `@SiteAuditCheck` annotation, including _id_, _name_, _description_, and diff --git a/site_audit.module b/site_audit.module index 7eb7e9c..a411b5e 100644 --- a/site_audit.module +++ b/site_audit.module @@ -2,7 +2,7 @@ /** * @file - * Contains hooks and functions for the site_audit.module. + * Hook implementations for the Site Audit module. */ use Drupal\Core\Routing\RouteMatchInterface; @@ -43,16 +43,22 @@ function site_audit_env_is_dev() { } if (!function_exists('human_filesize')) { + /** - * create the human readable file size - * @see https://gist.github.com/liunian/9338301 + * Create the human readable file size representation. * - * @param $size + * @param int $size + * The file size in bytes. * @param int $precision + * The number of decimal places to include in the result. Defaults to 2. + * * @return string + * The human-readable file size. + * + * @see https://gist.github.com/liunian/9338301 */ function human_filesize($size, $precision = 2) { - static $units = array('B','KB','MB','GB','TB','PB','EB','ZB','YB'); + static $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $step = 1024; $i = 0; while (($size / $step) > 0.9) { @@ -61,4 +67,5 @@ if (!function_exists('human_filesize')) { } return round($size, $precision) . ' ' . $units[$i]; } + } diff --git a/src/Checks/Extensions/Count.php b/src/Checks/Extensions/Count.php index abc7d50..dc2a4ea 100644 --- a/src/Checks/Extensions/Count.php +++ b/src/Checks/Extensions/Count.php @@ -5,36 +5,36 @@ namespace Drupal\site_audit\Checks\Extensions; use Drupal\site_audit\Check; /** - * Class SiteAuditCheckExtensionsCount. + * Implementation for checking the number of enabled extensions. */ class Count extends Check { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getLabel() { return $this->t('Count'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getDescription() { return $this->t('Count the number of enabled extensions (modules and themes) in a site.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('There are @extension_count extensions enabled.', [ @@ -43,16 +43,16 @@ class Count extends Check { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { - return $this->t('There are @extension_count extensions enabled; that\'s higher than the average.', [ + return $this->t("There are @extension_count extensions enabled; that's higher than the average.", [ '@extension_count' => $this->registry['extension_count'], ]); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if (!in_array($this->score, [Check::AUDIT_CHECK_SCORE_PASS])) { @@ -61,7 +61,7 @@ class Count extends Check { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry['extensions'] = \Drupal::moduleHandler()->getModuleList(); diff --git a/src/Commands/SiteAuditCommands.php b/src/Commands/SiteAuditCommands.php index cf8f7c1..cea1306 100644 --- a/src/Commands/SiteAuditCommands.php +++ b/src/Commands/SiteAuditCommands.php @@ -60,35 +60,45 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge /** * Run a Site Audit report. * - * @param $report - * The particular report to run. Omit this argument to choose from available reports. + * @param string $report + * The particular report to run. + * Omit this argument to choose from available reports. + * @param array $options + * An array containing the following options: + * skip: List of available reports to skip. + * format: Format in which the report is to be generated + * (html, text, json, markdown). + * detail: Boolean indicating whether to show details when no issues found + * for the check. + * bootstrap: Boolean indicating whether to wrap the report in HTML + * with Bootstrap derived styles (forces --format=html). * - * @option skip - * List of available reports. - * @option format - * Format you which the report is to be in (html, text, json, markdown) - * @option detail - * Show details when no issues found for the check. - * @option bootstrap - * Wrap the report in HTML with Bootstrap derived styles. Forces --format=html - * @usage site_audit:audit - * Run all Site Audit reports + * @return string + * The generated report. * * @command site_audit:audit * @aliases audit * + * @usage site_audit:audit + * Run all Site Audit reports * @usage audit watchdog * only run the watchdog report * @usage audit --skip=block,status * skip the block and status reports */ - public function audit($report, $options = ['skip' => 'none', 'format' => 'text', 'detail' => FALSE, 'bootstrap' => FALSE]) { + public function audit($report, + array $options = [ + 'skip' => 'none', + 'format' => 'text', + 'detail' => FALSE, + 'bootstrap' => FALSE, + ] + ) { if ($options['bootstrap']) { // Bootstrap implies html. $options['format'] = 'html'; } - $boot_manager = Drush::bootstrapManager(); - + // $boot_manager = Drush::bootstrapManager(); $output = $this->output(); $out = ''; $reportDefinitions = $this->auditReportManager->getDefinitions(); @@ -132,7 +142,8 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge default: foreach ($reports as $report) { $renderer = new Console($report, $this->logger, $options, $output); - // The Console::renderer() doesn't return anything, it print directly to the console. + // The Console::renderer() doesn't return anything, + // it print directly to the console. $renderer->render(TRUE); } break; @@ -149,7 +160,8 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge * @option detail * Show details when no issues found for the check. * @option bootstrap - * Wrap the report in HTML with Bootstrap derived styles. Forces --format=html + * Wrap the report in HTML with Bootstrap derived styles. + * Forces --format=html * @usage site_audit:audit-all * Run all Site Audit reports * @@ -162,17 +174,27 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge * @usage audit-all --skip=block,status * skip the block and status reports */ - public function audit_all($options = ['skip' => 'none', 'format' => 'text', 'detail' => FALSE, 'bootstrap' => FALSE]) { + public function auditAll( + $options = [ + 'skip' => 'none', + 'format' => 'text', + 'detail' => FALSE, + 'bootstrap' => FALSE, + ] + ) { return $this->audit('all', $options); } /** - * Take Drupal\Core\StringTranslation\TranslatableMarkup and return the string. + * Take TranslatableMarkup and return the string. * - * @param $message + * @param \Drupal\Core\StringTranslation\TranslatableMarkup|string $message + * The message to interpolate, it can be TranslatableMarkup or string. * @param array $context + * Additional context for message interpolation. * * @return string + * The interpolated string. */ public function interpolate($message, array $context = []) { if (get_class($message) == 'Drupal\Core\StringTranslation\TranslatableMarkup') { @@ -182,12 +204,19 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge } /** + * Implements hook interact for the "site_audit:audit" command. + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * The input interface. + * @param \Symfony\Component\Console\Output\OutputInterface $output + * The output interface. + * * @hook interact site_audit:audit - * @param $input - * @param $output + * * @throws \Drush\Exceptions\UserAbortException + * Thrown when the user aborts the interaction. */ - public function interactSiteAudit($input, $output) { + public function interactSiteAudit(InputInterface $input, OutputInterface $output) { $boot_manager = Drush::bootstrapManager(); if (empty($input->getArgument('report'))) { $reports = $this->getReports($boot_manager->hasBootstrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)); @@ -203,7 +232,7 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge } /** - * Get a list of all the report definitions + * Get a list of all the report definitions. */ public function getReports($include_bootstrapped_types = FALSE) { $reportDefinitions = $this->auditReportManager->getDefinitions(); @@ -226,6 +255,7 @@ class SiteAuditCommands extends DrushCommands implements IOAwareInterface, Logge * @aliases audit-list * * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields + * A structured data object containing the list of reports and checks. */ public function list() { $reportDefinitions = $this->auditReportManager->getDefinitions(); diff --git a/src/Controller/SiteAuditController.php b/src/Controller/SiteAuditController.php index 78d4a4f..a4c7a97 100644 --- a/src/Controller/SiteAuditController.php +++ b/src/Controller/SiteAuditController.php @@ -10,16 +10,16 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; /** - * Class SiteAuditController. + * Handles the generation of site audit reports. * * @package Drupal\site_audit\Controller */ class SiteAuditController extends ControllerBase { /** - * The Site Audit Report manager. - * - * @var \Drupal\site_audit\Plugin\SiteAuditReportManager - */ + * The Site Audit Report manager. + * + * @var \Drupal\site_audit\Plugin\SiteAuditReportManager + */ private $auditReportManager; /** @@ -30,6 +30,8 @@ class SiteAuditController extends ControllerBase { private $requestStack; /** + * Constructs a new \Drupal\site_audit\Controller\SiteAuditController object. + * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack @@ -39,9 +41,9 @@ class SiteAuditController extends ControllerBase { */ public function __construct(ConfigFactoryInterface $config_factory, RequestStack $requestStack, SiteAuditReportManager $auditReportManager) { $this->configFactory = $config_factory; - $this->auditReportManager = $auditReportManager; - $this->requestStack = $requestStack; - } + $this->auditReportManager = $auditReportManager; + $this->requestStack = $requestStack; + } /** * {@inheritdoc} @@ -84,9 +86,13 @@ class SiteAuditController extends ControllerBase { } } - $out = ''; - - $renderer = new Html($reports, NULL, ['detail' => TRUE, 'inline' => TRUE, 'uri' => \Drupal::request()->getHost()]); + $renderer = new Html($reports, NULL, + [ + 'detail' => TRUE, + 'inline' => TRUE, + 'uri' => \Drupal::request()->getHost(), + ] + ); return $renderer->render(TRUE); } diff --git a/src/Form/SiteAuditConfigForm.php b/src/Form/SiteAuditConfigForm.php index 04f7e7c..da4184a 100644 --- a/src/Form/SiteAuditConfigForm.php +++ b/src/Form/SiteAuditConfigForm.php @@ -11,25 +11,29 @@ use Drupal\site_audit\Plugin\SiteAuditReportManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * + * Configuration form for managing site audit reports. */ class SiteAuditConfigForm extends ConfigFormBase { /** + * The Site Audit Report Plugin Manager. + * * @var \Drupal\site_audit\Plugin\SiteAuditReportManager */ - protected $report_plugin_manager; + protected $reportPluginManager; /** - * SiteAuditConfigForm constructor. + * Constructs a new \Drupal\site_audit\Form\SiteAuditConfigForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * @param \Drupal\site_audit\Plugin\SiteAuditReportManager $site_audit_report_manager + * The configuration factory. + * @param \Drupal\site_audit\Plugin\SiteAuditReportManager $reportPluginManager + * The Site Audit Report Plugin Manager. */ - public function __construct(ConfigFactoryInterface $config_factory, SiteAuditReportManager $site_audit_report_manager) { + public function __construct(ConfigFactoryInterface $config_factory, SiteAuditReportManager $reportPluginManager) { parent::__construct($config_factory); - $this->report_plugin_manager = $site_audit_report_manager; + $this->reportPluginManager = $reportPluginManager; } /** @@ -62,7 +66,7 @@ class SiteAuditConfigForm extends ConfigFormBase { public function buildForm(array $form, FormStateInterface $form_state) { $options = []; $saved_options = $this->config('site_audit.settings')->get('reports'); - $reports = $this->report_plugin_manager->getDefinitions(); + $reports = $this->reportPluginManager->getDefinitions(); foreach ($reports as $report) { $options[$report['id']] = $report['name']; } diff --git a/src/Plugin/SiteAuditCheck/BestPracticesFast404.php b/src/Plugin/SiteAuditCheck/BestPracticesFast404.php index ca04978..3806812 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesFast404.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesFast404.php @@ -17,31 +17,31 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesFast404 extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Fast 404 pages are enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('Fast 404 pages are not enabled for any path.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -50,7 +50,7 @@ class BestPracticesFast404 extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $config = \Drupal::config('system.performance'); diff --git a/src/Plugin/SiteAuditCheck/BestPracticesFolderStructure.php b/src/Plugin/SiteAuditCheck/BestPracticesFolderStructure.php index 08d44a3..e2782de 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesFolderStructure.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesFolderStructure.php @@ -17,24 +17,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesFolderStructure extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('modules/contrib and modules/custom directories exist.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { if (!$this->registry->contrib && !$this->registry->custom) { @@ -49,7 +49,7 @@ class BestPracticesFolderStructure extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { $message = ''; @@ -68,7 +68,7 @@ class BestPracticesFolderStructure extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->contrib = is_dir(DRUPAL_ROOT . '/modules/contrib'); diff --git a/src/Plugin/SiteAuditCheck/BestPracticesMultisite.php b/src/Plugin/SiteAuditCheck/BestPracticesMultisite.php index 8558a85..9abe422 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesMultisite.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesMultisite.php @@ -17,7 +17,7 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesMultisite extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('The following multi-site configuration(s) were detected: @list', [ @@ -26,21 +26,21 @@ class BestPracticesMultisite extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultFail(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No multi-sites detected.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { if ($this->registry->multisite_enabled) { @@ -52,7 +52,7 @@ class BestPracticesMultisite extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { @@ -69,7 +69,7 @@ class BestPracticesMultisite extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $handle = opendir(DRUPAL_ROOT . '/sites/'); diff --git a/src/Plugin/SiteAuditCheck/BestPracticesServices.php b/src/Plugin/SiteAuditCheck/BestPracticesServices.php index 998ddf1..310a296 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesServices.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesServices.php @@ -17,31 +17,31 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesServices extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No site-specific services.yml file has been created.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('Site-specific services.yml in use.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -50,7 +50,7 @@ class BestPracticesServices extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { // Check if the services.yml file exists. @@ -60,4 +60,4 @@ class BestPracticesServices extends SiteAuditCheckBase { return SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS; } -} \ No newline at end of file +} diff --git a/src/Plugin/SiteAuditCheck/BestPracticesSettings.php b/src/Plugin/SiteAuditCheck/BestPracticesSettings.php index eced2ab..944ce2e 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesSettings.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesSettings.php @@ -17,35 +17,35 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesSettings extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('settings.php exists and is not a symbolic link.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('sites/default/settings.php is a symbolic link.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { - return $this->t('Don\'t rely on symbolic links for core configuration files; copy settings.php where it should be and remove the symbolic link.'); + return $this->t("Don't rely on symbolic links for core configuration files; copy settings.php where it should be and remove the symbolic link."); } if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { return $this->t('Even if environment settings are injected, create a stub settings.php file for compatibility.'); @@ -53,7 +53,7 @@ class BestPracticesSettings extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (file_exists(DRUPAL_ROOT . '/sites/default/settings.php')) { diff --git a/src/Plugin/SiteAuditCheck/BestPracticesSites.php b/src/Plugin/SiteAuditCheck/BestPracticesSites.php index 24d7111..82628f1 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesSites.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesSites.php @@ -17,17 +17,17 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesSites extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { if ($this->registry->multisite_enabled) { @@ -39,23 +39,23 @@ class BestPracticesSites extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('sites/sites.php is a symbolic link.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { - return $this->t('Don\'t rely on symbolic links for core configuration files; copy sites.php where it should be and remove the symbolic link.'); + return $this->t("Don't rely on symbolic links for core configuration files; copy sites.php where it should be and remove the symbolic link."); } } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->multisite_enabled = file_exists(DRUPAL_ROOT . '/sites/sites.php'); diff --git a/src/Plugin/SiteAuditCheck/BestPracticesSitesDefault.php b/src/Plugin/SiteAuditCheck/BestPracticesSitesDefault.php index 37bd07d..b4951a9 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesSitesDefault.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesSitesDefault.php @@ -17,47 +17,47 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesSitesDefault extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('sites/default does not exist!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('sites/default is a directory and not a symbolic link.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('sites/default exists as a symbolic link.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { return $this->t('sites/default is necessary; recreate the directory immediately.'); } if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { - return $this->t('Avoid changing Drupal\'s site structure; remove the symbolic link and recreate sites/default.'); + return $this->t("Avoid changing Drupal's site structure; remove the symbolic link and recreate sites/default."); } } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (is_dir(DRUPAL_ROOT . '/sites/default')) { diff --git a/src/Plugin/SiteAuditCheck/BestPracticesSitesSuperfluous.php b/src/Plugin/SiteAuditCheck/BestPracticesSitesSuperfluous.php index 1b3d29a..e32fac4 100644 --- a/src/Plugin/SiteAuditCheck/BestPracticesSitesSuperfluous.php +++ b/src/Plugin/SiteAuditCheck/BestPracticesSitesSuperfluous.php @@ -17,24 +17,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BestPracticesSitesSuperfluous extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No unnecessary files detected.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('The following extra files were detected: @list', [ @@ -43,16 +43,16 @@ class BestPracticesSitesSuperfluous extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { - return $this->t('Unless you have an explicit need for it, don\'t store anything other than settings here.'); + return $this->t("Unless you have an explicit need for it, don't store anything other than settings here."); } } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $handle = opendir(DRUPAL_ROOT . '/sites/'); diff --git a/src/Plugin/SiteAuditCheck/BlockEnabled.php b/src/Plugin/SiteAuditCheck/BlockEnabled.php index 679c48c..d29d99d 100644 --- a/src/Plugin/SiteAuditCheck/BlockEnabled.php +++ b/src/Plugin/SiteAuditCheck/BlockEnabled.php @@ -17,40 +17,40 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class BlockEnabled extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('Block caching is not enabled!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Block is not enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Block is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t("Block is enabled, but there is no default theme. Consider disabling block if you don't need it."); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!\Drupal::service('module_handler')->moduleExists('block')) { diff --git a/src/Plugin/SiteAuditCheck/CacheBinsAll.php b/src/Plugin/SiteAuditCheck/CacheBinsAll.php index 8a86109..fdf2d8f 100644 --- a/src/Plugin/SiteAuditCheck/CacheBinsAll.php +++ b/src/Plugin/SiteAuditCheck/CacheBinsAll.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CacheBinsAll extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $ret_val = [ @@ -38,22 +38,22 @@ class CacheBinsAll extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $container = \Drupal::getContainer(); diff --git a/src/Plugin/SiteAuditCheck/CacheBinsDefault.php b/src/Plugin/SiteAuditCheck/CacheBinsDefault.php index 281d85d..ad241af 100644 --- a/src/Plugin/SiteAuditCheck/CacheBinsDefault.php +++ b/src/Plugin/SiteAuditCheck/CacheBinsDefault.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CacheBinsDefault extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $ret_val = [ @@ -38,22 +38,22 @@ class CacheBinsDefault extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $container = \Drupal::getContainer(); diff --git a/src/Plugin/SiteAuditCheck/CacheBinsUsed.php b/src/Plugin/SiteAuditCheck/CacheBinsUsed.php index ba2e1f8..bb8acdb 100644 --- a/src/Plugin/SiteAuditCheck/CacheBinsUsed.php +++ b/src/Plugin/SiteAuditCheck/CacheBinsUsed.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CacheBinsUsed extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $ret_val = [ @@ -37,22 +37,22 @@ class CacheBinsUsed extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $container = \Drupal::getContainer(); diff --git a/src/Plugin/SiteAuditCheck/CachePageExpire.php b/src/Plugin/SiteAuditCheck/CachePageExpire.php index 5e8eac9..8d85460 100644 --- a/src/Plugin/SiteAuditCheck/CachePageExpire.php +++ b/src/Plugin/SiteAuditCheck/CachePageExpire.php @@ -17,21 +17,21 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CachePageExpire extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('Expiration of cached pages not set!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultFail(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Expiration of cached pages is set to @minutes min.', [ @@ -40,7 +40,7 @@ class CachePageExpire extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('Expiration of cached pages only set to @minutes min.', [ @@ -49,12 +49,12 @@ class CachePageExpire extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $config = \Drupal::config('system.performance')->get('cache.page.max_age'); diff --git a/src/Plugin/SiteAuditCheck/CachePreprocessCSS.php b/src/Plugin/SiteAuditCheck/CachePreprocessCSS.php index 2c10fb6..400c829 100644 --- a/src/Plugin/SiteAuditCheck/CachePreprocessCSS.php +++ b/src/Plugin/SiteAuditCheck/CachePreprocessCSS.php @@ -17,33 +17,33 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CachePreprocessCSS extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('CSS aggregation and compression is not enabled!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultFail(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('CSS aggregation and compression is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if (!in_array($this->score, [SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS])) { @@ -52,7 +52,7 @@ class CachePreprocessCSS extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $config = \Drupal::config('system.performance')->get('css.preprocess'); diff --git a/src/Plugin/SiteAuditCheck/CachePreprocessJS.php b/src/Plugin/SiteAuditCheck/CachePreprocessJS.php index ff4152b..90c9086 100644 --- a/src/Plugin/SiteAuditCheck/CachePreprocessJS.php +++ b/src/Plugin/SiteAuditCheck/CachePreprocessJS.php @@ -17,33 +17,33 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CachePreprocessJS extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('JavaScript aggregation is not enabled!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultFail(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('JavaScript aggregation is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if (!in_array($this->score, [SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS])) { @@ -52,7 +52,7 @@ class CachePreprocessJS extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $config = \Drupal::config('system.performance')->get('js.preprocess'); diff --git a/src/Plugin/SiteAuditCheck/CodebaseSizeAll.php b/src/Plugin/SiteAuditCheck/CodebaseSizeAll.php index 2c0b258..72c6b7c 100644 --- a/src/Plugin/SiteAuditCheck/CodebaseSizeAll.php +++ b/src/Plugin/SiteAuditCheck/CodebaseSizeAll.php @@ -18,14 +18,14 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CodebaseSizeAll extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('Empty, or unable to determine the size due to a permission error.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { @@ -35,22 +35,22 @@ class CodebaseSizeAll extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { try { diff --git a/src/Plugin/SiteAuditCheck/ContentDuplicateTitles.php b/src/Plugin/SiteAuditCheck/ContentDuplicateTitles.php index 7ccc419..8f87c2a 100644 --- a/src/Plugin/SiteAuditCheck/ContentDuplicateTitles.php +++ b/src/Plugin/SiteAuditCheck/ContentDuplicateTitles.php @@ -18,26 +18,26 @@ use Drupal\site_audit\Renderer\Html; class ContentDuplicateTitles extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('No nodes exist, which also means no duplicate titles.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No nodes with duplicate titles exist.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { $ret_val = [ @@ -62,7 +62,7 @@ class ContentDuplicateTitles extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -71,7 +71,7 @@ class ContentDuplicateTitles extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->content_entity_type_counts)) { diff --git a/src/Plugin/SiteAuditCheck/ContentEntityTypes.php b/src/Plugin/SiteAuditCheck/ContentEntityTypes.php index 94d39ff..0330873 100644 --- a/src/Plugin/SiteAuditCheck/ContentEntityTypes.php +++ b/src/Plugin/SiteAuditCheck/ContentEntityTypes.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentEntityTypes extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $ret_val = ''; @@ -59,31 +59,32 @@ class ContentEntityTypes extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this)) { return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO; } $all_bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo(); - // This might have already been run by Drupal\site_audit\Plugin\SiteAuditCheck\ContentEntityTypesUnused + // This might have already been run by + // Drupal\site_audit\Plugin\SiteAuditCheck\ContentEntityTypesUnused // if so we don't need to do it again. if (!isset($this->registry->content_entity_type_counts)) { $this->registry->content_types_unused = []; diff --git a/src/Plugin/SiteAuditCheck/ContentEntityTypesUnused.php b/src/Plugin/SiteAuditCheck/ContentEntityTypesUnused.php index dd7a4d2..0fde8b7 100644 --- a/src/Plugin/SiteAuditCheck/ContentEntityTypesUnused.php +++ b/src/Plugin/SiteAuditCheck/ContentEntityTypesUnused.php @@ -17,24 +17,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentEntityTypesUnused extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('There are no unused content types.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { $report = []; @@ -47,7 +47,7 @@ class ContentEntityTypesUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -56,7 +56,7 @@ class ContentEntityTypesUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->content_types_unused)) { diff --git a/src/Plugin/SiteAuditCheck/ContentFieldCount.php b/src/Plugin/SiteAuditCheck/ContentFieldCount.php index d18a445..79e9580 100644 --- a/src/Plugin/SiteAuditCheck/ContentFieldCount.php +++ b/src/Plugin/SiteAuditCheck/ContentFieldCount.php @@ -18,14 +18,14 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentFieldCount extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('There are no fields available!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $table_rows = []; @@ -51,12 +51,12 @@ class ContentFieldCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('There are @count total fields, which is higher than average', [ @@ -65,7 +65,7 @@ class ContentFieldCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { @@ -74,7 +74,7 @@ class ContentFieldCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->fields)) { diff --git a/src/Plugin/SiteAuditCheck/ContentFieldEnabled.php b/src/Plugin/SiteAuditCheck/ContentFieldEnabled.php index d042e5d..d419f6a 100644 --- a/src/Plugin/SiteAuditCheck/ContentFieldEnabled.php +++ b/src/Plugin/SiteAuditCheck/ContentFieldEnabled.php @@ -18,36 +18,36 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentFieldEnabled extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Field is not enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Field is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!\Drupal::moduleHandler()->moduleExists('field')) { diff --git a/src/Plugin/SiteAuditCheck/ContentFieldInstances.php b/src/Plugin/SiteAuditCheck/ContentFieldInstances.php index 6da9178..7a311cf 100644 --- a/src/Plugin/SiteAuditCheck/ContentFieldInstances.php +++ b/src/Plugin/SiteAuditCheck/ContentFieldInstances.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentFieldInstances extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $table_rows = []; @@ -54,22 +54,22 @@ class ContentFieldInstances extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->fields)) { @@ -96,14 +96,17 @@ class ContentFieldInstances extends SiteAuditCheckBase { ->condition('bundle', $bundle); $field_count = $query->countQuery()->execute()->fetchField(); break; + case 'office_hours': $table = $entity . '__' . $field; - $field_count = $this->custom_field_count($bundle, $table, $field . '_starthours'); + $field_count = $this->customFieldCount($bundle, $table, $field . '_starthours'); break; + case 'name': $table = $entity . '__' . $field; - $field_count = $this->custom_field_count($bundle, $table, $field . '_given'); + $field_count = $this->customFieldCount($bundle, $table, $field . '_given'); break; + default: $query = \Drupal::entityQuery($entity); if (!empty($bundle_column_name)) { @@ -126,20 +129,24 @@ class ContentFieldInstances extends SiteAuditCheckBase { } /** - * use a custom field to get the field count instead of the basic _value - * column that doesn't always exist + * Use custom field count instead of basic _value column. * - * @param $bundle - * @param $table - * @param $field + * @param string $bundle + * The bundle of the entity. + * @param string $table + * The table name where the field is stored. + * @param string $field + * The field name to count. * * @return mixed + * The count of the specified field for the given bundle. */ - function custom_field_count($bundle, $table, $field) { + public function customFieldCount($bundle, $table, $field) { $query = $this->db->select($table); $query->condition($field, NULL, 'IS NOT NULL') ->condition('bundle', $bundle); $field_count = $query->countQuery()->execute()->fetchField(); return $field_count; } + } diff --git a/src/Plugin/SiteAuditCheck/ContentFieldsUnused.php b/src/Plugin/SiteAuditCheck/ContentFieldsUnused.php index e963ba2..044f2c6 100644 --- a/src/Plugin/SiteAuditCheck/ContentFieldsUnused.php +++ b/src/Plugin/SiteAuditCheck/ContentFieldsUnused.php @@ -17,24 +17,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentFieldsUnused extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('There are no unused fields.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { $report = []; @@ -47,7 +47,7 @@ class ContentFieldsUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -56,7 +56,7 @@ class ContentFieldsUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->fields_unused = []; diff --git a/src/Plugin/SiteAuditCheck/ContentTaxonomy.php b/src/Plugin/SiteAuditCheck/ContentTaxonomy.php index 415c6f7..2673d4f 100644 --- a/src/Plugin/SiteAuditCheck/ContentTaxonomy.php +++ b/src/Plugin/SiteAuditCheck/ContentTaxonomy.php @@ -18,36 +18,36 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentTaxonomy extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Taxonomy module is not enabled'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Taxonomy module is enabled'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (\Drupal::moduleHandler()->moduleExists('taxonomy')) { diff --git a/src/Plugin/SiteAuditCheck/ContentVocabularies.php b/src/Plugin/SiteAuditCheck/ContentVocabularies.php index c41a718..3a22246 100644 --- a/src/Plugin/SiteAuditCheck/ContentVocabularies.php +++ b/src/Plugin/SiteAuditCheck/ContentVocabularies.php @@ -18,12 +18,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentVocabularies extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { if (!isset($this->registry->vocabulary_counts)) { @@ -35,8 +35,6 @@ class ContentVocabularies extends SiteAuditCheckBase { } return ''; } - $ret_val = ''; - $table_rows = []; foreach ($this->registry->vocabulary_counts as $vocabulary => $count) { $table_rows[] = [ @@ -58,24 +56,24 @@ class ContentVocabularies extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!\Drupal::moduleHandler()->moduleExists('taxonomy')) { diff --git a/src/Plugin/SiteAuditCheck/ContentVocabulariesUnused.php b/src/Plugin/SiteAuditCheck/ContentVocabulariesUnused.php index 8031fe0..1d44dea 100644 --- a/src/Plugin/SiteAuditCheck/ContentVocabulariesUnused.php +++ b/src/Plugin/SiteAuditCheck/ContentVocabulariesUnused.php @@ -18,24 +18,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ContentVocabulariesUnused extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('There are no unused vocabularies.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('The following vocabularies are unused: @vocabularies_unused', [ @@ -44,7 +44,7 @@ class ContentVocabulariesUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -53,7 +53,7 @@ class ContentVocabulariesUnused extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->vocabulary_unused)) { diff --git a/src/Plugin/SiteAuditCheck/CronEnabled.php b/src/Plugin/SiteAuditCheck/CronEnabled.php index 3416b23..bd3becc 100644 --- a/src/Plugin/SiteAuditCheck/CronEnabled.php +++ b/src/Plugin/SiteAuditCheck/CronEnabled.php @@ -17,19 +17,19 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CronEnabled extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('You have disabled cron, which will prevent routine system tasks from executing.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { // Manual execution. @@ -43,19 +43,19 @@ class CronEnabled extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { if ($this->registry->cron_safe_threshold > (24 * 60 * 60)) { return $this->t('Drupal Cron frequency is set to mare than 24 hours.'); } else { - return $this->t('Drupal Cron has not run in the past day even though it\'s frequency has been set to less than 24 hours.'); + return $this->t("Drupal Cron has not run in the past day even though it's frequency has been set to less than 24 hours."); } } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { @@ -69,7 +69,7 @@ class CronEnabled extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { // Determine when cron last ran. diff --git a/src/Plugin/SiteAuditCheck/CronLast.php b/src/Plugin/SiteAuditCheck/CronLast.php index 60724a6..4542adb 100644 --- a/src/Plugin/SiteAuditCheck/CronLast.php +++ b/src/Plugin/SiteAuditCheck/CronLast.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class CronLast extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { if ($this->registry->cron_last) { @@ -35,22 +35,22 @@ class CronLast extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO; diff --git a/src/Plugin/SiteAuditCheck/DatabaseCollation.php b/src/Plugin/SiteAuditCheck/DatabaseCollation.php index e2c3d6d..a10e49d 100644 --- a/src/Plugin/SiteAuditCheck/DatabaseCollation.php +++ b/src/Plugin/SiteAuditCheck/DatabaseCollation.php @@ -18,12 +18,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class DatabaseCollation extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { // If ($this->options['html']) {. @@ -58,21 +58,21 @@ class DatabaseCollation extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Every table is using UTF-8.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -83,7 +83,7 @@ class DatabaseCollation extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $connection = Database::getConnection(); diff --git a/src/Plugin/SiteAuditCheck/DatabaseEngine.php b/src/Plugin/SiteAuditCheck/DatabaseEngine.php index 893c1fc..d04818f 100644 --- a/src/Plugin/SiteAuditCheck/DatabaseEngine.php +++ b/src/Plugin/SiteAuditCheck/DatabaseEngine.php @@ -18,7 +18,7 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class DatabaseEngine extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { // If ($this->options['html']) {. @@ -53,24 +53,24 @@ class DatabaseEngine extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Every table is using InnoDB.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) { @@ -81,7 +81,7 @@ class DatabaseEngine extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $connection = Database::getConnection(); diff --git a/src/Plugin/SiteAuditCheck/DatabaseFragmentation.php b/src/Plugin/SiteAuditCheck/DatabaseFragmentation.php index 2d29bc0..1b89971 100644 --- a/src/Plugin/SiteAuditCheck/DatabaseFragmentation.php +++ b/src/Plugin/SiteAuditCheck/DatabaseFragmentation.php @@ -18,22 +18,22 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class DatabaseFragmentation extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { arsort($this->registry->database_fragmentation); @@ -56,7 +56,7 @@ class DatabaseFragmentation extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -65,7 +65,7 @@ class DatabaseFragmentation extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $connection = Database::getConnection(); diff --git a/src/Plugin/SiteAuditCheck/DatabaseRowCount.php b/src/Plugin/SiteAuditCheck/DatabaseRowCount.php index 240a0cb..5615aed 100644 --- a/src/Plugin/SiteAuditCheck/DatabaseRowCount.php +++ b/src/Plugin/SiteAuditCheck/DatabaseRowCount.php @@ -18,12 +18,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class DatabaseRowCount extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { if (empty($this->registry->rows_by_table)) { @@ -50,24 +50,24 @@ class DatabaseRowCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $connection = Database::getConnection(); diff --git a/src/Plugin/SiteAuditCheck/DatabaseSize.php b/src/Plugin/SiteAuditCheck/DatabaseSize.php index 33ba6fa..9b156fb 100644 --- a/src/Plugin/SiteAuditCheck/DatabaseSize.php +++ b/src/Plugin/SiteAuditCheck/DatabaseSize.php @@ -19,14 +19,14 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class DatabaseSize extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('Empty, or unable to determine the size due to a permission error.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Total size: @size_in_mbMB', [ @@ -35,22 +35,22 @@ class DatabaseSize extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $connection = Database::getConnection(); diff --git a/src/Plugin/SiteAuditCheck/ExtensionsCount.php b/src/Plugin/SiteAuditCheck/ExtensionsCount.php index 8d0501d..d53391a 100644 --- a/src/Plugin/SiteAuditCheck/ExtensionsCount.php +++ b/src/Plugin/SiteAuditCheck/ExtensionsCount.php @@ -17,17 +17,17 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ExtensionsCount extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('There are @extension_count extensions enabled.', [ @@ -36,16 +36,16 @@ class ExtensionsCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { - return $this->t('There are @extension_count extensions enabled; that\'s higher than the average.', [ + return $this->t("There are @extension_count extensions enabled; that's higher than the average.", [ '@extension_count' => $this->registry->extension_count, ]); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) { @@ -80,7 +80,7 @@ class ExtensionsCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->extensions) || empty($this->registry->extensions)) { diff --git a/src/Plugin/SiteAuditCheck/ExtensionsDev.php b/src/Plugin/SiteAuditCheck/ExtensionsDev.php index a708eba..ab7100d 100644 --- a/src/Plugin/SiteAuditCheck/ExtensionsDev.php +++ b/src/Plugin/SiteAuditCheck/ExtensionsDev.php @@ -17,26 +17,26 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ExtensionsDev extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultWarn(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No enabled development extensions were detected; no action required.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { $ret_val = $this->t('The following development modules(s) are currently enabled: @list', [ @@ -65,7 +65,7 @@ class ExtensionsDev extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -80,7 +80,7 @@ class ExtensionsDev extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->extensions) || empty($this->registry->extensions)) { diff --git a/src/Plugin/SiteAuditCheck/ExtensionsDuplicate.php b/src/Plugin/SiteAuditCheck/ExtensionsDuplicate.php index f6e733a..7e878b3 100644 --- a/src/Plugin/SiteAuditCheck/ExtensionsDuplicate.php +++ b/src/Plugin/SiteAuditCheck/ExtensionsDuplicate.php @@ -17,24 +17,24 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ExtensionsDuplicate extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No duplicate extensions were detected.', []); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { $paths = []; @@ -81,7 +81,7 @@ class ExtensionsDuplicate extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) { @@ -90,7 +90,7 @@ class ExtensionsDuplicate extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $extension_list = \Drupal::service('extension.list.module'); diff --git a/src/Plugin/SiteAuditCheck/ExtensionsUnrecommended.php b/src/Plugin/SiteAuditCheck/ExtensionsUnrecommended.php index 3774e2d..180e5e2 100644 --- a/src/Plugin/SiteAuditCheck/ExtensionsUnrecommended.php +++ b/src/Plugin/SiteAuditCheck/ExtensionsUnrecommended.php @@ -17,7 +17,7 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ExtensionsUnrecommended extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { $ret_val = $this->t('The following unrecommended modules(s) currently exist in your codebase: @list', [ @@ -51,28 +51,28 @@ class ExtensionsUnrecommended extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No unrecommended extensions were detected; no action required.', []); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { - return $this->t('There are @extension_count extensions enabled; that\'s higher than the average.', [ + return $this->t("There are @extension_count extensions enabled; that's higher than the average.", [ '@extension_count' => $this->registry->extension_count, ]); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->getScore() != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) { @@ -81,7 +81,7 @@ class ExtensionsUnrecommended extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->extensions_unrec = []; diff --git a/src/Plugin/SiteAuditCheck/SecurityMenuRouter.php b/src/Plugin/SiteAuditCheck/SecurityMenuRouter.php index fdeea02..47abbce 100644 --- a/src/Plugin/SiteAuditCheck/SecurityMenuRouter.php +++ b/src/Plugin/SiteAuditCheck/SecurityMenuRouter.php @@ -17,7 +17,7 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class SecurityMenuRouter extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { $ret_val = $this->t('The following potentially malicious paths have been discovered: @list', [ @@ -56,24 +56,24 @@ class SecurityMenuRouter extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No known potentially malicious entries were detected in the menu_router table.', []); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL) { @@ -82,7 +82,7 @@ class SecurityMenuRouter extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { // DRUPAL SA-CORE-2014-005 Exploits. diff --git a/src/Plugin/SiteAuditCheck/StatusSystem.php b/src/Plugin/SiteAuditCheck/StatusSystem.php index 6b7dc62..094f70d 100644 --- a/src/Plugin/SiteAuditCheck/StatusSystem.php +++ b/src/Plugin/SiteAuditCheck/StatusSystem.php @@ -17,19 +17,19 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class StatusSystem extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->getResultPass(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { $items = []; @@ -80,6 +80,7 @@ class StatusSystem extends SiteAuditCheckBase { case 'warning': $classes[] = 'label-warning'; break; + case 'error': $classes[] = 'label-danger'; break; @@ -97,19 +98,19 @@ class StatusSystem extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultPass(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { // See system/system.admin.inc function system_status(). diff --git a/src/Plugin/SiteAuditCheck/UsersBlockedNumberOne.php b/src/Plugin/SiteAuditCheck/UsersBlockedNumberOne.php index 6ef704a..1024a31 100644 --- a/src/Plugin/SiteAuditCheck/UsersBlockedNumberOne.php +++ b/src/Plugin/SiteAuditCheck/UsersBlockedNumberOne.php @@ -17,31 +17,31 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class UsersBlockedNumberOne extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('UID #1 is not blocked!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('UID #1 is blocked.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) { @@ -50,7 +50,7 @@ class UsersBlockedNumberOne extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $query = \Drupal::database()->select('users_field_data', 'ufd'); diff --git a/src/Plugin/SiteAuditCheck/UsersCountAll.php b/src/Plugin/SiteAuditCheck/UsersCountAll.php index 5c78110..b638956 100644 --- a/src/Plugin/SiteAuditCheck/UsersCountAll.php +++ b/src/Plugin/SiteAuditCheck/UsersCountAll.php @@ -18,36 +18,36 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class UsersCountAll extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('There are no users!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->formatPlural($this->registry->count_users_all, 'There is one user.', 'There are @count users.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $query = \Drupal::database()->select('users'); diff --git a/src/Plugin/SiteAuditCheck/UsersCountBlocked.php b/src/Plugin/SiteAuditCheck/UsersCountBlocked.php index f843952..b8c4c0a 100644 --- a/src/Plugin/SiteAuditCheck/UsersCountBlocked.php +++ b/src/Plugin/SiteAuditCheck/UsersCountBlocked.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class UsersCountBlocked extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { switch ($this->registry->count_users_blocked) { @@ -37,22 +37,22 @@ class UsersCountBlocked extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $query = \Drupal::database()->select('users_field_data', 'ufd'); diff --git a/src/Plugin/SiteAuditCheck/UsersRolesList.php b/src/Plugin/SiteAuditCheck/UsersRolesList.php index e41731e..09559ee 100644 --- a/src/Plugin/SiteAuditCheck/UsersRolesList.php +++ b/src/Plugin/SiteAuditCheck/UsersRolesList.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class UsersRolesList extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $counts = []; @@ -35,22 +35,22 @@ class UsersRolesList extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $query = \Drupal::database()->select('user__roles'); diff --git a/src/Plugin/SiteAuditCheck/UsersWhoIsNumberOne.php b/src/Plugin/SiteAuditCheck/UsersWhoIsNumberOne.php index d2aed54..d55e29c 100644 --- a/src/Plugin/SiteAuditCheck/UsersWhoIsNumberOne.php +++ b/src/Plugin/SiteAuditCheck/UsersWhoIsNumberOne.php @@ -19,14 +19,14 @@ use Drupal\user\Entity\User; class UsersWhoIsNumberOne extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('UID #1 does not exist! This is a serious problem.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('UID #1: @name, email: @mail', [ @@ -36,22 +36,22 @@ class UsersWhoIsNumberOne extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $uid_1 = User::load(1); diff --git a/src/Plugin/SiteAuditCheck/ViewsCacheOutput.php b/src/Plugin/SiteAuditCheck/ViewsCacheOutput.php index 6d617ab..41e1309 100644 --- a/src/Plugin/SiteAuditCheck/ViewsCacheOutput.php +++ b/src/Plugin/SiteAuditCheck/ViewsCacheOutput.php @@ -17,28 +17,28 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ViewsCacheOutput extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('No View is caching rendered output!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultWarn(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Every View is caching rendered output.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('The following Views are not caching rendered output: @views_without_output_caching', [ @@ -47,10 +47,16 @@ class ViewsCacheOutput extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { - if (!in_array($this->score, [SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO, SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS])) { + if (!in_array( + $this->score, + [ + SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO, + SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS, + ] + )) { $ret_val = $this->t('Rendered output should be cached for as long as possible (if the query changes, the output will be refreshed).'); $steps = [ @@ -62,7 +68,7 @@ class ViewsCacheOutput extends SiteAuditCheckBase { $this->t('Caching: (something other than None)'), ]; $ret_val = [ - '#theme' => 'item_list', + '#theme' => 'itemList', '#title' => $this->t('Rendered output should be cached for as long as possible (if the query changes, the output will be refreshed).'), // '#description' => $this->t(), '#items' => $steps, @@ -74,7 +80,7 @@ class ViewsCacheOutput extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->output_lifespan = []; diff --git a/src/Plugin/SiteAuditCheck/ViewsCacheResults.php b/src/Plugin/SiteAuditCheck/ViewsCacheResults.php index 4d25c0a..1d1e7dd 100644 --- a/src/Plugin/SiteAuditCheck/ViewsCacheResults.php +++ b/src/Plugin/SiteAuditCheck/ViewsCacheResults.php @@ -17,28 +17,28 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ViewsCacheResults extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('No View is caching query results!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->getResultWarn(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Every View is caching query results.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->t('The following Views are not caching query results: @views_without_results_caching', [ @@ -47,10 +47,16 @@ class ViewsCacheResults extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { - if (!in_array($this->score, [SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO, SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS])) { + if (!in_array( + $this->score, + [ + SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO, + SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS, + ] + )) { $steps = [ $this->t('Go to /admin/structure/views/'), $this->t('Edit the View in question'), @@ -61,7 +67,7 @@ class ViewsCacheResults extends SiteAuditCheckBase { ]; return [ - '#theme' => 'item_list', + '#theme' => 'itemList', '#title' => $this->t('Query results should be cached for at least 1 minute or use tag caching.'), // '#description' => $this->t(), '#items' => $steps, @@ -71,7 +77,7 @@ class ViewsCacheResults extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->results_lifespan = []; diff --git a/src/Plugin/SiteAuditCheck/ViewsCount.php b/src/Plugin/SiteAuditCheck/ViewsCount.php index 98b11cb..fb30f29 100644 --- a/src/Plugin/SiteAuditCheck/ViewsCount.php +++ b/src/Plugin/SiteAuditCheck/ViewsCount.php @@ -19,17 +19,17 @@ use Drupal\views\Views; class ViewsCount extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { $views_count = count($this->registry->views); @@ -42,23 +42,23 @@ class ViewsCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultPass(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { - return $this->t('Consider disabling the views module if you don\'t need it.'); + return $this->t("Consider disabling the views module if you don't need it."); } } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->views = []; diff --git a/src/Plugin/SiteAuditCheck/ViewsEnabled.php b/src/Plugin/SiteAuditCheck/ViewsEnabled.php index 1727532..22fcc70 100644 --- a/src/Plugin/SiteAuditCheck/ViewsEnabled.php +++ b/src/Plugin/SiteAuditCheck/ViewsEnabled.php @@ -18,36 +18,36 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class ViewsEnabled extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Views is not enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Views is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!\Drupal::moduleHandler()->moduleExists('views')) { diff --git a/src/Plugin/SiteAuditCheck/Watchdog404.php b/src/Plugin/SiteAuditCheck/Watchdog404.php index 14fbb02..12e05d6 100644 --- a/src/Plugin/SiteAuditCheck/Watchdog404.php +++ b/src/Plugin/SiteAuditCheck/Watchdog404.php @@ -17,12 +17,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class Watchdog404 extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('@count_404 pages not found (@percent_404%).', [ @@ -32,21 +32,21 @@ class Watchdog404 extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No 404 entries.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -55,7 +55,7 @@ class Watchdog404 extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (empty($this->registry->count_entries)) { @@ -71,7 +71,7 @@ class Watchdog404 extends SiteAuditCheckBase { $this->registry->percent_404 = 0; - // @TODO: Aggregate 404 entries and return top 10. + // @todo Aggregate 404 entries and return top 10. if (!$this->registry->count_404) { return SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS; } diff --git a/src/Plugin/SiteAuditCheck/WatchdogAge.php b/src/Plugin/SiteAuditCheck/WatchdogAge.php index 2b99b73..8ff5574 100644 --- a/src/Plugin/SiteAuditCheck/WatchdogAge.php +++ b/src/Plugin/SiteAuditCheck/WatchdogAge.php @@ -15,16 +15,28 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; * ) */ class WatchdogAge extends SiteAuditCheckBase { + + /** + * The timestamp of the newest log entry. + * + * @var int + */ public $ageNewest; + + /** + * The timestamp of the oldest log entry. + * + * @var int + */ public $ageOldest; /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { // If two different days... @@ -43,22 +55,22 @@ class WatchdogAge extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { // Age of oldest entry. diff --git a/src/Plugin/SiteAuditCheck/WatchdogCount.php b/src/Plugin/SiteAuditCheck/WatchdogCount.php index 8bd82b3..3c120d8 100644 --- a/src/Plugin/SiteAuditCheck/WatchdogCount.php +++ b/src/Plugin/SiteAuditCheck/WatchdogCount.php @@ -18,12 +18,12 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class WatchdogCount extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { if (!$this->registry->count_entries) { @@ -35,22 +35,22 @@ class WatchdogCount extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!isset($this->registry->watchdog_enabled)) { diff --git a/src/Plugin/SiteAuditCheck/WatchdogEnabled.php b/src/Plugin/SiteAuditCheck/WatchdogEnabled.php index 4aa06e3..9ee9822 100644 --- a/src/Plugin/SiteAuditCheck/WatchdogEnabled.php +++ b/src/Plugin/SiteAuditCheck/WatchdogEnabled.php @@ -18,36 +18,36 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class WatchdogEnabled extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { return $this->t('Database logging (dblog) is not enabled; if the site is having problems, consider enabling it for debugging.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('Database logging (dblog) is enabled.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { if (!\Drupal::moduleHandler()->moduleExists('dblog')) { diff --git a/src/Plugin/SiteAuditCheck/WatchdogPhp.php b/src/Plugin/SiteAuditCheck/WatchdogPhp.php index d3d001e..525458f 100644 --- a/src/Plugin/SiteAuditCheck/WatchdogPhp.php +++ b/src/Plugin/SiteAuditCheck/WatchdogPhp.php @@ -19,12 +19,12 @@ use Drupal\Core\Logger\RfcLogLevel; class WatchdogPhp extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { $counts = []; @@ -37,21 +37,21 @@ class WatchdogPhp extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->t('No PHP warnings, notices or errors.'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) { @@ -60,7 +60,7 @@ class WatchdogPhp extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->php_counts = []; @@ -74,7 +74,7 @@ class WatchdogPhp extends SiteAuditCheckBase { $query->orderBy('severity', 'ASC'); $result = $query->execute(); - $severity_levels = $this->watchdog_severity_levels(); + $severity_levels = $this->watchdogSeverityLevels(); while ($row = $result->fetchObject()) { $row->severity = $severity_levels[$row->severity]; // $row = watchdog_format_result($result); @@ -97,7 +97,7 @@ class WatchdogPhp extends SiteAuditCheckBase { * * @see drush_watchdog_severity_levels() */ - public function watchdog_severity_levels() { + public function watchdogSeverityLevels() { return [ RfcLogLevel::EMERGENCY => 'emergency', RfcLogLevel::ALERT => 'alert', diff --git a/src/Plugin/SiteAuditCheck/WatchdogSyslog.php b/src/Plugin/SiteAuditCheck/WatchdogSyslog.php index d3b318b..9a215f2 100644 --- a/src/Plugin/SiteAuditCheck/WatchdogSyslog.php +++ b/src/Plugin/SiteAuditCheck/WatchdogSyslog.php @@ -18,14 +18,14 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; class WatchdogSyslog extends SiteAuditCheckBase { /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultFail() { return $this->t('Syslog logging is enabled!'); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultInfo() { if ($this->registry->syslog_enabled) { @@ -35,40 +35,38 @@ class WatchdogSyslog extends SiteAuditCheckBase { } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultPass() { return $this->getResultInfo(); } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getResultWarn() {} /** - * {@inheritdoc}. + * {@inheritdoc} */ public function getAction() { - /* TODO configure settings in the web interface and from the DRUSH command line - if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL && $this->options['vendor'] == 'pantheon') { - return $this->t('On Pantheon, you can technically write to syslog, but there is no mechanism for reading it. Disable syslog and enable dblog instead.'); - } - */ + // @todo configure settings in the web interface and from the + // DRUSH command line + // if ($this->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL && $this->options['vendor'] == 'pantheon') { + // return $this->t('On Pantheon, you can technically write to syslog, but there is no mechanism for reading it. Disable syslog and enable dblog instead.'); + // }. } /** - * {@inheritdoc}. + * {@inheritdoc} */ public function calculateScore() { $this->registry->syslog_enabled = \Drupal::moduleHandler()->moduleExists('syslog'); if ($this->registry->syslog_enabled) { - /** - * TODO sonfigure settings in the web interface and from the DRUSH command line - * if ($this->options['vendor'] == 'pantheon') { - * return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL; - * } - */ + // @todo sonfigure settings in the web interface and from the DRUSH command line + // if ($this->options['vendor'] == 'pantheon') { + // return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL; + // } } return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO; } diff --git a/src/Plugin/SiteAuditCheckBase.php b/src/Plugin/SiteAuditCheckBase.php index 6a73a72..4812ea0 100644 --- a/src/Plugin/SiteAuditCheckBase.php +++ b/src/Plugin/SiteAuditCheckBase.php @@ -2,6 +2,7 @@ namespace Drupal\site_audit\Plugin; +use Drupal\Core\Logger\LoggerChannelFactory; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Database\Connection; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -70,25 +71,34 @@ abstract class SiteAuditCheckBase extends PluginBase implements SiteAuditCheckIn protected $options = []; /** + * The database connection. + * * @var \Drupal\Core\Database\Connection */ protected $db; /** + * The logger. + * * @var \Psr\Log\LoggerInterface */ protected $logger; /** - * Constructor. + * Constructs a new \Drupal\site_audit\Plugin\SiteAuditCheckBase object. * - * @param $configuration - * @param $plugin_id - * @param $plugin_definition + * @param array $configuration + * The plugin configuration. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definition. * @param \Drupal\Core\Database\Connection $database + * The database connection. * @param \Drupal\Core\Logger\LoggerChannelFactory $logger_factory + * The logger factory. */ - public function __construct($configuration, $plugin_id, $plugin_definition, Connection $database, \Drupal\Core\Logger\LoggerChannelFactory $logger_factory) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, LoggerChannelFactory $logger_factory) { parent::__construct($configuration, $plugin_id, $plugin_definition); if (isset($configuration['options'])) { $this->options = $configuration['options']; @@ -98,18 +108,25 @@ abstract class SiteAuditCheckBase extends PluginBase implements SiteAuditCheckIn $this->optOut = TRUE; $this->score = SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO; } - $static = FALSE; + // $static = FALSE; $this->db = $database; $this->logger = $logger_factory->get('site_audit'); } /** + * Creates a new instance of this class. + * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The container interface. * @param array $configuration + * The plugin configuration. * @param string $plugin_id + * The plugin ID. * @param mixed $plugin_definition + * The plugin definition. * * @return static + * A new instance of the class. */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( @@ -305,6 +322,9 @@ abstract class SiteAuditCheckBase extends PluginBase implements SiteAuditCheckIn /** * Invoke another check's calculateScore() method if it is needed. + * + * @param string $plugin_id + * The ID of the plugin to invoke the calculateScore() method for. */ protected function checkInvokeCalculateScore($plugin_id) { $checkManager = \Drupal::service('plugin.manager.site_audit_check'); diff --git a/src/Plugin/SiteAuditCheckManager.php b/src/Plugin/SiteAuditCheckManager.php index 5c04600..5b6a38e 100644 --- a/src/Plugin/SiteAuditCheckManager.php +++ b/src/Plugin/SiteAuditCheckManager.php @@ -30,7 +30,7 @@ class SiteAuditCheckManager extends DefaultPluginManager { } /** - * @inherit + * {@inheritdoc} */ public function getDefinitions() { $definitions = parent::getDefinitions(); diff --git a/src/Plugin/SiteAuditReportBase.php b/src/Plugin/SiteAuditReportBase.php index 1ecfee4..cba13c1 100644 --- a/src/Plugin/SiteAuditReportBase.php +++ b/src/Plugin/SiteAuditReportBase.php @@ -86,14 +86,16 @@ abstract class SiteAuditReportBase extends PluginBase implements SiteAuditReport } /** - * Constructor. + * Constructs a new Drupal\site_audit\Plugin\SiteAuditReportBase object. * - * @param array $registry - * Aggregates data from each individual check. - * @param bool $opt_out - * If set, will not perform checks. + * @param array $configuration + * An array of configuration settings. + * @param string $plugin_id + * The plugin ID. + * @param mixed $plugin_definition + * The plugin definition. */ - public function __construct($configuration, $plugin_id, $plugin_definition) { + public function __construct(array $configuration, $plugin_id, $plugin_definition) { $checkManager = \Drupal::service('plugin.manager.site_audit_check'); parent::__construct($configuration, $plugin_id, $plugin_definition); $this->registry = new \stdClass(); @@ -112,13 +114,18 @@ abstract class SiteAuditReportBase extends PluginBase implements SiteAuditReport if (empty($checks_to_perform)) { $this_def = $this->getPluginDefinition(); - // Throw new \RuntimeException(t('No checks are available for report \'@id\'!', ['@id' => $this_def['id']]));. } $config = \Drupal::config('site_audit'); foreach ($checks_to_perform as $check_id) { $opt_out = $config->get('opt_out.' . $this->getPluginId() . $check_id) != NULL; - $check = $checkManager->createInstance($check_id, ['registry' => $this->registry, 'opt_out' => $opt_out, 'options' => $this->configuration]); + $check = $checkManager->createInstance($check_id, + [ + 'registry' => $this->registry, + 'opt_out' => $opt_out, + 'options' => $this->configuration, + ] + ); // Calculate score. if ($check->getScore() != SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO) { diff --git a/src/Plugin/SiteAuditReportManager.php b/src/Plugin/SiteAuditReportManager.php index cd5bfb9..3be2292 100644 --- a/src/Plugin/SiteAuditReportManager.php +++ b/src/Plugin/SiteAuditReportManager.php @@ -12,7 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; class SiteAuditReportManager extends DefaultPluginManager { /** - * Constructs a new SiteAuditReportManager object. + * Constructs a new \Drupal\site_audit\Plugin\SiteAuditReportManager object. * * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths @@ -30,7 +30,7 @@ class SiteAuditReportManager extends DefaultPluginManager { } /** - * @inherit + * {@inheritdoc} */ public function getDefinitions() { $definitions = parent::getDefinitions(); diff --git a/src/Renderer.php b/src/Renderer.php index 5d1ec07..ab80c4d 100644 --- a/src/Renderer.php +++ b/src/Renderer.php @@ -5,38 +5,56 @@ namespace Drupal\site_audit; use Drupal\Core\StringTranslation\StringTranslationTrait; /** - * Class Renderer. + * Provides an abstract base class for site audit report renderers. */ abstract class Renderer { use StringTranslationTrait; /** - * The Report to be rendered. + * The site audit report to be rendered. * * @var \Drupal\site_audit\Report */ public $report; /** - * The logger we are using for output. + * The logger used for output. + * + * @var mixed + * The logger object or NULL if not used. */ public $logger; /** - * Any options that have been passed in. + * Any options passed to the renderer. + * + * @var array + * An array of options. */ public $options; /** - * Output interface. + * The output interface. + * + * @var mixed + * The output interface object. */ public $output; /** + * Constructs a new \Drupal\site_audit\Renderer object. * + * @param \Drupal\site_audit\Report $report + * The site audit report to be rendered. + * @param mixed $logger + * The logger used for output. + * @param array $options + * Any options passed to the renderer. + * @param mixed $output + * The output interface. */ - public function __construct($report, $logger, $options, $output) { + public function __construct(Report $report, $logger, array $options, $output) { $this->report = $report; $this->logger = $logger; $this->options = $options; @@ -44,7 +62,13 @@ abstract class Renderer { } /** + * Renders the site audit report. + * + * @param bool $detail + * Determines detail inclusion in the rendered output. * + * @return string + * The rendered output of the site audit report. */ abstract public function render($detail = FALSE); diff --git a/src/Renderer/Console.php b/src/Renderer/Console.php index 5c40f9c..54313cc 100644 --- a/src/Renderer/Console.php +++ b/src/Renderer/Console.php @@ -10,19 +10,38 @@ use Drush\Utils\StringUtils; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\Table; -use Symfony\Component\Console\Helper\TableCell; use Symfony\Component\Console\Terminal; /** - * + * Provides a console renderer for Site Audit reports. */ class Console extends Renderer { + /** + * The output object. + * + * @var \Symfony\Component\Console\Output\OutputInterface + */ public $output; + + /** + * The formatter helper. + * + * @var \Symfony\Component\Console\Helper\FormatterHelper + */ public $formatter; /** + * Constructs a new \Drupal\site_audit\Renderer\Console object. * + * @param mixed $report + * The Site Audit report. + * @param mixed $logger + * The logger. + * @param mixed $options + * The renderer options. + * @param mixed $output + * The output object. */ public function __construct($report, $logger, $options, $output) { parent::__construct($report, $logger, $options, $output); @@ -31,7 +50,13 @@ class Console extends Renderer { } /** + * Etrieves the log level based on the score. + * + * @param int $score + * The score value. * + * @return string + * The log level. */ public function getLogLevel($score) { switch ($score) { @@ -51,7 +76,13 @@ class Console extends Renderer { } /** + * Retrieves the score SymfonyStyle class based on the score. + * + * @param int $score + * The score value. * + * @return string + * The score SymfonyStyle class. */ public function getScoreSymfonyStyle($score) { switch ($score) { @@ -70,6 +101,9 @@ class Console extends Renderer { /** * Get the SymfonyStyle method associated with a percentage. * + * @param int $percent + * The percentage value. + * * @return string * Symfony\Component\Console\Style method. */ @@ -88,6 +122,9 @@ class Console extends Renderer { /** * Take text and center it horizontally in the console. + * + * @param string $text + * The text to center. */ public function centerText(string $text) { $width = (new Terminal())->getWidth(); @@ -112,14 +149,25 @@ class Console extends Renderer { } /** - * Take Drupal\Core\StringTranslation\TranslatableMarkup and return the string. + * Interpolates a TranslatableMarkup object and returns the string. + * + * @param \Drupal\Core\StringTranslation\TranslatableMarkup $message + * The translatable message object. + * @param array $context + * An array of replacements for placeholders in the message. + * + * @return string + * The interpolated string. */ public function interpolate(TranslatableMarkup $message, array $context = []) { return StringUtils::interpolate($message, $context); } /** + * Renders the Site Audit report. * + * @param bool $detail + * Whether to show detailed information (optional). Defaults to FALSE. */ public function render($detail = FALSE) { $outputStyle = new OutputFormatterStyle('black', 'white'); @@ -159,7 +207,7 @@ class Console extends Renderer { // Add the report header. $this->horizontalRule(); - $this->centerText('<info>' . $this->interpolate($this->t('Report: ')) . $this->interpolate($this->report->getLabel()) . '</> - <' . $style . '>' . $percent . '%</>'); + $this->centerText('<info>' . $this->interpolate($this->t('Report:')) . $this->interpolate($this->report->getLabel()) . '</> - <' . $style . '>' . $percent . '%</>'); $this->horizontalRule(); // No action required. @@ -179,7 +227,12 @@ class Console extends Renderer { // Result. $result = $check->getResult(); - $this->output->writeln($this->formatter->formatSection($label, $this->interpolate($this->t('Result: <@symfony-style>@logLevel</>', ['@logLevel' => ucfirst(strtolower($this->getLogLevel($score))), '@symfony-style' => $this->getScoreSymfonyStyle($score)])))); + $this->output->writeln($this->formatter->formatSection($label, $this->interpolate($this->t('Result: <@symfony-style>@logLevel</>', + [ + '@logLevel' => ucfirst(strtolower($this->getLogLevel($score))), + '@symfony-style' => $this->getScoreSymfonyStyle($score), + ] + )))); if (is_array($result)) { if ($result['#theme'] && method_exists($this, $result['#theme'])) { $this->{$result['#theme']}($result, $label); @@ -218,22 +271,27 @@ class Console extends Renderer { } /** - * + * Success theme. */ public function success() { } /** - * Theme a table. + * Themes a table. + * + * @param array $element + * The table element. + * @param string|bool $section + * The section name (optional). Defaults to FALSE. */ - public function table($element, $section = FALSE) { + public function table(array $element, $section = FALSE) { if ($section) { $this->output->writeln($this->formatter->formatSection($section, $element['#title'])); } - // make sure the table headers and rows have no translatable objects + // Make sure the table headers and rows have no translatable objects. $headers = $element['#header'] ?: $element['headers']; - foreach ($headers AS &$header) { + foreach ($headers as &$header) { if (is_object($header)) { $header = (string) $header; } @@ -246,11 +304,11 @@ class Console extends Renderer { else { $class = NULL; } - foreach ($rows AS &$row) { + foreach ($rows as &$row) { if (isset($row['data'])) { $row = $row['data']; } - foreach ($row AS &$cell) { + foreach ($row as &$cell) { if (is_object($cell)) { $cell = (string) $cell; } @@ -267,9 +325,16 @@ class Console extends Renderer { } /** - * Theme an item list. + * Themes an item list. + * + * @param array $element + * The item list element. + * @param string|bool $section + * The section name. Defaults to FALSE. + * @param string $class + * The class for the item list. Defaults to 'note'. */ - public function item_list($element, $section = FALSE, $class = 'note') { + public function itemList(array $element, $section = FALSE, $class = 'note') { switch ($element['#list_type']) { case 'ol': $count = 1; diff --git a/src/Renderer/Html.php b/src/Renderer/Html.php index 1996019..f1cef60 100644 --- a/src/Renderer/Html.php +++ b/src/Renderer/Html.php @@ -6,17 +6,28 @@ use Drupal\site_audit\Plugin\SiteAuditCheckBase; use Drupal\site_audit\Renderer; /** - * + * Defines a renderer for HTML output. */ class Html extends Renderer { /** * The build array for the page. + * + * @var array */ public $build; /** - * @inherit + * Constructs a new \Drupal\site_audit\Renderer\Html object. + * + * @param object $report + * The report object. + * @param object|null $logger + * The logger object. + * @param array|null $options + * The options array. + * @param object|null $output + * The output object. */ public function __construct($report, $logger = NULL, $options = NULL, $output = NULL) { parent::__construct($report, $logger, $options, $output); @@ -24,10 +35,13 @@ class Html extends Renderer { } /** - * Get the CSS class associated with a percentage. + * Gets the CSS class associated with a percentage. + * + * @param int $percent + * The percentage value. * * @return string - * Twitter Bootstrap CSS class. + * The Twitter Bootstrap CSS class. */ public function getPercentCssClass($percent) { if ($percent > 80) { @@ -43,10 +57,13 @@ class Html extends Renderer { } /** - * Get the CSS class associated with a score. + * Gets the CSS class associated with a score. + * + * @param int|null $score + * The score value. * * @return string - * Name of the Twitter bootstrap class. + * The name of the Twitter Bootstrap class. */ public function getScoreCssClass($score = NULL) { switch ($score) { @@ -132,8 +149,9 @@ class Html extends Renderer { } /** - * Check to see if the bootstrap option was selected and wrap in HTMl and add - * bootstrap derived styles is so. + * Wraps the content in HTML. + * + * Adds bootstrap derived styles if the bootstrap option is selected. */ protected function checkBootstrap() { if (isset($this->options['bootstrap']) && $this->options['bootstrap']) { @@ -275,9 +293,12 @@ class Html extends Renderer { $checkBuild = []; $score = $check->getScore(); if ( - $this->options['detail'] || // detail is required - $score < SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS || // this check didn't pass - $percent == SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO // info needs to be returned + // Detail is required. + $this->options['detail'] || + // This check didn't pass. + $score < SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS || + // Info needs to be returned. + $percent == SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO ) { // Heading. $checkBuild['panel']['panel_heading'] = [ @@ -337,7 +358,6 @@ class Html extends Renderer { $build[$check->getPluginId()] = [ '#type' => 'html_tag', '#tag' => 'div', - //'#value' => '<strong>' . $this->t('Well done!') . '</strong> ' . $this->t('No action required.'), '#attributes' => [ 'class' => 'panel panel-' . $this->getScoreCssClass($check->getScore()), 'id' => 'check-' . $check->getPluginId(), @@ -358,7 +378,13 @@ class Html extends Renderer { } /** + * Escapes special characters in a text using HTML entities. + * + * @param string $text + * The text to escape. * + * @return string + * The escaped text. */ public static function escape($text) { return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); diff --git a/src/Renderer/Json.php b/src/Renderer/Json.php index 52f3a53..88253fa 100644 --- a/src/Renderer/Json.php +++ b/src/Renderer/Json.php @@ -5,12 +5,18 @@ namespace Drupal\site_audit\Renderer; use Drupal\site_audit\Renderer; /** - * + * Provides a JSON renderer for site audit reports. */ class Json extends Renderer { /** + * Renders the site audit report in JSON format. * + * @param bool $detail + * Determines whether to include detailed information in the JSON output. + * + * @return string + * The JSON representation of the site audit report. */ public function render($detail = FALSE) { $report = [ diff --git a/src/Renderer/Markdown.php b/src/Renderer/Markdown.php index d21cde7..d2d6388 100644 --- a/src/Renderer/Markdown.php +++ b/src/Renderer/Markdown.php @@ -6,12 +6,18 @@ use Drupal\site_audit\Renderer; use Drupal\site_audit\Check; /** - * + * Provides a Markdown renderer for Site Audit reports. */ class Markdown extends Renderer { /** + * Renders the Site Audit report. * + * @param bool $detail + * (optional) Whether to show detailed information. Defaults to FALSE. + * + * @return string + * The rendered Site Audit report in Markdown format. */ public function render($detail = FALSE) { $ret_val = '## ' . $this->report->getLabel();