Skip to content

Commit f111e49

Browse files
committed
property type for php 7.4
1 parent dea780c commit f111e49

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

src/PTS/SymfonyDiLoader/CacheWatcher.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace PTS\SymfonyDiLoader;
55

6+
use RuntimeException;
7+
use function count;
8+
69
class CacheWatcher
710
{
811
/**
@@ -14,16 +17,15 @@ class CacheWatcher
1417
public function isActualCache(string $fileCache, array $configs): bool
1518
{
1619
$oldConfigs = $this->getMetaCache($fileCache . '.meta');
17-
if (\count($oldConfigs) !== \count($configs)) {
18-
return false;
19-
}
20+
$configs = array_unique($configs);
2021

21-
$diff = array_diff($oldConfigs, $configs);
22-
if (\count($diff)) {
22+
if (count($oldConfigs) !== count($configs)) {
2323
return false;
2424
}
2525

26-
return !$this->isExpired($fileCache, $configs);
26+
return array_diff($oldConfigs, $configs)
27+
? false
28+
: !$this->isExpired($fileCache, $configs);
2729
}
2830

2931
/**
@@ -34,7 +36,7 @@ public function isActualCache(string $fileCache, array $configs): bool
3436
protected function getMetaCache(string $fileMeta): array
3537
{
3638
if (!file_exists($fileMeta)) {
37-
throw new \RuntimeException('Can`t read meta for DI container');
39+
throw new RuntimeException('Can`t read meta for DI container');
3840
}
3941

4042
$configs = file_get_contents($fileMeta);

src/PTS/SymfonyDiLoader/FactoryContainer.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33

44
namespace PTS\SymfonyDiLoader;
55

6+
use Exception;
67
use Symfony\Component\Config\FileLocatorInterface;
78
use Symfony\Component\Config\Loader\LoaderInterface;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1011

1112
class FactoryContainer
1213
{
13-
/** @var FileLocatorInterface */
14-
protected $locator;
15-
/** @var string */
16-
protected $classLoader;
14+
protected FileLocatorInterface $locator;
15+
protected string $classLoader;
1716

1817
public function __construct(string $classLoader, FileLocatorInterface $locator)
1918
{
@@ -26,7 +25,7 @@ public function __construct(string $classLoader, FileLocatorInterface $locator)
2625
* @param ExtensionInterface[] $extensions
2726
*
2827
* @return ContainerBuilder
29-
* @throws \Exception
28+
* @throws Exception
3029
*/
3130
public function create(array $configs, array $extensions = []): ContainerBuilder
3231
{
@@ -49,7 +48,7 @@ protected function createBuilder(): ContainerBuilder
4948

5049
protected function registerExtensions(ContainerBuilder $builder, array $extensions = []): void
5150
{
52-
array_map(function(ExtensionInterface $extension) use ($builder) {
51+
array_map(static function(ExtensionInterface $extension) use ($builder) {
5352
$builder->registerExtension($extension);
5453
}, $extensions);
5554
}

src/PTS/SymfonyDiLoader/LoaderContainer.php

+16-32
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,30 @@
33

44
namespace PTS\SymfonyDiLoader;
55

6+
use RuntimeException;
67
use Symfony\Component\Config\FileLocator;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
10-
use Symfony\Component\DependencyInjection\Exception\EnvParameterException;
1111
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1212
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
13+
use Throwable;
1314

1415
class LoaderContainer implements LoaderContainerInterface
1516
{
16-
/** @var array */
17-
protected $configFiles = [];
18-
19-
/** @var FactoryContainer */
20-
protected $factory;
21-
/** @var ContainerInterface */
22-
protected $container;
23-
/** @var CacheWatcher */
24-
protected $cacheWatcher;
17+
/** @var string[] */
18+
protected array $configFiles = [];
19+
20+
protected FactoryContainer $factory;
21+
protected ?ContainerInterface $container = null;
22+
protected CacheWatcher $cacheWatcher;
2523
/** @var ExtensionInterface[] */
26-
protected $extensions = [];
24+
protected array $extensions = [];
2725

28-
/** @var string */
29-
protected $cacheFile = '';
30-
/** @var bool */
31-
protected $checkExpired = true;
26+
protected string $cacheFile = '';
27+
protected bool $checkExpired = true;
3228

33-
/** @var string */
34-
protected $classContainer = 'AppContainer';
29+
protected string $classContainer = 'AppContainer';
3530

3631
/**
3732
* @param string[] $configFiles
@@ -58,10 +53,6 @@ public function setCheckExpired(bool $checkExpired = true): self
5853
return $this;
5954
}
6055

61-
/**
62-
* @return ContainerInterface
63-
* @throws \Exception
64-
*/
6556
public function getContainer(): ContainerInterface
6657
{
6758
if ($this->container === null) {
@@ -94,18 +85,11 @@ protected function dumpMeta(string $filePath, array $configFiles): void
9485
{
9586
try {
9687
file_put_contents($filePath, serialize($configFiles));
97-
} catch (\Throwable $throwable) {
98-
throw new \RuntimeException('Can`t dump meta for DI container', 0, $throwable);
88+
} catch (Throwable $throwable) {
89+
throw new RuntimeException('Can`t dump meta for DI container', 0, $throwable);
9990
}
10091
}
10192

102-
/**
103-
* @param string $filePath
104-
* @param string $className
105-
* @param ContainerBuilder $container
106-
*
107-
* @throws EnvParameterException
108-
*/
10993
protected function dump(string $filePath, string $className, ContainerBuilder $container): void
11094
{
11195
$dumper = new PhpDumper($container);
@@ -114,8 +98,8 @@ protected function dump(string $filePath, string $className, ContainerBuilder $c
11498
file_put_contents($filePath, $dumper->dump([
11599
'class' => $className,
116100
]));
117-
} catch (\Throwable $throwable) {
118-
throw new \RuntimeException('Can`t dump cache for DI container', 0, $throwable);
101+
} catch (Throwable $throwable) {
102+
throw new RuntimeException('Can`t dump cache for DI container', 0, $throwable);
119103
}
120104
}
121105

0 commit comments

Comments
 (0)