Skip to content

Commit 7d1648b

Browse files
committed
Add type definitions
1 parent 52dca42 commit 7d1648b

File tree

4 files changed

+88
-82
lines changed

4 files changed

+88
-82
lines changed

Classes/VirtualObject/Configuration.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct($configurationData = [])
4444
*
4545
* @return array
4646
*/
47-
public function getAllProperties()
47+
public function getAllProperties(): array
4848
{
4949
return array_keys($this->configurationData['properties']);
5050
}
@@ -54,7 +54,7 @@ public function getAllProperties()
5454
*
5555
* @return array
5656
*/
57-
public function getAllSourceKeys()
57+
public function getAllSourceKeys(): array
5858
{
5959
return array_map(
6060
function ($item) {
@@ -70,7 +70,7 @@ function ($item) {
7070
* @param string $propertyName
7171
* @return boolean
7272
*/
73-
public function hasProperty($propertyName)
73+
public function hasProperty(string $propertyName): bool
7474
{
7575
return isset($this->configurationData['properties'][$propertyName]);
7676
}
@@ -83,7 +83,7 @@ public function hasProperty($propertyName)
8383
* @param string $sourceKey
8484
* @return boolean
8585
*/
86-
public function hasSourceKey($sourceKey)
86+
public function hasSourceKey(string $sourceKey): bool
8787
{
8888
$sourceKeyToPropertyMap = $this->getSourceKeyToPropertyMap();
8989

@@ -96,7 +96,7 @@ public function hasSourceKey($sourceKey)
9696
* @param string $propertyName
9797
* @return array
9898
*/
99-
public function getConfigurationForProperty($propertyName)
99+
public function getConfigurationForProperty(string $propertyName)
100100
{
101101
return isset($this->configurationData['properties'][$propertyName])
102102
? $this->configurationData['properties'][$propertyName]
@@ -109,7 +109,7 @@ public function getConfigurationForProperty($propertyName)
109109
* @param string $propertyName
110110
* @return string
111111
*/
112-
public function getSourceKeyForProperty($propertyName)
112+
public function getSourceKeyForProperty($propertyName): ?string
113113
{
114114
if (!$this->hasProperty($propertyName)) {
115115
return null;
@@ -126,7 +126,7 @@ public function getSourceKeyForProperty($propertyName)
126126
* @param string $sourceKey
127127
* @return string
128128
*/
129-
public function getPropertyForSourceKey($sourceKey)
129+
public function getPropertyForSourceKey(string $sourceKey): ?string
130130
{
131131
$sourceKeyToPropertyMap = $this->getSourceKeyToPropertyMap();
132132

@@ -141,7 +141,7 @@ public function getPropertyForSourceKey($sourceKey)
141141
* @param string $propertyName
142142
* @return string Returns one of the following: "string", "float", "int", "integer", "bool", "boolean"
143143
*/
144-
public function getTypeForProperty($propertyName)
144+
public function getTypeForProperty(string $propertyName): ?string
145145
{
146146
if (!$this->hasProperty($propertyName)) {
147147
return null;
@@ -157,7 +157,7 @@ public function getTypeForProperty($propertyName)
157157
*
158158
* @return string
159159
*/
160-
public function getSourceIdentifier()
160+
public function getSourceIdentifier(): ?string
161161
{
162162
return isset($this->configurationData['tableName'])
163163
? $this->configurationData['tableName']
@@ -186,7 +186,7 @@ public function getSourceKeyToPropertyMap()
186186
* @param boolean $skipUnknownProperties
187187
* @return $this
188188
*/
189-
public function setSkipUnknownProperties($skipUnknownProperties)
189+
public function setSkipUnknownProperties(bool $skipUnknownProperties): self
190190
{
191191
$this->skipUnknownProperties = $skipUnknownProperties;
192192

@@ -198,7 +198,7 @@ public function setSkipUnknownProperties($skipUnknownProperties)
198198
*
199199
* @return boolean
200200
*/
201-
public function shouldSkipUnknownProperties()
201+
public function shouldSkipUnknownProperties(): bool
202202
{
203203
return $this->skipUnknownProperties;
204204
}
@@ -208,7 +208,7 @@ public function shouldSkipUnknownProperties()
208208
*
209209
* @return string
210210
*/
211-
public function getIdentifier()
211+
public function getIdentifier(): ?string
212212
{
213213
return isset($this->configurationData['identifier']) ? $this->configurationData['identifier'] : null;
214214
}

Classes/VirtualObject/ConfigurationInterface.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
interface ConfigurationInterface
1313
{
1414
/**
15-
* Returns the list of all properties
15+
* Return the list of all properties
1616
*
1717
* @return array
1818
*/
19-
public function getAllProperties();
19+
public function getAllProperties(): array;
2020

2121
/**
22-
* Returns the list of all source keys
22+
* Return the list of all source keys
2323
*
2424
* @return array
2525
*/
26-
public function getAllSourceKeys();
26+
public function getAllSourceKeys(): array;
2727

2828
/**
2929
* Returns TRUE if the given property name exists
3030
*
3131
* @param string $propertyName
3232
* @return boolean
3333
*/
34-
public function hasProperty($propertyName);
34+
public function hasProperty(string $propertyName): bool;
3535

3636
/**
3737
* Returns TRUE if the given source key is mapped
@@ -41,66 +41,66 @@ public function hasProperty($propertyName);
4141
* @param string $sourceKey
4242
* @return boolean
4343
*/
44-
public function hasSourceKey($sourceKey);
44+
public function hasSourceKey(string $sourceKey): bool;
4545

4646
/**
47-
* Returns the configuration for the given property name
47+
* Return the configuration for the given property name
4848
*
4949
* @param string $propertyName
5050
* @return array
5151
*/
52-
public function getConfigurationForProperty($propertyName);
52+
public function getConfigurationForProperty(string $propertyName);
5353

5454
/**
55-
* Returns the source key (column name) for the given property name
55+
* Return the source key (column name) for the given property name, or NULL if it isn't defined
5656
*
5757
* @param string $propertyName
58-
* @return string
58+
* @return string|null
5959
*/
60-
public function getSourceKeyForProperty($propertyName);
60+
public function getSourceKeyForProperty($propertyName): ?string;
6161

6262
/**
63-
* Returns the property for the given source property (column)
63+
* Return the property for the given source property (column)
6464
*
65-
* @param $sourceKey
65+
* @param string $sourceKey
6666
* @return string
6767
*/
68-
public function getPropertyForSourceKey($sourceKey);
68+
public function getPropertyForSourceKey(string $sourceKey): ?string;
6969

7070
/**
71-
* Returns the data type for the given property name
71+
* Return the data type for the given property name
7272
*
7373
* @param string $propertyName
7474
* @return string Returns one of the following simple "string", "float", "int", "integer", "bool", "boolean" or one of the complex types
7575
*/
76-
public function getTypeForProperty($propertyName);
76+
public function getTypeForProperty(string $propertyName): ?string;
7777

7878
/**
79-
* Returns the source identifier (the database table name)
79+
* Return the source identifier (the database table name)
8080
*
8181
* @return string
8282
*/
83-
public function getSourceIdentifier();
83+
public function getSourceIdentifier(): ?string;
8484

8585
/**
86-
* Returns the name of the property which uniquely identifies an object
86+
* Return the name of the property which uniquely identifies an object
8787
*
8888
* @return string
8989
*/
90-
public function getIdentifier();
90+
public function getIdentifier(): ?string;
9191

9292
/**
9393
* Set whether unknown (un-configured) properties should be skipped during mapping, or throw an exception
9494
*
9595
* @param boolean $skipUnknownProperties
9696
* @return $this
9797
*/
98-
public function setSkipUnknownProperties($skipUnknownProperties);
98+
public function setSkipUnknownProperties(bool $skipUnknownProperties): self;
9999

100100
/**
101101
* Return whether unknown (un-configured) properties should be skipped during mapping, or throw an exception
102102
*
103103
* @return boolean
104104
*/
105-
public function shouldSkipUnknownProperties();
105+
public function shouldSkipUnknownProperties(): bool;
106106
}

Classes/VirtualObject/Persistence/Query.php

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Cundd\Rest\VirtualObject\Persistence;
55

6+
use Cundd\Rest\VirtualObject\ConfigurationInterface;
67
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement;
78

89
/**
@@ -48,47 +49,68 @@ class Query implements QueryInterface
4849
*/
4950
protected $statement;
5051

52+
/**
53+
* Query constructor
54+
*
55+
* @param array $constraint
56+
* @param array $orderings
57+
* @param int $limit
58+
* @param int $offset
59+
* @param string $sourceIdentifier
60+
* @param PersistenceManager $persistenceManager
61+
*/
62+
public function __construct(
63+
array $constraint = [],
64+
array $orderings = [],
65+
int $limit = 0,
66+
int $offset = 0,
67+
string $sourceIdentifier = null,
68+
PersistenceManager $persistenceManager = null
69+
) {
70+
$this->persistenceManager = $persistenceManager;
71+
$this->constraint = $constraint;
72+
$this->orderings = $orderings;
73+
$this->limit = $limit;
74+
$this->offset = $offset;
75+
$this->sourceIdentifier = $sourceIdentifier;
76+
}
77+
78+
5179
public function execute()
5280
{
5381
return $this->persistenceManager->getObjectDataByQuery($this);
5482
}
5583

56-
public function count()
84+
public function count(): int
5785
{
5886
return $this->persistenceManager->getObjectCountByQuery($this);
5987
}
6088

61-
public function getOrderings()
89+
public function getOrderings(): array
6290
{
6391
return $this->orderings;
6492
}
6593

66-
public function getLimit()
94+
public function getLimit(): int
6795
{
6896
return $this->limit;
6997
}
7098

71-
public function getOffset()
99+
public function getOffset(): int
72100
{
73101
return $this->offset;
74102
}
75103

76-
public function getConstraint()
104+
public function getConstraint(): array
77105
{
78106
return $this->constraint;
79107
}
80108

81-
public function getSourceIdentifier()
109+
public function getSourceIdentifier(): string
82110
{
83111
return $this->sourceIdentifier;
84112
}
85113

86-
/**
87-
* Return a copy of the Query with the given constraints
88-
*
89-
* @param array $constraint
90-
* @return QueryInterface
91-
*/
92114
public function withConstraints(array $constraint): QueryInterface
93115
{
94116
$clone = clone $this;
@@ -97,12 +119,6 @@ public function withConstraints(array $constraint): QueryInterface
97119
return $clone;
98120
}
99121

100-
/**
101-
* Return a copy of the Query with the given orderings
102-
*
103-
* @param array $orderings
104-
* @return QueryInterface
105-
*/
106122
public function withOrderings(array $orderings): QueryInterface
107123
{
108124
$clone = clone $this;
@@ -111,12 +127,6 @@ public function withOrderings(array $orderings): QueryInterface
111127
return $clone;
112128
}
113129

114-
/**
115-
* Return a copy of the Query with the given limit
116-
*
117-
* @param int $limit
118-
* @return QueryInterface
119-
*/
120130
public function withLimit(int $limit): QueryInterface
121131
{
122132
$clone = clone $this;
@@ -125,12 +135,6 @@ public function withLimit(int $limit): QueryInterface
125135
return $clone;
126136
}
127137

128-
/**
129-
* Return a copy of the Query with the given offset
130-
*
131-
* @param int $offset
132-
* @return QueryInterface
133-
*/
134138
public function withOffset(int $offset): QueryInterface
135139
{
136140
$clone = clone $this;
@@ -139,14 +143,14 @@ public function withOffset(int $offset): QueryInterface
139143
return $clone;
140144
}
141145

142-
public function setConfiguration($configuration)
146+
public function setConfiguration($configuration): QueryInterface
143147
{
144148
$this->persistenceManager->setConfiguration($configuration);
145149

146150
return $this;
147151
}
148152

149-
public function getConfiguration()
153+
public function getConfiguration(): ?ConfigurationInterface
150154
{
151155
return $this->persistenceManager->getConfiguration();
152156
}

0 commit comments

Comments
 (0)