Skip to content

Commit

Permalink
Extracted common code for Binary and Media field type (#407)
Browse files Browse the repository at this point in the history
For more details see #407

Key changes:

* Extracted redundant Binary and Media SearchField into a common base

* [Tests] Extracted common base for Binary and Media ft integration tests

* [Tests] Made MediaIntegrationTest::getValidFieldSettings return type more strict

* [PHPStan] Aligned baseline with the changes

---------

Co-authored-by: Adam Wójs <[email protected]>
Co-authored-by: Mikolaj Adamczyk <[email protected]>
  • Loading branch information
3 people authored and barw4 committed Oct 17, 2024
1 parent d0b9826 commit 61ddcc5
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 901 deletions.
185 changes: 0 additions & 185 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29310,101 +29310,6 @@ parameters:
count: 1
path: tests/integration/Core/Repository/FieldType/BaseIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertFieldDataLoadedCorrect\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) should return array but return statement is missing\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:checkSearchEngineSupport\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getAdditionallyIndexedFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getFixtureData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getSettingsSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getStoragePrefix\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) should return array but returns Ibexa\\\\Core\\\\FieldType\\\\BinaryFile\\\\Value\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidatorSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideFromHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideInvalidCreationFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideInvalidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideToHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:providerForTestIsEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:providerForTestIsNotEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Property Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:\\$loadedBinaryFilePath has no type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php

-
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -30305,96 +30210,6 @@ parameters:
count: 1
path: tests/integration/Core/Repository/FieldType/MapLocationIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertFieldDataLoadedCorrect\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) should return array but return statement is missing\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getAdditionallyIndexedFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getFixtureData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getSettingsSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getStoragePrefix\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) should return array but returns Ibexa\\\\Core\\\\FieldType\\\\Media\\\\Value\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidatorSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideFromHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideInvalidCreationFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideInvalidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideToHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:providerForTestIsEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:providerForTestIsNotEmptyValue\\(\\) has no return type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Property Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:\\$loadedMediaPath has no type specified\\.$#"
count: 1
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\RelationIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
66 changes: 66 additions & 0 deletions src/lib/FieldType/BinaryBase/AbstractBinarySearchField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\FieldType\BinaryBase;

use Ibexa\Contracts\Core\FieldType\Indexable;
use Ibexa\Contracts\Core\Persistence\Content\Field;
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
use Ibexa\Contracts\Core\Search;

/**
* @internal
*/
abstract class AbstractBinarySearchField implements Indexable
{
/**
* @return \Ibexa\Contracts\Core\Search\Field[]
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition): array
{
return [
new Search\Field(
'file_name',
$field->value->externalData['fileName'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->externalData['fileSize'] ?? null,
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->externalData['mimeType'] ?? null,
new Search\FieldType\StringField()
),
];
}

/**
* @return array<string, \Ibexa\Contracts\Core\Search\FieldType>
*/
public function getIndexDefinition(): array
{
return [
'file_name' => new Search\FieldType\StringField(),
'file_size' => new Search\FieldType\IntegerField(),
'mime_type' => new Search\FieldType\StringField(),
];
}

public function getDefaultMatchField(): string
{
return 'file_name';
}

public function getDefaultSortField(): string
{
return $this->getDefaultMatchField();
}
}
65 changes: 3 additions & 62 deletions src/lib/FieldType/BinaryFile/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,15 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\FieldType\BinaryFile;

use Ibexa\Contracts\Core\FieldType\Indexable;
use Ibexa\Contracts\Core\Persistence\Content\Field;
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
use Ibexa\Contracts\Core\Search;
use Ibexa\Core\FieldType\BinaryBase\AbstractBinarySearchField;

/**
* Indexable definition for BinaryFile field type.
*/
class SearchField implements Indexable
class SearchField extends AbstractBinarySearchField
{
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
{
return [
new Search\Field(
'file_name',
$field->value->externalData['fileName'] ?? null,
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->externalData['fileSize'] ?? null,
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->externalData['mimeType'] ?? null,
new Search\FieldType\StringField()
),
];
}

public function getIndexDefinition()
{
return [
'file_name' => new Search\FieldType\StringField(),
'file_size' => new Search\FieldType\IntegerField(),
'mime_type' => new Search\FieldType\StringField(),
];
}

/**
* Get name of the default field to be used for matching.
*
* As field types can index multiple fields (see MapLocation field type's
* implementation of this interface), this method is used to define default
* field for matching. Default field is typically used by Field criterion.
*
* @return string
*/
public function getDefaultMatchField()
{
return 'file_name';
}

/**
* Get name of the default field to be used for sorting.
*
* As field types can index multiple fields (see MapLocation field type's
* implementation of this interface), this method is used to define default
* field for sorting. Default field is typically used by Field sort clause.
*
* @return string
*/
public function getDefaultSortField()
{
return $this->getDefaultMatchField();
}
}
Loading

0 comments on commit 61ddcc5

Please sign in to comment.