Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit adcf5fe

Browse files
committed
Enable strict coding style with complete type hints and phpdoc
1 parent c0f6320 commit adcf5fe

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

.phpcs.xml.dist

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
5+
<file>src</file>
6+
<file>tests</file>
7+
8+
<rule ref="HardMode"/>
9+
</ruleset>

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/property-info": "^4.2"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^8.0"
23+
"phpunit/phpunit": "^8.0",
24+
"mnapoli/hard-mode": "^0.1.1"
2425
}
2526
}

src/Dynamap.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(DynamoDbClient $dynamoDb, array $mapping)
1818
$this->mappingObj = new Mapping($mapping);
1919
}
2020

21-
public static function fromOptions(array $options, array $mapping)
21+
public static function fromOptions(array $options, array $mapping): self
2222
{
2323
$options['version'] = $options['version'] ?? 'latest';
2424

@@ -36,8 +36,11 @@ public function getAll(string $table): array
3636

3737
/**
3838
* Get item by primary key.
39+
*
40+
* @param int|string|array $key
41+
* @throws \Exception
3942
*/
40-
public function get(string $table, $key)
43+
public function get(string $table, $key): object
4144
{
4245
$tableMapping = $this->mappingObj->getTableMapping($table);
4346

@@ -81,6 +84,16 @@ public function save(object $object): void
8184
]);
8285
}
8386

87+
/**
88+
* Update only specific fields for an item.
89+
*
90+
* Warning: if the item has been loaded as a PHP object, the PHP object will not be updated.
91+
* If you want it to be updated you will need to reload it from database.
92+
*
93+
* @param int|string|array $itemKey
94+
* @param array $values Key-value map
95+
* @throws \Exception
96+
*/
8497
public function partialUpdate(string $table, $itemKey, array $values): void
8598
{
8699
$tableMapping = $this->mappingObj->getTableMapping($table);
@@ -120,7 +133,7 @@ private function map(array $item, string $table): object
120133
$object = $class->newInstanceWithoutConstructor();
121134

122135
foreach ($item as $fieldName => $fieldData) {
123-
if (!$tableMapping->hasFieldOrKey($fieldName)) {
136+
if (! $tableMapping->hasFieldOrKey($fieldName)) {
124137
continue;
125138
}
126139
$fieldMapping = $tableMapping->getFieldMapping($fieldName);
@@ -133,6 +146,10 @@ private function map(array $item, string $table): object
133146
return $object;
134147
}
135148

149+
/**
150+
* @param int|string|array $key
151+
* @throws \Exception
152+
*/
136153
private function buildKeyQuery($key, TableMapping $tableMapping): array
137154
{
138155
$keyQuery = [];

src/FieldMapping.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ public function name(): string
3636
return $this->name;
3737
}
3838

39+
/**
40+
* @return mixed
41+
*/
3942
public function readFieldValue(array $item, string $fieldName)
4043
{
4144
$rawDynamoDbValue = $item[$fieldName][$this->dynamoDbType()];
4245

4346
return $this->castValueFromDynamoDbFormat($rawDynamoDbValue);
4447
}
4548

49+
/**
50+
* @param mixed $fieldValue
51+
*/
4652
public function dynamoDbQueryValue($fieldValue): array
4753
{
4854
return [
49-
$this->dynamoDbType() => $this->castValueForDynamoDbFormat($fieldValue)
55+
$this->dynamoDbType() => $this->castValueForDynamoDbFormat($fieldValue),
5056
];
5157
}
5258

@@ -55,6 +61,10 @@ public function dynamoDbType(): string
5561
return $this->dynamoDbType;
5662
}
5763

64+
/**
65+
* @param mixed $value
66+
* @return mixed
67+
*/
5868
private function castValueForDynamoDbFormat($value)
5969
{
6070
switch ($this->dynamoDbType()) {
@@ -70,6 +80,10 @@ private function castValueForDynamoDbFormat($value)
7080
}
7181
}
7282

83+
/**
84+
* @param mixed $value
85+
* @return mixed
86+
*/
7387
private function castValueFromDynamoDbFormat($value)
7488
{
7589
switch ($this->dynamoDbType()) {

src/Mapping.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Mapping
1313

1414
public function __construct(array $mappingConfig)
1515
{
16-
$phpDocExtractor = new PhpDocExtractor();
17-
$reflectionExtractor = new ReflectionExtractor();
16+
$phpDocExtractor = new PhpDocExtractor;
17+
$reflectionExtractor = new ReflectionExtractor;
1818
$listExtractors = [$reflectionExtractor];
1919
$typeExtractors = [$phpDocExtractor, $reflectionExtractor];
2020
$descriptionExtractors = [$phpDocExtractor];

0 commit comments

Comments
 (0)