Skip to content

Commit

Permalink
cs:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
overclokk committed Jul 26, 2024
1 parent b54cddd commit d49bd70
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/AurynConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class AurynConfig implements AurynConfigInterface
private array $extensions = [];

private ProxyFactoryInterface $proxy_factory;

/**
* @var array<array-key, class-string>
*/
private array $extensionsClasses = [];

/**
Expand Down Expand Up @@ -73,6 +77,7 @@ public function resolve(): void
}

foreach ($this->extensionsClasses as $extensionClass) {
/** @var Extension $extension */
$extension = $this->injector->share($extensionClass)->make($extensionClass);
$extension->execute($this);
}
Expand All @@ -82,6 +87,9 @@ public function resolve(): void
}
}

/**
* @param class-string $className
*/
public function extendFromClassName(string $className): void
{
$this->extensionsClasses[] = $className;
Expand Down
18 changes: 13 additions & 5 deletions src/ProvidersCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
use Brick\VarExporter\ExportException;
use Brick\VarExporter\VarExporter;
use ItalyStrap\Config\ConfigInterface;
use phpDocumentor\Reflection\Types\Self_;
use Safe\DateTimeImmutable;
use Webimpress\SafeWriter\Exception\ExceptionInterface as FileWriterException;
use Webimpress\SafeWriter\FileWriter;

/**
* @psalm-api
*/
class ProvidersCache implements ProvidersCacheInterface
{
private const CACHE_TEMPLATE = <<<'EOT'
Expand All @@ -35,31 +39,35 @@ public function read(
ConfigInterface $config
): bool {

$cachedConfigFile = (string)$config->get(static::CACHE_PATH, $this->file);
$cachedConfigFile = (string)$config->get(self::CACHE_PATH, $this->file);

if (
!$cachedConfigFile
$cachedConfigFile === ''
|| !file_exists($cachedConfigFile)
|| !is_readable($cachedConfigFile)
) {
return false;
}

/**
* @psalm-suppress UnresolvableInclude
*/
$config->merge((array)require $cachedConfigFile);
return true;
}

public function write(
ConfigInterface $config
): void {
$cachedConfigFile = (string)$config->get(static::CACHE_PATH, $this->file);
$cachedConfigFile = (string)$config->get(self::CACHE_PATH, $this->file);

if (!$cachedConfigFile) {
if ($cachedConfigFile === '') {
return;
}

try {
$contents = sprintf(
static::CACHE_TEMPLATE,
self::CACHE_TEMPLATE,
static::class,
// Write an alternative to date('c')
(new DateTimeImmutable('now'))->format('c'),
Expand Down
7 changes: 3 additions & 4 deletions src/ProvidersCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ProvidersCollection
{
private ConfigInterface $config;
private Injector $injector;
private ProvidersCacheInterface $cache;
private ProvidersCache $cache;
/**
* @var array|callable[]|iterable|string[]
*/
Expand All @@ -28,14 +28,13 @@ class ProvidersCollection
* @param Injector $injector
* @param ConfigInterface $config
* @param iterable<class-string|callable> $providers
* @param ProvidersCacheInterface|null $cache
* @throws \ErrorException
* @param ProvidersCache|null $cache
*/
public function __construct(
Injector $injector,
ConfigInterface $config,
iterable $providers = [],
ProvidersCacheInterface $cache = null
ProvidersCache $cache = null
) {
$this->injector = $injector;
$this->config = $config;
Expand Down

0 comments on commit d49bd70

Please sign in to comment.