Skip to content

Commit 61ddcc5

Browse files
alongoszadamwojsmikadamczyk
authored andcommitted
Extracted common code for Binary and Media field type (#407)
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]>
1 parent d0b9826 commit 61ddcc5

File tree

7 files changed

+381
-901
lines changed

7 files changed

+381
-901
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -29310,101 +29310,6 @@ parameters:
2931029310
count: 1
2931129311
path: tests/integration/Core/Repository/FieldType/BaseIntegrationTest.php
2931229312

29313-
-
29314-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
29315-
count: 1
29316-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29317-
29318-
-
29319-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertFieldDataLoadedCorrect\\(\\) has no return type specified\\.$#"
29320-
count: 1
29321-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29322-
29323-
-
29324-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) return type has no value type specified in iterable type array\\.$#"
29325-
count: 1
29326-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29327-
29328-
-
29329-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) should return array but return statement is missing\\.$#"
29330-
count: 1
29331-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29332-
29333-
-
29334-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:checkSearchEngineSupport\\(\\) has no return type specified\\.$#"
29335-
count: 1
29336-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29337-
29338-
-
29339-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getAdditionallyIndexedFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
29340-
count: 1
29341-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29342-
29343-
-
29344-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getFixtureData\\(\\) return type has no value type specified in iterable type array\\.$#"
29345-
count: 1
29346-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29347-
29348-
-
29349-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getSettingsSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
29350-
count: 1
29351-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29352-
29353-
-
29354-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getStoragePrefix\\(\\) has no return type specified\\.$#"
29355-
count: 1
29356-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29357-
29358-
-
29359-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
29360-
count: 1
29361-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29362-
29363-
-
29364-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) should return array but returns Ibexa\\\\Core\\\\FieldType\\\\BinaryFile\\\\Value\\.$#"
29365-
count: 1
29366-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29367-
29368-
-
29369-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:getValidatorSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
29370-
count: 1
29371-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29372-
29373-
-
29374-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideFromHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
29375-
count: 1
29376-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29377-
29378-
-
29379-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideInvalidCreationFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
29380-
count: 1
29381-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29382-
29383-
-
29384-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideInvalidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
29385-
count: 1
29386-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29387-
29388-
-
29389-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:provideToHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
29390-
count: 1
29391-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29392-
29393-
-
29394-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:providerForTestIsEmptyValue\\(\\) has no return type specified\\.$#"
29395-
count: 1
29396-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29397-
29398-
-
29399-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:providerForTestIsNotEmptyValue\\(\\) has no return type specified\\.$#"
29400-
count: 1
29401-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29402-
29403-
-
29404-
message: "#^Property Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\BinaryFileIntegrationTest\\:\\:\\$loadedBinaryFilePath has no type specified\\.$#"
29405-
count: 1
29406-
path: tests/integration/Core/Repository/FieldType/BinaryFileIntegrationTest.php
29407-
2940829313
-
2940929314
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
2941029315
count: 1
@@ -30305,96 +30210,6 @@ parameters:
3030530210
count: 1
3030630211
path: tests/integration/Core/Repository/FieldType/MapLocationIntegrationTest.php
3030730212

30308-
-
30309-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
30310-
count: 1
30311-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30312-
30313-
-
30314-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertFieldDataLoadedCorrect\\(\\) has no return type specified\\.$#"
30315-
count: 1
30316-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30317-
30318-
-
30319-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) return type has no value type specified in iterable type array\\.$#"
30320-
count: 1
30321-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30322-
30323-
-
30324-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:assertUpdatedFieldDataLoadedCorrect\\(\\) should return array but return statement is missing\\.$#"
30325-
count: 1
30326-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30327-
30328-
-
30329-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getAdditionallyIndexedFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
30330-
count: 1
30331-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30332-
30333-
-
30334-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getFixtureData\\(\\) return type has no value type specified in iterable type array\\.$#"
30335-
count: 1
30336-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30337-
30338-
-
30339-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getSettingsSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
30340-
count: 1
30341-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30342-
30343-
-
30344-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getStoragePrefix\\(\\) has no return type specified\\.$#"
30345-
count: 1
30346-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30347-
30348-
-
30349-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
30350-
count: 1
30351-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30352-
30353-
-
30354-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidUpdateFieldData\\(\\) should return array but returns Ibexa\\\\Core\\\\FieldType\\\\Media\\\\Value\\.$#"
30355-
count: 1
30356-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30357-
30358-
-
30359-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:getValidatorSchema\\(\\) return type has no value type specified in iterable type array\\.$#"
30360-
count: 1
30361-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30362-
30363-
-
30364-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideFromHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
30365-
count: 1
30366-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30367-
30368-
-
30369-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideInvalidCreationFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
30370-
count: 1
30371-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30372-
30373-
-
30374-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideInvalidUpdateFieldData\\(\\) return type has no value type specified in iterable type array\\.$#"
30375-
count: 1
30376-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30377-
30378-
-
30379-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:provideToHashData\\(\\) return type has no value type specified in iterable type array\\.$#"
30380-
count: 1
30381-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30382-
30383-
-
30384-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:providerForTestIsEmptyValue\\(\\) has no return type specified\\.$#"
30385-
count: 1
30386-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30387-
30388-
-
30389-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:providerForTestIsNotEmptyValue\\(\\) has no return type specified\\.$#"
30390-
count: 1
30391-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30392-
30393-
-
30394-
message: "#^Property Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\MediaIntegrationTest\\:\\:\\$loadedMediaPath has no type specified\\.$#"
30395-
count: 1
30396-
path: tests/integration/Core/Repository/FieldType/MediaIntegrationTest.php
30397-
3039830213
-
3039930214
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\FieldType\\\\RelationIntegrationTest\\:\\:assertCopiedFieldDataLoadedCorrectly\\(\\) has no return type specified\\.$#"
3040030215
count: 1
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Core\FieldType\BinaryBase;
10+
11+
use Ibexa\Contracts\Core\FieldType\Indexable;
12+
use Ibexa\Contracts\Core\Persistence\Content\Field;
13+
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
14+
use Ibexa\Contracts\Core\Search;
15+
16+
/**
17+
* @internal
18+
*/
19+
abstract class AbstractBinarySearchField implements Indexable
20+
{
21+
/**
22+
* @return \Ibexa\Contracts\Core\Search\Field[]
23+
*/
24+
public function getIndexData(Field $field, FieldDefinition $fieldDefinition): array
25+
{
26+
return [
27+
new Search\Field(
28+
'file_name',
29+
$field->value->externalData['fileName'] ?? null,
30+
new Search\FieldType\StringField()
31+
),
32+
new Search\Field(
33+
'file_size',
34+
$field->value->externalData['fileSize'] ?? null,
35+
new Search\FieldType\IntegerField()
36+
),
37+
new Search\Field(
38+
'mime_type',
39+
$field->value->externalData['mimeType'] ?? null,
40+
new Search\FieldType\StringField()
41+
),
42+
];
43+
}
44+
45+
/**
46+
* @return array<string, \Ibexa\Contracts\Core\Search\FieldType>
47+
*/
48+
public function getIndexDefinition(): array
49+
{
50+
return [
51+
'file_name' => new Search\FieldType\StringField(),
52+
'file_size' => new Search\FieldType\IntegerField(),
53+
'mime_type' => new Search\FieldType\StringField(),
54+
];
55+
}
56+
57+
public function getDefaultMatchField(): string
58+
{
59+
return 'file_name';
60+
}
61+
62+
public function getDefaultSortField(): string
63+
{
64+
return $this->getDefaultMatchField();
65+
}
66+
}

src/lib/FieldType/BinaryFile/SearchField.php

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,15 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Core\FieldType\BinaryFile;
910

10-
use Ibexa\Contracts\Core\FieldType\Indexable;
11-
use Ibexa\Contracts\Core\Persistence\Content\Field;
12-
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
13-
use Ibexa\Contracts\Core\Search;
11+
use Ibexa\Core\FieldType\BinaryBase\AbstractBinarySearchField;
1412

1513
/**
1614
* Indexable definition for BinaryFile field type.
1715
*/
18-
class SearchField implements Indexable
16+
class SearchField extends AbstractBinarySearchField
1917
{
20-
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
21-
{
22-
return [
23-
new Search\Field(
24-
'file_name',
25-
$field->value->externalData['fileName'] ?? null,
26-
new Search\FieldType\StringField()
27-
),
28-
new Search\Field(
29-
'file_size',
30-
$field->value->externalData['fileSize'] ?? null,
31-
new Search\FieldType\IntegerField()
32-
),
33-
new Search\Field(
34-
'mime_type',
35-
$field->value->externalData['mimeType'] ?? null,
36-
new Search\FieldType\StringField()
37-
),
38-
];
39-
}
40-
41-
public function getIndexDefinition()
42-
{
43-
return [
44-
'file_name' => new Search\FieldType\StringField(),
45-
'file_size' => new Search\FieldType\IntegerField(),
46-
'mime_type' => new Search\FieldType\StringField(),
47-
];
48-
}
49-
50-
/**
51-
* Get name of the default field to be used for matching.
52-
*
53-
* As field types can index multiple fields (see MapLocation field type's
54-
* implementation of this interface), this method is used to define default
55-
* field for matching. Default field is typically used by Field criterion.
56-
*
57-
* @return string
58-
*/
59-
public function getDefaultMatchField()
60-
{
61-
return 'file_name';
62-
}
63-
64-
/**
65-
* Get name of the default field to be used for sorting.
66-
*
67-
* As field types can index multiple fields (see MapLocation field type's
68-
* implementation of this interface), this method is used to define default
69-
* field for sorting. Default field is typically used by Field sort clause.
70-
*
71-
* @return string
72-
*/
73-
public function getDefaultSortField()
74-
{
75-
return $this->getDefaultMatchField();
76-
}
7718
}

0 commit comments

Comments
 (0)