Skip to content

Commit

Permalink
Merge 0ab25e0 into f28c621
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Apr 8, 2022
2 parents f28c621 + 0ab25e0 commit c1af67d
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bc_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: '8.0'
- name: Install Checker
run: composer require --dev roave/backward-compatibility-check
- name: Check for BC breaks
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Dependencies
Expand All @@ -25,12 +25,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
symfonyVersion: [ ^4.4, ^5.0 ]
symfonyVersion: [^6.0]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Dependencies
Expand All @@ -44,12 +44,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
symfonyVersion: [^4.4, ^5.0]
symfonyVersion: [^6.0]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Dependencies
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Dependencies
Expand Down
6 changes: 3 additions & 3 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return PhpCsFixer\Config::create()
return (new \PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
Expand All @@ -10,7 +10,7 @@
],
'cast_spaces' => true,
'class_attributes_separation' => [
'elements' => ['method', 'property'],
'elements' => ['method' => 'one', 'property' => 'one'],
],
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
Expand Down Expand Up @@ -70,7 +70,7 @@
'single_quote' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => ['property', 'method', 'const'],
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"minimum-stability": "stable",
"license": "MIT",
"require": {
"symfony/framework-bundle": "^4.4 | ^5.0",
"symfony/framework-bundle": "^6.0",
"rikudou/psr6-dynamo-db": "^2.0",
"php": "^7.2 | ^8.0",
"symfony/cache": "^4.4 | ^5.0",
"php": "^8.0",
"symfony/cache": "^6.0",
"ext-json": "*"
},
"autoload": {
Expand All @@ -17,9 +17,9 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.44",
"phpunit/phpunit": "^9.3"
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"psr-4": {
Expand Down
7 changes: 3 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
excludes_analyse:
- src/DependencyInjection/Configuration.php
ignoreErrors:
- '#Return type .*? of method .*?DynamoDbCacheAdapter::getItems.*? should be compatible .*#'
excludePaths:
analyse:
- src/DependencyInjection/Configuration.php
36 changes: 13 additions & 23 deletions src/Cache/DynamoDbCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@ final class DynamoDbCacheAdapter implements AdapterInterface, CacheInterface
{
use CacheTrait;

/**
* @var DynamoDbCache
*/
private $cache;

/**
* @var SymfonyCacheItemConverter
*/
private $converter;

/**
* @param DynamoDbCache $cache
* @param SymfonyCacheItemConverter $converter
*/
public function __construct(DynamoDbCache $cache, SymfonyCacheItemConverter $converter)
{
$this->cache = $cache;
$this->converter = $converter;
public function __construct(
private DynamoDbCache $cache,
private SymfonyCacheItemConverter $converter
) {
}

/**
Expand All @@ -43,7 +33,7 @@ public function __construct(DynamoDbCache $cache, SymfonyCacheItemConverter $con
*
* @return CacheItem
*/
public function getItem($key)
public function getItem(mixed $key): CacheItem
{
return $this->converter->convertToCacheItem($this->cache->getItem($key));
}
Expand All @@ -55,7 +45,7 @@ public function getItem($key)
*
* @return CacheItem[]
*/
public function getItems(array $keys = [])
public function getItems(array $keys = []): iterable
{
return array_map(function (DynamoCacheItem $item) {
return $this->converter->convertToCacheItem($item);
Expand All @@ -67,7 +57,7 @@ public function getItems(array $keys = [])
*
* @return bool
*/
public function clear(string $prefix = '')
public function clear(string $prefix = ''): bool
{
return $this->cache->clear();
}
Expand All @@ -79,7 +69,7 @@ public function clear(string $prefix = '')
*
* @return bool
*/
public function hasItem($key)
public function hasItem(string $key): bool
{
return $this->cache->hasItem($key);
}
Expand All @@ -91,7 +81,7 @@ public function hasItem($key)
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(string $key): bool
{
return $this->cache->deleteItem($key);
}
Expand All @@ -103,7 +93,7 @@ public function deleteItem($key)
*
* @return bool
*/
public function deleteItems(array $keys)
public function deleteItems(array $keys): bool
{
return $this->cache->deleteItems($keys);
}
Expand All @@ -115,7 +105,7 @@ public function deleteItems(array $keys)
*
* @return bool
*/
public function save(CacheItemInterface $item)
public function save(CacheItemInterface $item): bool
{
return $this->cache->save($item);
}
Expand All @@ -127,7 +117,7 @@ public function save(CacheItemInterface $item)
*
* @return bool
*/
public function saveDeferred(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item): bool
{
return $this->cache->saveDeferred($item);
}
Expand All @@ -137,7 +127,7 @@ public function saveDeferred(CacheItemInterface $item)
*
* @return bool
*/
public function commit()
public function commit(): bool
{
return $this->cache->commit();
}
Expand Down
22 changes: 7 additions & 15 deletions src/Converter/SymfonyCacheItemConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@

final class SymfonyCacheItemConverter implements CacheItemConverterInterface
{
/**
* @var ClockInterface
*/
private $clock;

/**
* @var CacheItemEncoderInterface
*/
private $encoder;

public function __construct(ClockInterface $clock, CacheItemEncoderInterface $encoder)
{
$this->clock = $clock;
$this->encoder = $encoder;
public function __construct(
private ClockInterface $clock,
private CacheItemEncoderInterface $encoder,
) {
}

public function supports(CacheItemInterface $cacheItem): bool
Expand All @@ -43,6 +33,8 @@ public function convert(CacheItemInterface $cacheItem): DynamoCacheItem
$reflectionExpiry = new ReflectionProperty(CacheItem::class, 'expiry');
$reflectionExpiry->setAccessible(true);
$value = $reflectionExpiry->getValue($cacheItem);
assert(is_scalar($value) || $value === null);

if ($value === null) {
$expiry = null;
} else {
Expand Down Expand Up @@ -85,7 +77,7 @@ public function convertToCacheItem(DynamoCacheItem $dynamoCacheItem): CacheItem
$valueReflection->setValue($item, $dynamoCacheItem->get());
$expiryReflection->setValue(
$item,
$expiry ? $expiry->getTimestamp() : null
$expiry?->getTimestamp()
);

return $item;
Expand Down
15 changes: 15 additions & 0 deletions src/DependencyInjection/RikudouDynamoDbCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ private function createDynamoClient(ContainerBuilder $container, array $configs)
{
if ($configs['client_service']) {
$client = $configs['client_service'];
assert(is_string($client));
} else {
assert(is_array($configs['client_config']));

$service = new Definition(DynamoDbClient::class);
$service->addArgument([
'region' => $configs['client_config']['region'],
Expand Down Expand Up @@ -77,6 +80,8 @@ private function createCacheClient(ContainerBuilder $container, array $configs,
*/
private function createDefaultEncoder(ContainerBuilder $container, array $configs): void
{
assert(is_array($configs['encoder']));

$container->removeDefinition('rikudou.dynamo_cache.encoder.default');
$container->setAlias('rikudou.dynamo_cache.encoder.default', $configs['encoder']['service']);
}
Expand All @@ -87,11 +92,19 @@ private function createDefaultEncoder(ContainerBuilder $container, array $config
*/
private function createParameters(ContainerBuilder $container, array $configs): void
{
assert(
is_array($configs['replace_default_adapter'])
|| is_scalar($configs['replace_default_adapter'])
|| $configs['replace_default_adapter'] === null
);

$container->setParameter(
'rikudou.dynamo_cache.internal.replace_adapter',
$configs['replace_default_adapter']
);

assert(is_array($configs['encoder']));

$container->setParameter(
'rikudou.dynamo_cache.json_encoder.encode_flags',
$configs['encoder']['json_options']['encode_flags']
Expand All @@ -112,6 +125,8 @@ private function createParameters(ContainerBuilder $container, array $configs):
*/
private function createSessionHandler(ContainerBuilder $container, array $configs): void
{
assert(is_array($configs['session']));

$definition = $container->getDefinition('rikudou.dynamo_cache.session');
$definition->setArgument('$ttl', $configs['session']['ttl']);
$definition->setArgument('$prefix', $configs['session']['prefix']);
Expand Down

0 comments on commit c1af67d

Please sign in to comment.