Skip to content

Commit

Permalink
Replaced usages of magic getters with strict ones relevant to the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed May 23, 2024
1 parent 65bb33d commit 309d64a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
13 changes: 7 additions & 6 deletions src/lib/MVC/Symfony/SiteAccess/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ public function match(SimplifiedRequest $request)
}

// Request header always have precedence
// Note: request headers are always in lower cased.
if (!empty($request->headers['x-siteaccess'])) {
$siteaccessName = $request->headers['x-siteaccess'][0];
if (!$this->siteAccessProvider->isDefined($siteaccessName)) {
// Note: request headers are always lower case.
$xSiteAccess = $request->getHeader('x-siteaccess');
if (!empty($xSiteAccess) && is_array($xSiteAccess)) {
$siteAccessName = $xSiteAccess[0];
if (!$this->siteAccessProvider->isDefined($siteAccessName)) {
throw new InvalidSiteAccessException(
$siteaccessName,
$siteAccessName,
$this->siteAccessProvider,
'X-Siteaccess request header',
$this->debug
);
}

$this->siteAccess = $this->siteAccessProvider->getSiteAccess($siteaccessName);
$this->siteAccess = $this->siteAccessProvider->getSiteAccess($siteAccessName);
$this->siteAccess->matchingType = self::HEADER_SA_MATCHING_TYPE;

return $this->siteAccess;
Expand Down
6 changes: 2 additions & 4 deletions src/lib/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function loadContentInfoByRemoteId(string $remoteId): ContentInfo
*/
public function loadVersionInfo(ContentInfo $contentInfo, ?int $versionNo = null): APIVersionInfo
{
return $this->loadVersionInfoById($contentInfo->id, $versionNo);
return $this->loadVersionInfoById($contentInfo->getId(), $versionNo);
}

/**
Expand Down Expand Up @@ -2121,9 +2121,7 @@ public function countReverseRelations(ContentInfo $contentInfo): int
return 0;
}

return $this->persistenceHandler->contentHandler()->countReverseRelations(
$contentInfo->id
);
return $this->persistenceHandler->contentHandler()->countReverseRelations($contentInfo->getId());
}

/**
Expand Down
17 changes: 9 additions & 8 deletions src/lib/Repository/Mapper/ContentDomainMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ public function buildDomainFields(
}

$fieldDefinitionsMap = [];
foreach ($contentType->fieldDefinitions as $fieldDefinition) {
$fieldDefinitionsMap[$fieldDefinition->id] = $fieldDefinition;
foreach ($contentType->getFieldDefinitions() as $fieldDefinition) {

Check failure on line 240 in src/lib/Repository/Mapper/ContentDomainMapper.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Call to an undefined method Ibexa\Contracts\Core\Persistence\Content\Type|Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType::getFieldDefinitions().

Check failure on line 240 in src/lib/Repository/Mapper/ContentDomainMapper.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Call to an undefined method Ibexa\Contracts\Core\Persistence\Content\Type|Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType::getFieldDefinitions().

Check failure on line 240 in src/lib/Repository/Mapper/ContentDomainMapper.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Call to an undefined method Ibexa\Contracts\Core\Persistence\Content\Type|Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType::getFieldDefinitions().
$fieldDefinitionsMap[$fieldDefinition->getId()] = $fieldDefinition;
}

$fieldInFilterLanguagesMap = [];
if (!empty($prioritizedLanguages) && $alwaysAvailableLanguage !== null) {
foreach ($spiFields as $spiField) {
if (in_array($spiField->languageCode, $prioritizedLanguages)) {
if (in_array($spiField->languageCode, $prioritizedLanguages, true)) {
$fieldInFilterLanguagesMap[$spiField->fieldDefinitionId] = true;
}
}
Expand All @@ -259,7 +259,7 @@ public function buildDomainFields(

$fieldDefinition = $fieldDefinitionsMap[$spiField->fieldDefinitionId];

if (!empty($prioritizedLanguages) && !in_array($spiField->languageCode, $prioritizedLanguages)) {
if (!empty($prioritizedLanguages) && !in_array($spiField->languageCode, $prioritizedLanguages, true)) {
// If filtering is enabled we ignore fields in other languages then $prioritizedLanguages, if:
if ($alwaysAvailableLanguage === null) {
// Ignore field if we don't have $alwaysAvailableLanguageCode fallback
Expand All @@ -273,13 +273,13 @@ public function buildDomainFields(
}
}

$fields[$fieldDefinition->position][] = new Field(
$fields[$fieldDefinition->getPosition()][] = new Field(
[
'id' => $spiField->id,
'value' => $this->fieldTypeRegistry->getFieldType($spiField->type)
->fromPersistenceValue($spiField->value),
'languageCode' => $spiField->languageCode,
'fieldDefIdentifier' => $fieldDefinition->identifier,
'fieldDefIdentifier' => $fieldDefinition->getIdentifier(),
'fieldTypeIdentifier' => $spiField->type,
]
);
Expand Down Expand Up @@ -536,12 +536,13 @@ private function buildRootLocation(SPILocation $spiLocation): APILocation
'alwaysAvailable' => 1,
'remoteId' => null,
'mainLanguageCode' => 'eng-GB',
'isHidden' => false,
]);

$content = new Content([
'versionInfo' => new VersionInfo([
'names' => [
$contentInfo->mainLanguageCode => $contentInfo->name,
$contentInfo->getMainLanguageCode() => $contentInfo->getName(),
],
'contentInfo' => $contentInfo,
'versionNo' => $contentInfo->currentVersionNo,
Expand Down Expand Up @@ -571,7 +572,7 @@ private function mapLocation(
'contentInfo' => $contentInfo,
'id' => $spiLocation->id,
'priority' => $spiLocation->priority,
'hidden' => $spiLocation->hidden || $contentInfo->isHidden,
'hidden' => $spiLocation->hidden || $contentInfo->isHidden(),
'invisible' => $spiLocation->invisible,
'explicitlyHidden' => $spiLocation->hidden,
'remoteId' => $spiLocation->remoteId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ private function setLocationMappings(iterable $locationList): void
{
foreach ($locationList as $location) {
$this->contentLocationMapper->setMapping(
$location->id,
$location->contentId
$location->getId(),
$location->getContentId()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public function getThumbnail(ContentType $contentType, array $fields, ?VersionIn
$fieldDefinitions = $contentType->getFieldDefinitions();

foreach ($fieldDefinitions as $fieldDefinition) {
$field = $this->getFieldByIdentifier($fieldDefinition->identifier, $fields);
$field = $this->getFieldByIdentifier($fieldDefinition->getIdentifier(), $fields);

if ($field === null) {
continue;
}

$fieldType = $this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier);
$fieldType = $this->fieldTypeService->getFieldType($fieldDefinition->getFieldTypeIdentifier());

if (
$fieldDefinition->isThumbnail
&& $this->contentFieldStrategy->hasStrategy($field->fieldTypeIdentifier)
&& !$fieldType->isEmptyValue($field->value)
$fieldDefinition->isThumbnail()
&& $this->contentFieldStrategy->hasStrategy($field->getFieldTypeIdentifier())
&& !$fieldType->isEmptyValue($field->getValue())
) {
return $this->contentFieldStrategy->getThumbnail($field, $versionInfo);
}
Expand All @@ -61,7 +61,7 @@ private function getFieldByIdentifier(string $identifier, array $fields): ?Field
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Field $field */
foreach ($fields as $field) {
if ($field->fieldDefIdentifier === $identifier) {
if ($field->getFieldDefinitionIdentifier() === $identifier) {
return $field;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Repository/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ public function loadUser(int $userId, array $prioritizedLanguages = []): APIUser
$content = $this->repository->getContentService()->internalLoadContentById($userId, $prioritizedLanguages);
// Get spiUser value from Field Value
foreach ($content->getFields() as $field) {
if (!$field->value instanceof UserValue) {
$fieldValue = $field->getValue();
if (!$fieldValue instanceof UserValue) {
continue;
}

/** @var \Ibexa\Core\FieldType\User\Value $value */
$value = $field->value;
$value = $fieldValue;
$spiUser = new SPIUser();
$spiUser->id = $value->contentId;
$spiUser->login = $value->login;
Expand Down
10 changes: 6 additions & 4 deletions src/lib/Repository/Values/Content/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public function __construct(array $data = [])
$this->prioritizedFieldLanguageCode = $data['prioritizedFieldLanguageCode'] ?? null;

foreach ($this->internalFields as $field) {
$this->fieldDefinitionTranslationMap[$field->fieldDefIdentifier][$field->languageCode] = $field;
$languageCode = $field->getLanguageCode();
$fieldDefinitionIdentifier = $field->getFieldDefinitionIdentifier();
$this->fieldDefinitionTranslationMap[$fieldDefinitionIdentifier][$languageCode] = $field;
// kept for BC due to property-read magic getter
$this->fields[$field->fieldDefIdentifier][$field->languageCode] = $field->value;
$this->fields[$fieldDefinitionIdentifier][$languageCode] = $field->getValue();
}
}

Expand Down Expand Up @@ -182,10 +184,10 @@ public function __get($property)
{
switch ($property) {
case 'id':
return $this->versionInfo->getContentInfo()->id;
return $this->getVersionInfo()->getContentInfo()->getId();

case 'contentInfo':
return $this->versionInfo->getContentInfo();
return $this->getVersionInfo()->getContentInfo();

case 'thumbnail':
return $this->getThumbnail();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Repository/Values/Content/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __get($property)
{
switch ($property) {
case 'contentId':
return $this->contentInfo->id;
return $this->getContentInfo()->getId();
case 'path':
if ($this->path !== null) {
return $this->path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(iterable $fieldDefinitions = [])

foreach ($fieldDefinitions as $fieldDefinition) {
$this->fieldDefinitions[] = $fieldDefinition;
$this->fieldDefinitionsByIdentifier[$fieldDefinition->identifier] = $fieldDefinition;
$this->fieldDefinitionsByIdentifier[$fieldDefinition->getIdentifier()] = $fieldDefinition;
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public function toArray(): array
private function getIsTypePredicate(string $fieldTypeIdentifier): Closure
{
return static function (FieldDefinition $fieldDefinition) use ($fieldTypeIdentifier) {
return $fieldDefinition->fieldTypeIdentifier === $fieldTypeIdentifier;
return $fieldDefinition->getFieldTypeIdentifier() === $fieldTypeIdentifier;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Repository/Values/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function __get($property)
return $this->getVersionInfo()->getContentInfo();

case 'id':
return $this->getVersionInfo()->getContentInfo()->id;
return $this->getVersionInfo()->getContentInfo()->getId();

case 'versionInfo':
return $this->getVersionInfo();
Expand Down

0 comments on commit 309d64a

Please sign in to comment.