Skip to content

Commit 1f6a30a

Browse files
committed
codestyle
1 parent 44b74cc commit 1f6a30a

File tree

4 files changed

+109
-108
lines changed

4 files changed

+109
-108
lines changed

Diff for: src/PTS/SymfonyDiLoader/CacheWatcher.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
class CacheWatcher
77
{
8-
/**
8+
/**
99
* @param string $fileCache
1010
* @param string[] $configs
1111
*
1212
* @return bool
1313
*/
14-
public function isActualCache(string $fileCache, array $configs): bool
14+
public function isActualCache(string $fileCache, array $configs): bool
1515
{
1616
$oldConfigs = $this->getMetaCache($fileCache . '.meta');
1717
if (\count($oldConfigs) !== \count($configs)) {
@@ -41,22 +41,22 @@ protected function getMetaCache(string $fileMeta): array
4141
return unserialize($configs);
4242
}
4343

44-
/**
45-
* @param string $fileCache
46-
* @param string[] $configs
47-
*
48-
* @return bool
49-
*/
50-
public function isExpired(string $fileCache, array $configs): bool
51-
{
52-
$cacheTime = filemtime($fileCache);
53-
54-
foreach ($configs as $config) {
55-
if ($cacheTime < filemtime($config)) {
56-
return true;
57-
}
58-
}
59-
60-
return false;
61-
}
44+
/**
45+
* @param string $fileCache
46+
* @param string[] $configs
47+
*
48+
* @return bool
49+
*/
50+
public function isExpired(string $fileCache, array $configs): bool
51+
{
52+
$cacheTime = filemtime($fileCache);
53+
54+
foreach ($configs as $config) {
55+
if ($cacheTime < filemtime($config)) {
56+
return true;
57+
}
58+
}
59+
60+
return false;
61+
}
6262
}

Diff for: src/PTS/SymfonyDiLoader/FactoryContainer.php

+38-38
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,44 @@
99

1010
class FactoryContainer
1111
{
12-
/** @var FileLocatorInterface */
13-
protected $locator;
14-
/** @var string */
15-
protected $classLoader;
16-
17-
public function __construct(string $classLoader, FileLocatorInterface $locator)
18-
{
19-
$this->classLoader = $classLoader;
20-
$this->locator = $locator;
21-
}
22-
23-
/**
24-
* @param string[] $configs
25-
*
26-
* @return ContainerBuilder
27-
* @throws \Exception
28-
*/
29-
public function create(array $configs): ContainerBuilder
30-
{
31-
$builder = $this->createBuilder();
32-
$loader = $this->createLoader($builder, $this->locator);
33-
34-
foreach ($configs as $config) {
35-
$loader->load($config);
36-
}
12+
/** @var FileLocatorInterface */
13+
protected $locator;
14+
/** @var string */
15+
protected $classLoader;
16+
17+
public function __construct(string $classLoader, FileLocatorInterface $locator)
18+
{
19+
$this->classLoader = $classLoader;
20+
$this->locator = $locator;
21+
}
22+
23+
/**
24+
* @param string[] $configs
25+
*
26+
* @return ContainerBuilder
27+
* @throws \Exception
28+
*/
29+
public function create(array $configs): ContainerBuilder
30+
{
31+
$builder = $this->createBuilder();
32+
$loader = $this->createLoader($builder, $this->locator);
33+
34+
foreach ($configs as $config) {
35+
$loader->load($config);
36+
}
3737

3838
$builder->compile(true);
39-
return $builder;
40-
}
41-
42-
protected function createBuilder(): ContainerBuilder
43-
{
44-
return new ContainerBuilder;
45-
}
46-
47-
protected function createLoader(ContainerBuilder $builder, FileLocatorInterface $locator): LoaderInterface
48-
{
49-
$class = $this->classLoader;
50-
return new $class($builder, $locator);
51-
}
39+
return $builder;
40+
}
41+
42+
protected function createBuilder(): ContainerBuilder
43+
{
44+
return new ContainerBuilder;
45+
}
46+
47+
protected function createLoader(ContainerBuilder $builder, FileLocatorInterface $locator): LoaderInterface
48+
{
49+
$class = $this->classLoader;
50+
return new $class($builder, $locator);
51+
}
5252
}

Diff for: src/PTS/SymfonyDiLoader/LoaderContainer.php

+50-49
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,27 @@ public function __construct(array $configFiles, string $cacheFile, FactoryContai
4343
$this->cacheWatcher = new CacheWatcher;
4444
}
4545

46-
public function setCheckExpired(bool $checkExpired = true): self
47-
{
48-
$this->checkExpired = $checkExpired;
49-
return $this;
50-
}
51-
52-
/**
53-
* @return ContainerInterface
54-
* @throws \Exception
55-
*/
56-
public function getContainer(): ContainerInterface
57-
{
58-
if ($this->container === null) {
59-
$container = $this->tryGetContainerFromCache($this->cacheFile, $this->configFiles);
60-
$container = $container ?? $this->createContainer($this->configFiles, $this->cacheFile, $this->classContainer);
46+
public function setCheckExpired(bool $checkExpired = true): self
47+
{
48+
$this->checkExpired = $checkExpired;
49+
return $this;
50+
}
51+
52+
/**
53+
* @return ContainerInterface
54+
* @throws \Exception
55+
*/
56+
public function getContainer(): ContainerInterface
57+
{
58+
if ($this->container === null) {
59+
$container = $this->tryGetContainerFromCache($this->cacheFile, $this->configFiles);
60+
$container =
61+
$container ?? $this->createContainer($this->configFiles, $this->cacheFile, $this->classContainer);
6162
$this->container = $container;
62-
}
63+
}
6364

64-
return $this->container;
65-
}
65+
return $this->container;
66+
}
6667

6768
/**
6869
* @param string[] $configs
@@ -72,20 +73,20 @@ public function getContainer(): ContainerInterface
7273
* @return ContainerInterface
7374
* @throws \Exception
7475
*/
75-
protected function createContainer(array $configs, string $cacheFile, string $class): ContainerInterface
76-
{
76+
protected function createContainer(array $configs, string $cacheFile, string $class): ContainerInterface
77+
{
7778
$appContainer = $this->factory->create($configs);
7879
$this->dump($cacheFile, $class, $appContainer);
7980
$this->dumpMeta($cacheFile . '.meta', $configs);
8081

81-
return $appContainer;
82-
}
82+
return $appContainer;
83+
}
8384

8485
/**
8586
* @param string $filePath
8687
* @param string[] $configFiles
8788
*/
88-
protected function dumpMeta(string $filePath, array $configFiles): void
89+
protected function dumpMeta(string $filePath, array $configFiles): void
8990
{
9091
try {
9192
file_put_contents($filePath, serialize($configFiles));
@@ -94,45 +95,45 @@ protected function dumpMeta(string $filePath, array $configFiles): void
9495
}
9596
}
9697

97-
/**
98-
* @param string $filePath
99-
* @param string $className
100-
* @param ContainerBuilder $container
101-
*
102-
* @throws EnvParameterException
103-
*/
104-
protected function dump(string $filePath, string $className, ContainerBuilder $container): void
105-
{
106-
$dumper = new PhpDumper($container);
107-
108-
try {
98+
/**
99+
* @param string $filePath
100+
* @param string $className
101+
* @param ContainerBuilder $container
102+
*
103+
* @throws EnvParameterException
104+
*/
105+
protected function dump(string $filePath, string $className, ContainerBuilder $container): void
106+
{
107+
$dumper = new PhpDumper($container);
108+
109+
try {
109110
file_put_contents($filePath, $dumper->dump([
110111
'class' => $className,
111112
]));
112113
} catch (\Throwable $throwable) {
113114
throw new \RuntimeException('Can`t dump cache for DI container', 0, $throwable);
114115
}
115-
}
116+
}
116117

117118
/**
118119
* @param string $fileCache
119120
* @param string[] $configs
120121
*
121122
* @return null|ContainerInterface
122123
*/
123-
protected function tryGetContainerFromCache(string $fileCache, array $configs): ?ContainerInterface
124-
{
125-
if (!file_exists($fileCache)) {
126-
return null;
127-
}
128-
129-
if ($this->checkExpired && !$this->getWatcher()->isActualCache($fileCache, $configs)) {
130-
return null;
131-
}
132-
133-
require_once $fileCache;
134-
return new $this->classContainer;
135-
}
124+
protected function tryGetContainerFromCache(string $fileCache, array $configs): ?ContainerInterface
125+
{
126+
if (!file_exists($fileCache)) {
127+
return null;
128+
}
129+
130+
if ($this->checkExpired && !$this->getWatcher()->isActualCache($fileCache, $configs)) {
131+
return null;
132+
}
133+
134+
require_once $fileCache;
135+
return new $this->classContainer;
136+
}
136137

137138
protected function getWatcher(): CacheWatcher
138139
{

Diff for: src/PTS/SymfonyDiLoader/LoaderContainerInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
interface LoaderContainerInterface
99
{
10-
public function getContainer(): ContainerInterface;
10+
public function getContainer(): ContainerInterface;
1111
}

0 commit comments

Comments
 (0)