Skip to content

Commit

Permalink
fix(global): Psalm fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deluxetom committed Jan 9, 2024
1 parent d934f5b commit e06a27e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "Monorepo for Secretary's PHP implementation",
"type": "library",
"require-dev": {
"aws/aws-sdk-php": "^3.91",
"php": "^8.0",
"ext-json": "*",
"aws/aws-sdk-php": "^3.91",
"guzzlehttp/guzzle": "^7.0",
"mockery/mockery": "^1.4",
"php": "^8.0",
"phpunit/phpunit": "^9.0 || ^10.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"symfony/config": "^5.3 || ^6.0 || ^7.0",
Expand Down Expand Up @@ -36,6 +36,12 @@
"**/Tests/"
]
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"scripts": {
"ecs": "ecs check",
"ecs:fix": "ecs check --fix",
Expand Down
47 changes: 28 additions & 19 deletions src/Bundle/SecretaryBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Class Configuration.
*
* @package Secretary\Bundle\SecretaryBundle\DependencyInjection
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('secretary');
$rootNode = $treeBuilder->getRootNode();
$treeBuilder = new TreeBuilder('secretary', 'array');

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand All @@ -34,30 +34,39 @@ public function getConfigTreeBuilder(): TreeBuilder
return $treeBuilder;
}

/**
* @psalm-suppress UndefinedInterfaceMethod
*/
private function addAdaptersSection(): ArrayNodeDefinition
{
$treeBuilder = new TreeBuilder('adapters');
$node = $treeBuilder->getRootNode();

/** @var ArrayNodeDefinition $node */
$node = $treeBuilder->getRootNode();

$node
->useAttributeAsKey('name')
->arrayPrototype()
->addDefaultsIfNotSet()
->children()
->scalarNode('adapter')
->isRequired()
->info('Class name, or service ID of adapter')
->end()
->arrayNode('config')->ignoreExtraKeys(false)->end()
->arrayNode('cache')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
->enumNode('type')->values(['psr6', 'psr16'])->end()
->scalarNode('service_id')->end()
->end()
->end()
->end()
->scalarNode('adapter')
->isRequired()
->info('Class name, or service ID of adapter')
->end()
->arrayNode('config')
->ignoreExtraKeys(false)
->end()
->arrayNode('cache')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
->enumNode('type')
->values(['psr6', 'psr16'])
->end()
->scalarNode('service_id')->end()
->end()
->end()
->end()
->end();

return $node;
Expand Down
12 changes: 2 additions & 10 deletions src/Core/Helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,18 @@ public static function without(array $array, ...$keys): array
}

/**
* @psalm-suppress InvalidArrayOffset
*
* @param string ...$keys
*/
public static function remove(array &$array, ...$keys): array
{
$newArray = [];
foreach (array_keys($newArray) as $key) {
if (!in_array($key, $keys)) {
foreach (array_keys($array) as $key) {
if (in_array($key, $keys)) {
$newArray[$key] = $array[$key];
unset($array[$key]);
}
}

foreach ($keys as $key) {
if (!array_key_exists($key, $newArray)) {
$newArray[$key] = null;
}
}

return $newArray;
}
}
14 changes: 4 additions & 10 deletions src/Core/Secret.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@
use Secretary\Exception\ValueNotSupportedException;

/**
* @package Secretary
* @implements \ArrayAccess<string, mixed>
*/
class Secret implements \ArrayAccess
{
private string $key;

/**
* @var array|string
*/
private $value;
private array|string $value;

private ?array $metadata = null;
private ?array $metadata;

/**
* @param array|string $value
*/
public function __construct(string $key, $value, ?array $metadata = null)
public function __construct(string $key, array|string $value, ?array $metadata = null)
{
$this->key = $key;
$this->value = $value;
Expand Down

0 comments on commit e06a27e

Please sign in to comment.