Skip to content

Commit

Permalink
fix: Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Paweł Niedzielski <pawel.niedzielski@ibexa.co>
  • Loading branch information
Nattfarinn and Steveb-p authored Mar 21, 2024
1 parent aa1a848 commit b1d6e31
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
3 changes: 3 additions & 0 deletions eZ/Publish/API/Repository/Values/Content/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public function getFieldTypeIdentifier(): string
return $this->fieldTypeIdentifier;
}

/**
* @phpstan-assert-if-true !null $this->getId()
*/
public function isVirtual(): bool
{
return null === $this->id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function getEmptyField(FieldDefinition $fieldDefinition, $languageCode
public function createExistingFieldsInNewVersion(Content $content): void
{
foreach ($content->fields as $field) {
if ($field->id === null) {
if ($field->getId() === null) {
// Virtual field with default value, skip creating field as it has no id
continue;
}
Expand Down
35 changes: 29 additions & 6 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,35 @@
*
* Performs mapping of Content objects.
*
* @phpstan-type TVersionedLanguageFieldDefinitionsMap array<int, array<int, array<string, array<int, \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition>>>>
* @phpstan-type TVersionedFieldMap array<int, array<int, array<int, \eZ\Publish\SPI\Persistence\Content\Field>>>
* @phpstan-type TVersionedNameMap array<int, array<int, array<string, array<int, string>>>>
* @phpstan-type TVersionedLanguageFieldDefinitionsMap array<
int, array<
int, array<
string, array<
int, \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition,
>
>
>
>
* @phpstan-type TVersionedFieldMap array<
int, array<
int, array<
int, \eZ\Publish\SPI\Persistence\Content\Field,
>
>
>
* @phpstan-type TVersionedNameMap array<
int, array<
int, array<
string, array<int, string>
>
>
>
* @phpstan-type TContentInfoMap array<int, \eZ\Publish\SPI\Persistence\Content\ContentInfo>
* @phpstan-type TVersionInfoMap array<int, array<int, \eZ\Publish\SPI\Persistence\Content\VersionInfo>>
* @phpstan-type TVersionInfoMap array<
int, array<
int, \eZ\Publish\SPI\Persistence\Content\VersionInfo,
>
>
*/
class Mapper
{
Expand Down Expand Up @@ -324,8 +348,7 @@ private function loadCachedVersionFieldDefinitionsPerLanguage(
}

$languageCodes = $this->extractLanguageCodesFromMask($languageMask, $allLanguages);
$contentType = $contentTypes[$contentTypeId] = $contentTypes[$contentTypeId]
?? $this->contentTypeHandler->load($contentTypeId);
$contentType = $contentTypes[$contentTypeId] ??= $this->contentTypeHandler->load($contentTypeId);

Check failure on line 351 in eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php

View workflow job for this annotation

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

Syntax error, unexpected '=' on line 351
foreach ($contentType->fieldDefinitions as $fieldDefinition) {
foreach ($languageCodes as $languageCode) {
$id = $fieldDefinition->id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function copyFieldData(VersionInfo $versionInfo, Field $field, Field $ori
public function getFieldData(VersionInfo $versionInfo, Field $field)
{
$storage = $this->storageRegistry->getStorage($field->type);
if ($field->id !== null && $storage->hasFieldData()) {
if ($field->getId() !== null && $storage->hasFieldData()) {
$storage->getFieldData($versionInfo, $field, $this->context);
}
}
Expand Down
14 changes: 8 additions & 6 deletions eZ/Publish/Core/Persistence/Legacy/Tests/Content/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ static function (Content\Type\FieldDefinition $fieldDefinition) {
$result = $mapper->extractContentFromRows($rowsFixture, $nameRowsFixture);

$expectedContent = $this->getContentExtractReference();
$expectedContent->fields = array_values(array_filter($expectedContent->fields, static function (Field $field) {
return $field->fieldDefinitionId !== 185;
}));
$expectedContent->fields = array_values(
array_filter($expectedContent->fields, static function (Field $field): bool {
return $field->fieldDefinitionId !== 185;
})
);

$this->assertEquals(
[
Expand Down Expand Up @@ -331,8 +333,8 @@ private function getFieldRegistry(
$converterMock = $this->createMock(Converter::class);
$converterMock->expects(
$expectedConverterCalls === null
? self::any()
: self::exactly($expectedConverterCalls)
? self::any()
: self::exactly($expectedConverterCalls)
)
->method('toFieldValue')
->willReturn(new FieldValue());
Expand Down Expand Up @@ -735,7 +737,7 @@ static function ($languageCode) use ($languages) {
}

/**
* @return Content\Type\Handler|\PHPUnit\Framework\MockObject\MockObject
* @return \eZ\Publish\SPI\Persistence\Content\Type\Handler&\PHPUnit\Framework\MockObject\MockObject
*/
protected function getContentTypeHandler()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testGetFieldDataNotAvailableForVirtualField()

$storageRegistryMock->expects(self::once())
->method('getStorage')
->with($this->equalTo('foobar'))
->with(self::equalTo('foobar'))
->willReturn($storageMock);

$field = new Field();
Expand Down

0 comments on commit b1d6e31

Please sign in to comment.