Skip to content

Commit

Permalink
Add purity markers
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed May 31, 2021
1 parent da1bde5 commit 8ac5da7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"phpunit/phpunit": "^8.5 || ^9.2",
"scrutinizer/ocular": "^1.5",
"unleashedtech/php-coding-standard": "^3.0",
"vimeo/psalm": "^4.4.1"
"vimeo/psalm": "^4.7.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
45 changes: 40 additions & 5 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ final class Configuration implements ConfigurationBuilderInterface, Configuratio
*/
private $userConfig;

/** @var array<string, Schema> */
/**
* @var array<string, Schema>
*
* @psalm-allow-private-mutation
*/
private $configSchemas = [];

/** @var Data|null */
/**
* @var Data|null
*
* @psalm-allow-private-mutation
*/
private $finalConfig;

/** @var array<string, mixed> */
/**
* @var array<string, mixed>
*
* @psalm-allow-private-mutation
*/
private $cache = [];

/**
Expand All @@ -61,6 +73,8 @@ public function __construct(array $baseSchemas = [])

/**
* Registers a new configuration schema at the given top-level key
*
* @psalm-allow-private-mutation
*/
public function addSchema(string $key, Schema $schema): void
{
Expand All @@ -71,6 +85,8 @@ public function addSchema(string $key, Schema $schema): void

/**
* {@inheritdoc}
*
* @psalm-allow-private-mutation
*/
public function merge(array $config = []): void
{
Expand All @@ -81,6 +97,8 @@ public function merge(array $config = []): void

/**
* {@inheritdoc}
*
* @psalm-allow-private-mutation
*/
public function set(string $key, $value): void
{
Expand All @@ -91,6 +109,8 @@ public function set(string $key, $value): void

/**
* {@inheritDoc}
*
* @psalm-allow-private-mutation
*/
public function get(string $key)
{
Expand All @@ -107,6 +127,11 @@ public function get(string $key)
}
}

/**
* {@inheritDoc}
*
* @psalm-allow-private-mutation
*/
public function exists(string $key): bool
{
if ($this->finalConfig === null) {
Expand All @@ -118,11 +143,17 @@ public function exists(string $key): bool
return $this->finalConfig->has($key);
}

/**
* @psalm-mutation-free
*/
public function reader(): ConfigurationInterface
{
return $this->reader;
}

/**
* @psalm-allow-private-mutation
*/
private function invalidate(): void
{
$this->cache = [];
Expand All @@ -131,6 +162,8 @@ private function invalidate(): void

/**
* Applies the schema against the configuration to return the final configuration
*
* @psalm-allow-private-mutation
*/
private function build(): Data
{
Expand All @@ -153,6 +186,8 @@ private function build(): Data
* @param mixed $data
*
* @return mixed
*
* @psalm-pure
*/
private static function convertStdClassesToArrays($data)
{
Expand All @@ -161,8 +196,8 @@ private static function convertStdClassesToArrays($data)
}

if (\is_array($data)) {
foreach ($data as &$v) {
$v = self::convertStdClassesToArrays($v);
foreach ($data as $k => $v) {
$data[$k] = self::convertStdClassesToArrays($v);
}
}

Expand Down

0 comments on commit 8ac5da7

Please sign in to comment.