Skip to content

Commit

Permalink
Add type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
cundd committed Dec 19, 2018
1 parent 52dca42 commit 7d1648b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 82 deletions.
24 changes: 12 additions & 12 deletions Classes/VirtualObject/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct($configurationData = [])
*
* @return array
*/
public function getAllProperties()
public function getAllProperties(): array
{
return array_keys($this->configurationData['properties']);
}
Expand All @@ -54,7 +54,7 @@ public function getAllProperties()
*
* @return array
*/
public function getAllSourceKeys()
public function getAllSourceKeys(): array
{
return array_map(
function ($item) {
Expand All @@ -70,7 +70,7 @@ function ($item) {
* @param string $propertyName
* @return boolean
*/
public function hasProperty($propertyName)
public function hasProperty(string $propertyName): bool
{
return isset($this->configurationData['properties'][$propertyName]);
}
Expand All @@ -83,7 +83,7 @@ public function hasProperty($propertyName)
* @param string $sourceKey
* @return boolean
*/
public function hasSourceKey($sourceKey)
public function hasSourceKey(string $sourceKey): bool
{
$sourceKeyToPropertyMap = $this->getSourceKeyToPropertyMap();

Expand All @@ -96,7 +96,7 @@ public function hasSourceKey($sourceKey)
* @param string $propertyName
* @return array
*/
public function getConfigurationForProperty($propertyName)
public function getConfigurationForProperty(string $propertyName)
{
return isset($this->configurationData['properties'][$propertyName])
? $this->configurationData['properties'][$propertyName]
Expand All @@ -109,7 +109,7 @@ public function getConfigurationForProperty($propertyName)
* @param string $propertyName
* @return string
*/
public function getSourceKeyForProperty($propertyName)
public function getSourceKeyForProperty($propertyName): ?string
{
if (!$this->hasProperty($propertyName)) {
return null;
Expand All @@ -126,7 +126,7 @@ public function getSourceKeyForProperty($propertyName)
* @param string $sourceKey
* @return string
*/
public function getPropertyForSourceKey($sourceKey)
public function getPropertyForSourceKey(string $sourceKey): ?string
{
$sourceKeyToPropertyMap = $this->getSourceKeyToPropertyMap();

Expand All @@ -141,7 +141,7 @@ public function getPropertyForSourceKey($sourceKey)
* @param string $propertyName
* @return string Returns one of the following: "string", "float", "int", "integer", "bool", "boolean"
*/
public function getTypeForProperty($propertyName)
public function getTypeForProperty(string $propertyName): ?string
{
if (!$this->hasProperty($propertyName)) {
return null;
Expand All @@ -157,7 +157,7 @@ public function getTypeForProperty($propertyName)
*
* @return string
*/
public function getSourceIdentifier()
public function getSourceIdentifier(): ?string
{
return isset($this->configurationData['tableName'])
? $this->configurationData['tableName']
Expand Down Expand Up @@ -186,7 +186,7 @@ public function getSourceKeyToPropertyMap()
* @param boolean $skipUnknownProperties
* @return $this
*/
public function setSkipUnknownProperties($skipUnknownProperties)
public function setSkipUnknownProperties(bool $skipUnknownProperties): self
{
$this->skipUnknownProperties = $skipUnknownProperties;

Expand All @@ -198,7 +198,7 @@ public function setSkipUnknownProperties($skipUnknownProperties)
*
* @return boolean
*/
public function shouldSkipUnknownProperties()
public function shouldSkipUnknownProperties(): bool
{
return $this->skipUnknownProperties;
}
Expand All @@ -208,7 +208,7 @@ public function shouldSkipUnknownProperties()
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): ?string
{
return isset($this->configurationData['identifier']) ? $this->configurationData['identifier'] : null;
}
Expand Down
44 changes: 22 additions & 22 deletions Classes/VirtualObject/ConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
interface ConfigurationInterface
{
/**
* Returns the list of all properties
* Return the list of all properties
*
* @return array
*/
public function getAllProperties();
public function getAllProperties(): array;

/**
* Returns the list of all source keys
* Return the list of all source keys
*
* @return array
*/
public function getAllSourceKeys();
public function getAllSourceKeys(): array;

/**
* Returns TRUE if the given property name exists
*
* @param string $propertyName
* @return boolean
*/
public function hasProperty($propertyName);
public function hasProperty(string $propertyName): bool;

/**
* Returns TRUE if the given source key is mapped
Expand All @@ -41,66 +41,66 @@ public function hasProperty($propertyName);
* @param string $sourceKey
* @return boolean
*/
public function hasSourceKey($sourceKey);
public function hasSourceKey(string $sourceKey): bool;

/**
* Returns the configuration for the given property name
* Return the configuration for the given property name
*
* @param string $propertyName
* @return array
*/
public function getConfigurationForProperty($propertyName);
public function getConfigurationForProperty(string $propertyName);

/**
* Returns the source key (column name) for the given property name
* Return the source key (column name) for the given property name, or NULL if it isn't defined
*
* @param string $propertyName
* @return string
* @return string|null
*/
public function getSourceKeyForProperty($propertyName);
public function getSourceKeyForProperty($propertyName): ?string;

/**
* Returns the property for the given source property (column)
* Return the property for the given source property (column)
*
* @param $sourceKey
* @param string $sourceKey
* @return string
*/
public function getPropertyForSourceKey($sourceKey);
public function getPropertyForSourceKey(string $sourceKey): ?string;

/**
* Returns the data type for the given property name
* Return the data type for the given property name
*
* @param string $propertyName
* @return string Returns one of the following simple "string", "float", "int", "integer", "bool", "boolean" or one of the complex types
*/
public function getTypeForProperty($propertyName);
public function getTypeForProperty(string $propertyName): ?string;

/**
* Returns the source identifier (the database table name)
* Return the source identifier (the database table name)
*
* @return string
*/
public function getSourceIdentifier();
public function getSourceIdentifier(): ?string;

/**
* Returns the name of the property which uniquely identifies an object
* Return the name of the property which uniquely identifies an object
*
* @return string
*/
public function getIdentifier();
public function getIdentifier(): ?string;

/**
* Set whether unknown (un-configured) properties should be skipped during mapping, or throw an exception
*
* @param boolean $skipUnknownProperties
* @return $this
*/
public function setSkipUnknownProperties($skipUnknownProperties);
public function setSkipUnknownProperties(bool $skipUnknownProperties): self;

/**
* Return whether unknown (un-configured) properties should be skipped during mapping, or throw an exception
*
* @return boolean
*/
public function shouldSkipUnknownProperties();
public function shouldSkipUnknownProperties(): bool;
}
68 changes: 36 additions & 32 deletions Classes/VirtualObject/Persistence/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cundd\Rest\VirtualObject\Persistence;

use Cundd\Rest\VirtualObject\ConfigurationInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement;

/**
Expand Down Expand Up @@ -48,47 +49,68 @@ class Query implements QueryInterface
*/
protected $statement;

/**
* Query constructor
*
* @param array $constraint
* @param array $orderings
* @param int $limit
* @param int $offset
* @param string $sourceIdentifier
* @param PersistenceManager $persistenceManager
*/
public function __construct(
array $constraint = [],
array $orderings = [],
int $limit = 0,
int $offset = 0,
string $sourceIdentifier = null,
PersistenceManager $persistenceManager = null
) {
$this->persistenceManager = $persistenceManager;
$this->constraint = $constraint;
$this->orderings = $orderings;
$this->limit = $limit;
$this->offset = $offset;
$this->sourceIdentifier = $sourceIdentifier;
}


public function execute()
{
return $this->persistenceManager->getObjectDataByQuery($this);
}

public function count()
public function count(): int
{
return $this->persistenceManager->getObjectCountByQuery($this);
}

public function getOrderings()
public function getOrderings(): array
{
return $this->orderings;
}

public function getLimit()
public function getLimit(): int
{
return $this->limit;
}

public function getOffset()
public function getOffset(): int
{
return $this->offset;
}

public function getConstraint()
public function getConstraint(): array
{
return $this->constraint;
}

public function getSourceIdentifier()
public function getSourceIdentifier(): string
{
return $this->sourceIdentifier;
}

/**
* Return a copy of the Query with the given constraints
*
* @param array $constraint
* @return QueryInterface
*/
public function withConstraints(array $constraint): QueryInterface
{
$clone = clone $this;
Expand All @@ -97,12 +119,6 @@ public function withConstraints(array $constraint): QueryInterface
return $clone;
}

/**
* Return a copy of the Query with the given orderings
*
* @param array $orderings
* @return QueryInterface
*/
public function withOrderings(array $orderings): QueryInterface
{
$clone = clone $this;
Expand All @@ -111,12 +127,6 @@ public function withOrderings(array $orderings): QueryInterface
return $clone;
}

/**
* Return a copy of the Query with the given limit
*
* @param int $limit
* @return QueryInterface
*/
public function withLimit(int $limit): QueryInterface
{
$clone = clone $this;
Expand All @@ -125,12 +135,6 @@ public function withLimit(int $limit): QueryInterface
return $clone;
}

/**
* Return a copy of the Query with the given offset
*
* @param int $offset
* @return QueryInterface
*/
public function withOffset(int $offset): QueryInterface
{
$clone = clone $this;
Expand All @@ -139,14 +143,14 @@ public function withOffset(int $offset): QueryInterface
return $clone;
}

public function setConfiguration($configuration)
public function setConfiguration($configuration): QueryInterface
{
$this->persistenceManager->setConfiguration($configuration);

return $this;
}

public function getConfiguration()
public function getConfiguration(): ?ConfigurationInterface
{
return $this->persistenceManager->getConfiguration();
}
Expand Down
Loading

0 comments on commit 7d1648b

Please sign in to comment.