BestPracticesSitesSuperfluous.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/BestPracticesSitesSuperfluous.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class BestPracticesSitesSuperfluous extends SiteAuditCheckBase {
public function getResultFail() {
}
public function getResultInfo() {
}
public function getResultPass() {
return $this
->t('No unnecessary files detected.');
}
public function getResultWarn() {
return $this
->t('The following extra files were detected: @list', [
'@list' => implode(', ', $this->registry->superfluous),
]);
}
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.');
}
}
public function calculateScore() {
$handle = opendir(DRUPAL_ROOT . '/sites/');
$this->registry->superfluous = [];
while (FALSE !== ($entry = readdir($handle))) {
if (!in_array($entry, [
'.',
'..',
'default',
'all',
'example.sites.php',
'development.services.yml',
'example.settings.local.php',
'README.txt',
'.DS_Store',
])) {
if (is_file(DRUPAL_ROOT . '/sites/' . $entry)) {
if ($entry != 'sites.php' || $this->options['vendor'] == 'pantheon') {
$this->registry->superfluous[] = $entry;
}
}
}
}
closedir($handle);
if (!empty($this->registry->superfluous)) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS;
}
}