Skip to content

Commit

Permalink
EZP-31095: Introduced strict types for FieldTypeService (#2853)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs authored Nov 7, 2019
1 parent 0685d5f commit 696301a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
15 changes: 7 additions & 8 deletions eZ/Publish/API/Repository/FieldTypeService.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

/**
* File containing the eZ\Publish\API\Repository\FieldTypeService class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\API\Repository;

/**
* An implementation of this class provides access to FieldTypes.
*
* @see eZ\Publish\API\Repository\FieldType
* @see \eZ\Publish\API\Repository\FieldType
*/
interface FieldTypeService
{
Expand All @@ -20,7 +20,7 @@ interface FieldTypeService
*
* @return \eZ\Publish\API\Repository\FieldType[]
*/
public function getFieldTypes();
public function getFieldTypes(): iterable;

/**
* Returns the FieldType registered with the given identifier.
Expand All @@ -29,10 +29,9 @@ public function getFieldTypes();
*
* @return \eZ\Publish\API\Repository\FieldType
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* if there is no FieldType registered with $identifier
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if there is no FieldType registered with $identifier
*/
public function getFieldType($identifier);
public function getFieldType(string $identifier): FieldType;

/**
* Returns if there is a FieldType registered under $identifier.
Expand All @@ -41,5 +40,5 @@ public function getFieldType($identifier);
*
* @return bool
*/
public function hasFieldType($identifier);
public function hasFieldType(string $identifier): bool;
}
5 changes: 3 additions & 2 deletions eZ/Publish/Core/Helper/Tests/FieldHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use eZ\Publish\Core\FieldType\TextLine\Value;
use eZ\Publish\Core\Helper\FieldHelper;
use eZ\Publish\Core\Helper\TranslationHelper;
use eZ\Publish\Core\Repository\Values\ContentType\FieldType;
use PHPUnit\Framework\TestCase;

class FieldHelperTest extends TestCase
Expand Down Expand Up @@ -85,7 +86,7 @@ public function testIsFieldEmpty()
->expects($this->any())
->method('getFieldType')
->with('ezstring')
->will($this->returnValue($textLineFT));
->will($this->returnValue(new FieldType($textLineFT)));

$this->assertTrue($this->fieldHelper->isFieldEmpty($content, $fieldDefIdentifier));
}
Expand Down Expand Up @@ -131,7 +132,7 @@ public function testIsFieldNotEmpty()
->expects($this->any())
->method('getFieldType')
->with('ezstring')
->will($this->returnValue($textLineFT));
->will($this->returnValue(new FieldType($textLineFT)));

$this->assertFalse($this->fieldHelper->isFieldEmpty($content, $fieldDefIdentifier));
}
Expand Down
16 changes: 8 additions & 8 deletions eZ/Publish/Core/Repository/FieldTypeService.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?php

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

namespace eZ\Publish\Core\Repository;

use eZ\Publish\API\Repository\FieldTypeService as FieldTypeServiceInterface;
use eZ\Publish\API\Repository\FieldType as APIFieldType;
use eZ\Publish\Core\FieldType\FieldTypeRegistry;
use eZ\Publish\Core\Repository\Values\ContentType\FieldType;

/**
* An implementation of this class provides access to FieldTypes.
*
* @see eZ\Publish\API\Repository\FieldType
* @see \eZ\Publish\API\Repository\FieldType
*/
class FieldTypeService implements FieldTypeServiceInterface
{
Expand Down Expand Up @@ -44,7 +45,7 @@ public function __construct(FieldTypeRegistry $fieldTypeRegistry)
*
* @return \eZ\Publish\API\Repository\FieldType[]
*/
public function getFieldTypes()
public function getFieldTypes(): iterable
{
foreach ($this->fieldTypeRegistry->getFieldTypes() as $identifier => $spiFieldType) {
if (isset($this->fieldTypes[$identifier])) {
Expand All @@ -64,10 +65,9 @@ public function getFieldTypes()
*
* @return \eZ\Publish\API\Repository\FieldType
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* if there is no FieldType registered with $identifier
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if there is no FieldType registered with $identifier
*/
public function getFieldType($identifier)
public function getFieldType(string $identifier): APIFieldType
{
if (isset($this->fieldTypes[$identifier])) {
return $this->fieldTypes[$identifier];
Expand All @@ -83,7 +83,7 @@ public function getFieldType($identifier)
*
* @return bool
*/
public function hasFieldType($identifier)
public function hasFieldType(string $identifier): bool
{
return $this->fieldTypeRegistry->hasFieldType($identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace eZ\Publish\SPI\Repository\Decorator;

use eZ\Publish\API\Repository\FieldTypeService;
use eZ\Publish\API\Repository\FieldType;

abstract class FieldTypeServiceDecorator implements FieldTypeService
{
Expand All @@ -20,17 +21,17 @@ public function __construct(FieldTypeService $innerService)
$this->innerService = $innerService;
}

public function getFieldTypes()
public function getFieldTypes(): iterable
{
return $this->innerService->getFieldTypes();
}

public function getFieldType($identifier)
public function getFieldType(string $identifier): FieldType
{
return $this->innerService->getFieldType($identifier);
}

public function hasFieldType($identifier)
public function hasFieldType(string $identifier): bool
{
return $this->innerService->hasFieldType($identifier);
}
Expand Down

0 comments on commit 696301a

Please sign in to comment.