Skip to content

Commit

Permalink
fixed minor phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Oct 10, 2024
1 parent 732ed6f commit 4b9802e
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 950 deletions.
877 changes: 16 additions & 861 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/lib/FieldType/BinaryBase/BinaryBaseStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public function copyLegacyField(VersionInfo $versionInfo, Field $field, Field $o
*
* @param mixed $fieldId
* @param string $versionNo
* @param array $context
*/
protected function removeOldFile($fieldId, $versionNo)
{
Expand Down
13 changes: 0 additions & 13 deletions src/lib/FieldType/Keyword/KeywordStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class KeywordStorage extends GatewayBasedStorage
/**
* @see \Ibexa\Contracts\Core\FieldType\FieldStorage
*
* @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo
* @param \Ibexa\Contracts\Core\Persistence\Content\Field $field
* @param array $context
*
* @return mixed
*/
public function storeFieldData(VersionInfo $versionInfo, Field $field)
Expand All @@ -45,11 +41,7 @@ public function getFieldData(VersionInfo $versionInfo, Field $field)
}

/**
* @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo
* @param array $fieldIds
* @param array $context
*
* @return bool
*/
public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): bool
{
Expand All @@ -60,11 +52,6 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): bool
return true;
}

/**
* Checks if field type has external data to deal with.
*
* @return bool
*/
public function hasFieldData(): bool
{
return true;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/FieldType/User/UserStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public function getFieldData(VersionInfo $versionInfo, Field $field)
}

/**
* @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo
* @param int[] $fieldIds Array of field Ids
* @param array $context
*
* @return bool
*
Expand Down
7 changes: 0 additions & 7 deletions src/lib/Helper/PreviewLocationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Ibexa\Core\Helper;

use Ibexa\Contracts\Core\Persistence\Content\Location\Handler as PersistenceLocationHandler;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Content as APIContent;
use Ibexa\Contracts\Core\Repository\Values\Content\Location as APILocation;
Expand All @@ -22,24 +21,18 @@ class PreviewLocationProvider
/** @var \Ibexa\Contracts\Core\Repository\LocationService */
private $locationService;

/** @var \Ibexa\Contracts\Core\Repository\ContentService */
private $contentService;

/** @var \Ibexa\Contracts\Core\Persistence\Content\Location\Handler */
private $locationHandler;

/**
* @param \Ibexa\Contracts\Core\Repository\LocationService $locationService
* @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
* @param \Ibexa\Contracts\Core\Persistence\Content\Location\Handler $locationHandler
*/
public function __construct(
LocationService $locationService,
ContentService $contentService,
PersistenceLocationHandler $locationHandler
) {
$this->locationService = $locationService;
$this->contentService = $contentService;
$this->locationHandler = $locationHandler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ final class SimplifiedRequestNormalizer extends PropertyNormalizer
* @param \Ibexa\Core\MVC\Symfony\Routing\SimplifiedRequest $object
*
* @return array{
* scheme: string,
* host: string,
* port: string,
* pathinfo: string,
* scheme: ?string,
* host: ?string,
* port: ?int,
* pathinfo: ?string,
* queryParams: array<mixed>,
* languages: string[],
* headers: array{}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Matcher/HostElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getRequest()

public function reverseMatch($siteAccessName)
{
$hostElements = explode('.', $this->request->getHost());
$hostElements = explode('.', (string)$this->request->getHost());
$elementNumber = $this->elementNumber - 1;
if (!isset($hostElements[$elementNumber])) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Matcher/HostText.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getName(): string
public function setRequest(SimplifiedRequest $request): void
{
if (!$this->element) {
$this->setMatchElement($request->getHost());
$this->setMatchElement((string)$request->getHost());
}

parent::setRequest($request);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Matcher/Map/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getName(): string
public function setRequest(SimplifiedRequest $request)
{
if (!$this->key) {
$this->setMapKey($request->getHost());
$this->setMapKey((string)$request->getHost());
}

parent::setRequest($request);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/MVC/Symfony/SiteAccess/Matcher/Map/Port.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setRequest(SimplifiedRequest $request)
}
}

$this->setMapKey($key);
$this->setMapKey((string)$key);
}

parent::setRequest($request);
Expand All @@ -49,7 +49,7 @@ public function reverseMatch($siteAccessName)
{
$matcher = parent::reverseMatch($siteAccessName);
if ($matcher instanceof self) {
$matcher->getRequest()->setPort($matcher->getMapKey());
$matcher->getRequest()->setPort((int)$matcher->getMapKey());
}

return $matcher;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/MVC/Symfony/SiteAccess/Matcher/Map/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class URI extends Map implements URILexer
public function setRequest(SimplifiedRequest $request)
{
if (!$this->key) {
sscanf($request->getPathInfo(), '/%[^/]', $key);
sscanf((string)$request->getPathInfo(), '/%[^/]', $key);
$this->setMapKey(rawurldecode((string)$key));
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function reverseMatch($siteAccessName)
if ($matcher instanceof self) {
$request = $matcher->getRequest();
// Clean up "old" siteaccess prefix and add the new prefix.
$request->setPathinfo($this->analyseLink($request->getPathInfo()));
$request->setPathinfo($this->analyseLink((string)$request->getPathInfo()));
}

return $matcher;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Matcher/URIElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function reverseMatch($siteAccessName)
return null;
}

$pathinfo = '/' . implode('/', $elements) . '/' . ltrim($this->request->getPathInfo(), '/');
$pathinfo = '/' . implode('/', $elements) . '/' . ltrim((string)$this->request->getPathInfo(), '/');
$this->request->setPathinfo($pathinfo);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Matcher/URIText.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getName(): string
public function setRequest(SimplifiedRequest $request): void
{
if (!$this->element) {
$this->setMatchElement($request->getPathInfo());
$this->setMatchElement((string)$request->getPathInfo());
}

parent::setRequest($request);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MVC/Symfony/SiteAccess/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function matchByName($siteAccessName): ?SiteAccess
$request = clone $this->request;
// Be sure to have a clean pathinfo, without SiteAccess part in it.
if ($this->siteAccess && $this->siteAccess->matcher instanceof URILexer) {
$request->setPathinfo($this->siteAccess->matcher->analyseURI($request->getPathInfo()));
$request->setPathinfo($this->siteAccess->matcher->analyseURI((string)$request->getPathInfo()));
}

$siteAccessClass = $this->siteAccessClass;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/Repository/URLWildcardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ private function validateUrls(string $sourceUrl, string $destinationUrl): void
preg_match_all('(\\*)', $sourceUrl, $patterns);
preg_match_all('({(\d+)})', $destinationUrl, $placeholders);

if (empty($patterns) || empty($placeholders)) {
throw new ContentValidationException('Invalid URL wildcards provided.');
}

$patterns = array_map('intval', $patterns[0]);
$placeholders = array_map('intval', $placeholders[1]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\LanguageLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\LocationLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\SubtreeLimitation;
Expand Down Expand Up @@ -1199,6 +1200,7 @@ public function testLoadRelationsWithUnauthorizedRelations()
* @var \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\RelationListItemInterface $relationListItem
*/
foreach ($actualRelations as $relationListItem) {
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Relation $relation */
$relation = $relationListItem->getRelation();
$destination = $relation->destinationContentInfo;
$expected = $expectedRelations[$destination->id]->destinationContentInfo;
Expand Down
36 changes: 22 additions & 14 deletions tests/integration/Core/Repository/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ public function testLoadContentDraftsReturnsEmptyArrayByDefault()
*
* @depends testCreateContentDraft
*/
public function testLoadContentDraftList()
public function testLoadContentDraftList(): void
{
// "Media" content object
$mediaContentInfo = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID);
Expand All @@ -2433,11 +2433,17 @@ public function testLoadContentDraftList()
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\DraftList\ContentDraftListItemInterface[] $draftedVersions */
$draftedVersions = iterator_to_array($this->contentService->loadContentDraftList()->getIterator());

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $draftedVersionInfo0 */
$draftedVersionInfo0 = $draftedVersions[0]->getVersionInfo();

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $draftedVersionInfo1 */
$draftedVersionInfo1 = $draftedVersions[1]->getVersionInfo();

$actual = [
$draftedVersions[0]->getVersionInfo()->status,
$draftedVersions[0]->getVersionInfo()->getContentInfo()->remoteId,
$draftedVersions[1]->getVersionInfo()->status,
$draftedVersions[1]->getVersionInfo()->getContentInfo()->remoteId,
$draftedVersionInfo0->status,
$draftedVersionInfo0->getContentInfo()->remoteId,
$draftedVersionInfo1->status,
$draftedVersionInfo1->getContentInfo()->remoteId,
];
sort($actual, SORT_STRING);

Expand Down Expand Up @@ -2481,27 +2487,29 @@ public function testLoadContentDraftsWithFirstParameter()

self::assertSame([], $oldCurrentUserDrafts);

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $newCurrentUserDraftVersionInfo */
$newCurrentUserDraftVersionInfo = $newCurrentUserDrafts[0]->getVersionInfo();
self::assertEquals(
[
VersionInfo::STATUS_DRAFT,
self::MEDIA_REMOTE_ID,
],
[
$newCurrentUserDrafts[0]->getVersionInfo()->status,
$newCurrentUserDrafts[0]->getVersionInfo()->getContentInfo()->remoteId,
$newCurrentUserDraftVersionInfo->status,
$newCurrentUserDraftVersionInfo->getContentInfo()->remoteId,
]
);
self::assertTrue($newCurrentUserDrafts[0]->getVersionInfo()->isDraft());
self::assertFalse($newCurrentUserDrafts[0]->getVersionInfo()->isArchived());
self::assertFalse($newCurrentUserDrafts[0]->getVersionInfo()->isPublished());
self::assertTrue($newCurrentUserDraftVersionInfo->isDraft());
self::assertFalse($newCurrentUserDraftVersionInfo->isArchived());
self::assertFalse($newCurrentUserDraftVersionInfo->isPublished());
}

/**
* Test for the loadContentDraftList() method.
*
* @covers \Ibexa\Contracts\Core\Repository\ContentService::loadContentDraftList()
*/
public function testLoadContentDraftListWithPaginationParameters()
public function testLoadContentDraftListWithPaginationParameters(): void
{
// Create some drafts
$publishedContent = $this->createContentVersion1();
Expand All @@ -2527,7 +2535,7 @@ public function testLoadContentDraftListWithPaginationParameters()
*
* @covers \Ibexa\Contracts\Core\Repository\ContentService::loadContentDraftList($user)
*/
public function testLoadContentDraftListWithForUserWithLimitation()
public function testLoadContentDraftListWithForUserWithLimitation(): void
{
$oldUser = $this->permissionResolver->getCurrentUserReference();

Expand Down Expand Up @@ -2566,7 +2574,7 @@ public function testLoadContentDraftListWithForUserWithLimitation()
*
* @covers \Ibexa\Contracts\Core\Repository\ContentService::loadContentDraftList()
*/
public function testLoadAllContentDraftList()
public function testLoadAllContentDraftList(): void
{
// Create more drafts then default pagination limit
$this->createContentDrafts(12);
Expand Down Expand Up @@ -6691,7 +6699,7 @@ private function createParentLocationsForHideReveal(int $parentLocationId): arra
$this->createFolder([self::ENG_US => 'P3'], $parentLocationId)->contentInfo->mainLocationId,
];

return array_values($this->locationService->loadLocationList($parentFoldersLocationsIds));
return array_values([...$this->locationService->loadLocationList($parentFoldersLocationsIds)]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getSettingsSchema()
}

/**
* @covers \Ibexa\Contracts\Core\Repository\Tests\FieldType\BaseIntegrationTest::getValidatorSchema()
* @covers \Ibexa\Tests\Integration\Core\Repository\FieldType\BaseIntegrationTest::getValidatorSchema()
*/
public function getValidatorSchema()
{
Expand Down Expand Up @@ -230,10 +230,8 @@ public function provideInvalidCreationFieldData()

/**
* Get update field externals data.
*
* @return array
*/
public function getValidUpdateFieldData()
public function getValidUpdateFieldData(): RelationValue
{
return new RelationValue(49);
}
Expand All @@ -242,10 +240,8 @@ public function getValidUpdateFieldData()
* Get externals updated field data values.
*
* This is a PHPUnit data provider
*
* @return array
*/
public function assertUpdatedFieldDataLoadedCorrect(Field $field)
public function assertUpdatedFieldDataLoadedCorrect(Field $field): void
{
self::assertInstanceOf(RelationValue::class, $field->value);

Expand All @@ -271,7 +267,7 @@ public function provideInvalidUpdateFieldData()
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field
*/
public function assertCopiedFieldDataLoadedCorrectly(Field $field)
public function assertCopiedFieldDataLoadedCorrectly(Field $field): void
{
self::assertInstanceOf(
RelationValue::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,8 @@ public function provideInvalidCreationFieldData()

/**
* Get update field externals data.
*
* @return array
*/
public function getValidUpdateFieldData()
public function getValidUpdateFieldData(): RelationListValue
{
return new RelationListValue([49, 54, 4]);
}
Expand All @@ -271,10 +269,8 @@ public function getValidUpdateFieldData()
* Get externals updated field data values.
*
* This is a PHPUnit data provider
*
* @return array
*/
public function assertUpdatedFieldDataLoadedCorrect(Field $field)
public function assertUpdatedFieldDataLoadedCorrect(Field $field): void
{
self::assertInstanceOf(RelationListValue::class, $field->value);

Expand All @@ -300,7 +296,7 @@ public function provideInvalidUpdateFieldData()
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Field $field
*/
public function assertCopiedFieldDataLoadedCorrectly(Field $field)
public function assertCopiedFieldDataLoadedCorrectly(Field $field): void
{
self::assertInstanceOf(
RelationListValue::class,
Expand Down
Loading

0 comments on commit 4b9802e

Please sign in to comment.