Skip to content
Snippets Groups Projects
Commit ac7a3edc authored by Andrey Tymchuk's avatar Andrey Tymchuk Committed by A.Tymchuk
Browse files

Issue #3423280 by WalkingDexter: Fix PHPStan errors (level 5)

parent 2795fb4c
No related branches found
Tags 1.0.0-alpha17
No related merge requests found
Pipeline #112788 failed
Showing with 65 additions and 46 deletions
......@@ -24,6 +24,16 @@ parameters:
count: 1
path: src/Entity/EntityHelper.php
-
message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(Drupal\\\\Core\\\\Entity\\\\EntityInterface, Drupal\\\\Core\\\\Entity\\\\EntityInterface\\)\\: int, array\\{'Drupal\\\\\\\\simple_sitemap\\\\\\\\Entity\\\\\\\\SimpleSitemap', 'sort'\\} given\\.$#"
count: 2
path: src/Entity/SimpleSitemapStorage.php
-
message: "#^Parameter \\#1 \\$priority of static method Drupal\\\\simple_sitemap\\\\Form\\\\FormHelper\\:\\:formatPriority\\(\\) expects string, \\(float\\|int\\) given\\.$#"
count: 1
path: src/Form/FormHelper.php
-
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
count: 2
......@@ -62,3 +72,8 @@ parameters:
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\) with non\\-empty\\-array\\<Behat\\\\Mink\\\\Element\\\\NodeElement\\> will always evaluate to false\\.$#"
count: 1
path: tests/src/Functional/SimplesitemapTest.php
-
message: "#^Parameter \\#2 \\$value of method Drupal\\\\Core\\\\Database\\\\Query\\\\ConditionInterface\\:\\:condition\\(\\) expects array\\|Drupal\\\\Core\\\\Database\\\\Query\\\\SelectInterface\\|int\\|string\\|null, true given\\.$#"
count: 1
path: tests/src/Functional/SimplesitemapTest.php
includes:
- phpstan-baseline.neon
parameters:
level: 4
level: 5
paths:
- .
excludePaths:
......
......@@ -266,7 +266,7 @@ class SimpleSitemap extends ConfigEntityBase implements SimpleSitemapInterface {
/**
* {@inheritdoc}
*/
public function getCreated(): ?string {
public function getCreated(): ?int {
return $this->entityTypeManager()->getStorage('simple_sitemap')->getCreated($this, $this->fetchByStatus);
}
......
......@@ -126,10 +126,10 @@ interface SimpleSitemapInterface extends ConfigEntityInterface {
/**
* Returns the timestamp of the sitemap chunk generation.
*
* @return string|null
* @return int|null
* Timestamp of sitemap chunk generation.
*/
public function getCreated(): ?string;
public function getCreated(): ?int;
/**
* Returns the number of links indexed in the sitemap content.
......
......@@ -244,10 +244,10 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Publishes the specified sitemap.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity to publish.
*/
public function publish(SimpleSitemap $entity): void {
public function publish(SimpleSitemapInterface $entity): void {
$unpublished_chunk = $this->database->query('SELECT MAX(id) FROM {simple_sitemap} WHERE type = :type AND status = :status', [
':type' => $entity->id(),
':status' => self::SITEMAP_UNPUBLISHED,
......@@ -272,10 +272,10 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
* A sitemap entity can exist without the sitemap (XML) content which lives
* in the DB. This purges the sitemap content.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity to process.
*/
public function deleteContent(SimpleSitemap $entity): void {
public function deleteContent(SimpleSitemapInterface $entity): void {
$this->purgeContent([$entity->id()]);
}
......@@ -344,7 +344,7 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Returns the number of all content chunks of the specified sitemap.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param int|null $status
* Fetch by sitemap status.
......@@ -352,7 +352,7 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
* @return int
* Number of chunks.
*/
public function getChunkCount(SimpleSitemap $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): int {
public function getChunkCount(SimpleSitemapInterface $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): int {
$query = $this->database->select('simple_sitemap', 's')
->condition('s.type', $entity->id())
->condition('s.delta', self::SITEMAP_INDEX_DELTA, '<>');
......@@ -367,9 +367,9 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Retrieves the content of a specified sitemap's chunk.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param bool|null $status
* @param int|null $status
* Fetch by sitemap status.
* @param int $delta
* Delta of the chunk.
......@@ -379,7 +379,7 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
*
* @todo Fix the duplicate query.
*/
public function getChunk(SimpleSitemap $entity, ?bool $status, int $delta = SimpleSitemapStorage::SITEMAP_CHUNK_FIRST_DELTA): string {
public function getChunk(SimpleSitemapInterface $entity, ?int $status, int $delta = SimpleSitemapStorage::SITEMAP_CHUNK_FIRST_DELTA): string {
if ($delta === self::SITEMAP_INDEX_DELTA) {
throw new SitemapNotExistsException('The sitemap chunk delta cannot be ' . self::SITEMAP_INDEX_DELTA . '.');
}
......@@ -390,15 +390,15 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Determines whether the specified sitemap has a chunk index.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity to check.
* @param bool $status
* @param int|null $status
* Fetch by sitemap status.
*
* @return bool
* TRUE if the sitemap has an index, FALSE otherwise.
*/
public function hasIndex(SimpleSitemap $entity, bool $status): bool {
public function hasIndex(SimpleSitemapInterface $entity, ?int $status): bool {
try {
$this->getIdByDelta($entity, self::SITEMAP_INDEX_DELTA, $status);
return TRUE;
......@@ -411,9 +411,9 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Gets the sitemap chunk index content.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param bool|null $status
* @param int|null $status
* Fetch by sitemap status.
*
* @return string
......@@ -421,24 +421,24 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
*
* @todo Fix the duplicate query.
*/
public function getIndex(SimpleSitemap $entity, ?bool $status): string {
public function getIndex(SimpleSitemapInterface $entity, ?int $status): string {
return $this->getSitemapString($entity, $this->getIdByDelta($entity, self::SITEMAP_INDEX_DELTA, $status), $status);
}
/**
* Returns the sitemap chunk ID by delta.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param int $delta
* Delta of the chunk.
* @param bool $status
* @param int|null $status
* Fetch by sitemap status.
*
* @return int
* The sitemap chunk ID.
*/
protected function getIdByDelta(SimpleSitemap $entity, int $delta, bool $status): int {
protected function getIdByDelta(SimpleSitemapInterface $entity, int $delta, ?int $status): int {
foreach ($this->getChunkData($entity) as $chunk) {
if ($chunk->delta == $delta && $chunk->status == $status) {
return $chunk->id;
......@@ -451,17 +451,17 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Retrieves the sitemap chunk content.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param int $id
* The sitemap chunk ID.
* @param bool|null $status
* @param int|null $status
* Fetch by sitemap status.
*
* @return string
* The sitemap chunk content.
*/
protected function getSitemapString(SimpleSitemap $entity, int $id, ?bool $status): string {
protected function getSitemapString(SimpleSitemapInterface $entity, int $id, ?int $status): string {
$chunk_data = $this->getChunkData($entity);
if (!isset($chunk_data[$id])) {
throw new SitemapNotExistsException();
......@@ -485,13 +485,13 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
* The sitemap can be unpublished (0), published (1), or published and in
* regeneration (2).
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
*
* @return int
* The sitemap status.
*/
public function status(SimpleSitemap $entity): int {
public function status(SimpleSitemapInterface $entity): int {
foreach ($this->getChunkData($entity) as $chunk) {
$status[$chunk->status] = $chunk->status;
}
......@@ -512,15 +512,15 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Returns the timestamp of the specified sitemap's chunk generation.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param int|null $status
* Fetch by sitemap status.
*
* @return string|null
* @return int|null
* Timestamp of sitemap chunk generation.
*/
public function getCreated(SimpleSitemap $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): ?string {
public function getCreated(SimpleSitemapInterface $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): ?int {
foreach ($this->getChunkData($entity) as $chunk) {
if ($status === SimpleSitemap::FETCH_BY_STATUS_ALL || $chunk->status == $status) {
return $chunk->sitemap_created;
......@@ -533,7 +533,7 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
/**
* Returns the number of links indexed in the specified sitemap's content.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap $entity
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface $entity
* The sitemap entity.
* @param int|null $status
* Fetch by sitemap status.
......@@ -541,7 +541,7 @@ class SimpleSitemapStorage extends ConfigEntityStorage {
* @return int
* Number of links.
*/
public function getLinkCount(SimpleSitemap $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): int {
public function getLinkCount(SimpleSitemapInterface $entity, ?int $status = SimpleSitemap::FETCH_BY_STATUS_ALL): int {
$count = 0;
foreach ($this->getChunkData($entity) as $chunk) {
if ($chunk->delta != self::SITEMAP_INDEX_DELTA
......
......@@ -190,7 +190,7 @@ class CustomLinkManager implements SitemapGetterInterface {
/**
* Gets all compatible sitemaps.
*
* @return \Drupal\simple_sitemap\Entity\SimpleSitemap[]
* @return \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]
* Array of sitemaps of a type that implements a custom URL
* generator.
*/
......
......@@ -598,7 +598,7 @@ class EntityManager implements SitemapGetterInterface {
/**
* Gets all compatible sitemaps.
*
* @return \Drupal\simple_sitemap\Entity\SimpleSitemap[]
* @return \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]
* Array of sitemaps of a type that uses a URL generator which
* extends EntityUrlGeneratorBase. Keyed by variant.
*
......
......@@ -4,6 +4,7 @@ namespace Drupal\simple_sitemap\Manager;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\simple_sitemap\Entity\SimpleSitemap;
use Drupal\simple_sitemap\Entity\SimpleSitemapInterface;
use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Queue\QueueWorker;
use Drupal\simple_sitemap\Settings;
......@@ -119,10 +120,10 @@ class Generator implements SitemapGetterInterface {
/**
* Gets the default sitemap from the currently set sitemaps.
*
* @return \Drupal\simple_sitemap\Entity\SimpleSitemap|null
* @return \Drupal\simple_sitemap\Entity\SimpleSitemapInterface|null
* The default sitemap or NULL if there are no sitemaps.
*/
public function getDefaultSitemap(): ?SimpleSitemap {
public function getDefaultSitemap(): ?SimpleSitemapInterface {
if (empty($sitemaps = $this->getSitemaps())) {
return NULL;
}
......@@ -259,7 +260,7 @@ class Generator implements SitemapGetterInterface {
/**
* Gets all compatible sitemaps.
*
* @return \Drupal\simple_sitemap\Entity\SimpleSitemap[]
* @return \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]
* Array of sitemaps.
*/
protected function getCompatibleSitemaps(): array {
......
......@@ -10,7 +10,7 @@ interface SitemapGetterInterface {
/**
* Gets the currently set sitemaps.
*
* @return \Drupal\simple_sitemap\Entity\SimpleSitemap[]
* @return \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]
* The currently set sitemaps, or all compatible sitemaps if none are set.
*/
public function getSitemaps(): array;
......@@ -18,10 +18,10 @@ interface SitemapGetterInterface {
/**
* Sets the sitemaps.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap[]|\Drupal\simple_sitemap\Entity\SimpleSitemap|string[]|string|null $sitemaps
* SimpleSitemap[]: Array of sitemap objects to be set.
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]|\Drupal\simple_sitemap\Entity\SimpleSitemapInterface|string[]|string|null $sitemaps
* SimpleSitemapInterface[]: Array of sitemap objects to be set.
* string[]: Array of sitemap IDs to be set.
* SimpleSitemap: A particular sitemap object to be set.
* SimpleSitemapInterface: A particular sitemap object to be set.
* string: A particular sitemap ID to be set.
* null: All compatible sitemaps will be set.
*
......
......@@ -12,7 +12,7 @@ trait SitemapGetterTrait {
/**
* The currently set sitemaps.
*
* @var \Drupal\simple_sitemap\Entity\SimpleSitemap[]
* @var \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[]
*/
protected $sitemaps;
......
......@@ -2,6 +2,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\simple_sitemap\Entity\EntityHelper;
......@@ -158,7 +159,7 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase {
: NULL,
'priority' => $data_set['priority'] ?? NULL,
'changefreq' => !empty($data_set['changefreq']) ? $data_set['changefreq'] : NULL,
'images' => $this->includeImages && !empty($entity)
'images' => $this->includeImages && !empty($entity) && $entity instanceof ContentEntityInterface
? $this->getEntityImageData($entity)
: [],
'meta' => [
......
......@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
......@@ -228,7 +229,7 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase {
: NULL,
'priority' => $entity_settings['priority'] ?? NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images']) && !empty($entity)
'images' => !empty($entity_settings['include_images']) && !empty($entity) && $entity instanceof ContentEntityInterface
? $this->getEntityImageData($entity)
: [],
......
......@@ -223,6 +223,7 @@ class EntityUrlGenerator extends EntityUrlGeneratorBase {
* {@inheritdoc}
*/
protected function processDataSet($data_set): array {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
foreach ($this->entityTypeManager->getStorage($data_set['entity_type'])->loadMultiple((array) $data_set['id']) as $entity) {
try {
$paths[] = $this->processEntity($entity);
......
......@@ -169,7 +169,7 @@ class QueueWorker {
/**
* Queues links from sitemaps.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap[] $sitemaps
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[] $sitemaps
* The sitemaps.
*
* @return $this
......@@ -218,7 +218,7 @@ class QueueWorker {
/**
* Deletes the queue and queues links from sitemaps.
*
* @param \Drupal\simple_sitemap\Entity\SimpleSitemap[] $sitemaps
* @param \Drupal\simple_sitemap\Entity\SimpleSitemapInterface[] $sitemaps
* The sitemaps.
*
* @return $this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment