8000 Extracted `if` block content · symfony/symfony@a202182 · GitHub
[go: up one dir, main page]

Skip to content

Commit a202182

Browse files
committed
Extracted if block content
1 parent b5693be commit a202182

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,19 @@ public function setKernel(KernelInterface $kernel = null)
5959
*/
6060
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
6161
{
62+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
63+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
64+
6265
$this->data = [
6366
'app_name' => $this->name,
6467
'app_version' => $this->version,
6568
'token' => $response->headers->get('X-Debug-Token'),
6669
'symfony_version' => Kernel::VERSION,
67-
'symfony_state' => 'unknown',
70+
'symfony_minor_version' => sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION),
71+
'symfony_lts' => 4 === Kernel::MINOR_VERSION,
72+
'symfony_state' => $this->determineSymfonyState(),
73+
'symfony_eom' => $eom->format('F Y'),
74+
'symfony_eol' => $eol->format('F Y'),
6875
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
6976
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
7077
'php_version' => \PHP_VERSION,
@@ -82,14 +89,6 @@ public function collect(Request $request, Response $response/*, \Throwable $exce
8289
foreach ($this->kernel->getBundles() as $name => $bundle) {
8390
$this->data['bundles'][$name] = new ClassStub(\get_class($bundle));
8491
}
85-
86-
$this->data['symfony_state'] = $this->determineSymfonyState();
87-
$this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
88-
$this->data['symfony_lts'] = 4 === Kernel::MINOR_VERSION;
89-
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
90-
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
91-
$this->data['symfony_eom'] = $eom->format('F Y');
92-
$this->data['symfony_eol'] = $eol->format('F Y');
9392
}
9493

9594
if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
@@ -175,9 +174,9 @@ public function getSymfonyMinorVersion()
175174
/**
176175
* Returns if the current Symfony version is a Long-Term Support one.
177176
*/
178-
public function isSymfonyLts(): ?bool
177+
public function isSymfonyLts(): bool
179178
{
180-
return $this->data['symfony_lts'] ?? null;
179+
return $this->data['symfony_lts'];
181180
}
182181

183182
/**

src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php

Lines changed: 34 additions & 1 deletion
8000
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function testCollect()
4141
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
4242
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
4343
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
44+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
45+
$this->assertSame($this->determineSymfonyState(), $c->getSymfonyState());
46+
47+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
48+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
49+
$this->assertSame($eom, $c->getSymfonyEom());
50+
$this->assertSame($eol, $c->getSymfonyEol());
4451
}
4552

4653
/**
@@ -73,11 +80,37 @@ public function testCollectWithoutKernel()
7380
$this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
7481
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
7582
$this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
76-
$this->assertNull($c->isSymfonyLts());
83+
$this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts());
7784
$this->assertNull($c->getToken());
7885
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
7986
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
8087
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
88+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
89+
$this->assertSame($this->determineSymfonyState(), $c->getSymfonyState());
90+
91+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
92+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
93+
$this->assertSame($eom, $c->getSymfonyEom());
94+
$this->assertSame($eol, $c->getSymfonyEol());
95+
}
96+
97+
private function determineSymfonyState(): string
98+
{
99+
$now = new \DateTime();
100+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
101+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
102+
103+
if ($now > $eol) {
104+
$versionState = 'eol';
105+
} elseif ($now > $eom) {
106+
$versionState = 'eom';
107+
} elseif ('' !== Kernel::EXTRA_VERSION) {
108+
$versionState = 'dev';
109+
} else {
110+
$versionState = 'stable';
111+
}
112+
113+
return $versionState;
81114
}
82115
}
83116

0 commit comments

Comments
 (0)
< 2A78 /div>
0