Commit f99c8fa7 authored by gbyte.co's avatar gbyte.co

Code cleanup

parent 72a4e780
......@@ -67,8 +67,8 @@ class SimplesitemapCommands extends DrushCommands {
if (strlen($options['variants']) > 0) {
$chosen_variants = array_map('trim', array_filter(explode(',', $options['variants'])));
if (!empty($erroneous_variants = array_diff($chosen_variants, $variants))) {
$message = "The following variants do not exist: " . implode(', ', $erroneous_variants)
. ". Available variants are: " . implode(', ', $variants) . '.';
$message = 'The following variants do not exist: ' . implode(', ', $erroneous_variants)
. '. Available variants are: ' . implode(', ', $variants) . '.';
$this->logger()->log('error', $message);
return;
}
......
......@@ -102,6 +102,7 @@ class EntityHelper {
/**
* Determines if an entity type is supported or not.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* @return bool
* TRUE if entity type supported by Simple Sitemap, FALSE if not.
*/
......
......@@ -15,7 +15,6 @@ use Drupal\Core\Session\AccountProxyInterface;
class FormHelper {
use StringTranslationTrait;
const PRIORITY_DEFAULT = 0.5;
const PRIORITY_HIGHEST = 10;
const PRIORITY_DIVIDER = 10;
......
......@@ -37,57 +37,6 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
'xmlns:image' => self::XMLNS_IMAGE,
];
/**
* DefaultSitemapGenerator constructor.
*
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
* @param \Drupal\Core\Database\Connection $database
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Component\Datetime\Time $time
* @param \Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapWriter $sitemapWriter
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
Connection $database,
ModuleHandler $module_handler,
LanguageManagerInterface $language_manager,
Time $time,
SitemapWriter $sitemapWriter
) {
parent::__construct(
$configuration,
$plugin_id,
$plugin_definition,
$database,
$module_handler,
$language_manager,
$time,
$sitemapWriter
);
}
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('database'),
$container->get('module_handler'),
$container->get('language_manager'),
$container->get('datetime.time'),
$container->get('simple_sitemap.sitemap_writer')
);
}
/**
* Generates and returns a sitemap chunk.
*
......
......@@ -8,15 +8,15 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;
*/
interface SitemapGeneratorInterface {
function setSitemapVariant($sitemap_variant);
public function setSitemapVariant($sitemap_variant);
function setSettings(array $settings);
public function setSettings(array $settings);
function generate(array $links);
public function generate(array $links);
function generateIndex();
public function generateIndex();
function publish();
public function publish();
function remove();
public function remove();
}
......@@ -199,9 +199,8 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
unset($path_data['url']);
return $this->getUrlVariants($path_data, $url_object);
}
else {
return FALSE !== $path_data ? [$path_data] : [];
}
return FALSE !== $path_data ? [$path_data] : [];
}
/**
......
......@@ -8,11 +8,11 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
*/
interface UrlGeneratorInterface {
function setSettings(array $settings);
public function setSettings(array $settings);
function setSitemapVariant($sitemap_variant);
public function setSitemapVariant($sitemap_variant);
function getDataSets();
public function getDataSets();
function generate($data_set);
public function generate($data_set);
}
......@@ -138,7 +138,7 @@ class QueueWorker {
? $this->manager->getSitemapVariants()
: array_filter(
$this->manager->getSitemapVariants(),
function($name) use ($variants) { return in_array($name, (array) $variants); },
static function($name) use ($variants) { return in_array($name, (array) $variants); },
ARRAY_FILTER_USE_KEY
);
......@@ -177,7 +177,7 @@ class QueueWorker {
$this->getQueuedElementCount(TRUE);
// Remove all sitemap instances of variants which did not yield any queue elements.
$this->manager->removeSitemap(array_keys(array_filter($queue_variants, function($e) { return empty($e['data']); })));
$this->manager->removeSitemap(array_keys(array_filter($queue_variants, static function($e) { return empty($e['data']); })));
return $this;
}
......
......@@ -242,18 +242,16 @@ class Simplesitemap {
return $this->fetchSitemapChunk($chunk_info[SitemapGeneratorBase::INDEX_DELTA]->id)
->sitemap_string;
}
else {
// Return sitemap chunk if there is only one chunk.
return isset($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA])
? $this->fetchSitemapChunk($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA]->id)
->sitemap_string
: FALSE;
}
}
else {
// Return specific sitemap chunk.
return $this->fetchSitemapChunk($chunk_info[$delta]->id)->sitemap_string;
// Return sitemap chunk if there is only one chunk.
return isset($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA])
? $this->fetchSitemapChunk($chunk_info[SitemapGeneratorBase::FIRST_CHUNK_DELTA]->id)
->sitemap_string
: FALSE;
}
// Return specific sitemap chunk.
return $this->fetchSitemapChunk($chunk_info[$delta]->id)->sitemap_string;
}
/**
......@@ -276,9 +274,8 @@ class Simplesitemap {
? $result->fetchAllAssoc('type')
: $result->fetchAllAssoc('delta');
}
else {
return [];
}
return [];
}
/**
......@@ -598,11 +595,8 @@ class Simplesitemap {
->getEditable("simple_sitemap.bundle_settings.$variant.$entity_type_id.$bundle_name")->delete();
}
$this->removeEntityInstanceSettings($entity_type_id, (
empty($ids)
? NULL
: $this->entityHelper->getEntityInstanceIds($entity_type_id, $bundle_name)
));
$entity_ids = $this->entityHelper->getEntityInstanceIds($entity_type_id, $bundle_name);
$this->removeEntityInstanceSettings($entity_type_id, (empty($entity_ids) ? NULL : $entity_ids));
}
else {
foreach ($variants as $variant) {
......@@ -610,8 +604,8 @@ class Simplesitemap {
foreach ($config_names as $config_name) {
$this->configFactory->getEditable($config_name)->delete();
}
$this->removeEntityInstanceSettings();
}
$this->removeEntityInstanceSettings();
}
return $this;
......@@ -736,16 +730,15 @@ class Simplesitemap {
if (!empty($results)) {
return unserialize($results);
}
else {
if (empty($entity = $this->entityTypeManager->getStorage($entity_type_id)->load($id))) {
return FALSE;
}
return $this->getBundleSettings(
$entity_type_id,
$this->entityHelper->getEntityInstanceBundleName($entity)
);
if (empty($entity = $this->entityTypeManager->getStorage($entity_type_id)->load($id))) {
return FALSE;
}
return $this->getBundleSettings(
$entity_type_id,
$this->entityHelper->getEntityInstanceBundleName($entity)
);
}
/**
......
......@@ -160,7 +160,7 @@ class SimplesitemapManager {
* @return array
*/
protected function attachSitemapTypeToVariants(array $variants, $type) {
return array_map(function($variant) use ($type) { return $variant + ['type' => $type]; }, $variants);
return array_map(static function($variant) use ($type) { return $variant + ['type' => $type]; }, $variants);
}
/**
......@@ -198,7 +198,7 @@ class SimplesitemapManager {
}
if (isset($old_variant)) {
$definition = $definition + $old_variant;
$definition += $old_variant;
}
$variants = array_merge($this->getSitemapVariants($definition['type'], FALSE), [$name => ['label' => $definition['label'], 'weight' => $definition['weight']]]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment