Skip to content

Commit 48c1634

Browse files
committed
feature #1128 improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods - removes Argon2 support with `make:user` - deprecates unused methods that are not `final` or `internal` - removes PHP 7.x version checks - uses rector (not included) to bring `src` up to PHP 8 standards Commits ------- 88148d0 improve PHP 8 support w/ rector, removes legacy code, deprecates unused methods
2 parents 33fb24f + 88148d0 commit 48c1634

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+195
-372
lines changed

src/Command/MakerCommand.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
5757
$dependencies = new DependencyBuilder();
5858
$this->maker->configureDependencies($dependencies, $input);
5959

60-
if (!$dependencies->isPhpVersionSatisfied()) {
61-
throw new RuntimeCommandException('The make:entity command requires that you use PHP 7.1 or higher.');
62-
}
63-
6460
if ($missingPackagesMessage = $dependencies->getMissingPackagesMessage($this->getName())) {
6561
throw new RuntimeCommandException($missingPackagesMessage);
6662
}

src/Console/MigrationDiffFilteredOutput.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616

17-
if (\PHP_VERSION_ID < 80000
18-
// look for the "string|iterable" type on OutputInterface::write()
19-
|| !(new \ReflectionMethod(OutputInterface::class, 'write'))->getParameters()[0]->getType()) {
17+
// look for the "string|iterable" type on OutputInterface::write()
18+
// @legacy - Use MigrationDiffFilteredOutput_php8 when Symfony 5.4 is no longer supported
19+
if (!(new \ReflectionMethod(OutputInterface::class, 'write'))->getParameters()[0]->getType()) {
2020
class MigrationDiffFilteredOutput implements OutputInterface
2121
{
2222
use BaseMakerMigrationDiffFilteredOuputTrait;
@@ -47,13 +47,12 @@ public function setDecorated($decorated)
4747

4848
trait BaseMakerMigrationDiffFilteredOuputTrait
4949
{
50-
private $output;
51-
private $buffer = '';
52-
private $previousLineWasRemoved = false;
50+
private string $buffer = '';
51+
private bool $previousLineWasRemoved = false;
5352

54-
public function __construct(OutputInterface $output)
55-
{
56-
$this->output = $output;
53+
public function __construct(
54+
private OutputInterface $output,
55+
) {
5756
}
5857

5958
public function _write($messages, bool $newline = false, $options = 0)
@@ -144,7 +143,7 @@ private function filterMessages($messages, bool $newLine)
144143

145144
$this->previousLineWasRemoved = false;
146145
foreach ($hiddenPhrases as $hiddenPhrase) {
147-
if (false !== strpos($message, $hiddenPhrase)) {
146+
if (str_contains($message, $hiddenPhrase)) {
148147
$this->previousLineWasRemoved = true;
149148
unset($messages[$key]);
150149

src/ConsoleStyle.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
*/
2222
final class ConsoleStyle extends SymfonyStyle
2323
{
24-
private $output;
25-
26-
public function __construct(InputInterface $input, OutputInterface $output)
27-
{
28-
$this->output = $output;
29-
24+
public function __construct(
25+
InputInterface $input,
26+
private OutputInterface $output,
27+
) {
3028
parent::__construct($input, $output);
3129
}
3230

src/DependencyBuilder.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
final class DependencyBuilder
1515
{
16-
private $dependencies = [];
17-
private $devDependencies = [];
18-
19-
private $minimumPHPVersion = 70100;
16+
private array $dependencies = [];
17+
private array $devDependencies = [];
2018

2119
/**
2220
* Add a dependency that will be reported if the given class is missing.
@@ -44,7 +42,7 @@ public function addClassDependency(string $class, string $package, bool $require
4442

4543
public function requirePHP71(): void
4644
{
47-
// no-op - MakerBundle now required PHP 7.1
45+
trigger_deprecation('symfony/maker-bundle', 'v1.44.0', 'requirePHP71() is deprecated and will be removed in a future version.');
4846
}
4947

5048
/**
@@ -110,14 +108,6 @@ public function getMissingPackagesMessage(string $commandName, $message = null):
110108
return $message;
111109
}
112110

113-
/**
114-
* @internal
115-
*/
116-
public function isPhpVersionSatisfied(): bool
117-
{
118-
return \PHP_VERSION_ID >= $this->minimumPHPVersion;
119-
}
120-
121111
private function getRequiredDependencyNames(array $dependencies): array
122112
{
123113
$packages = [];
@@ -149,6 +139,6 @@ private function calculateMissingDependencies(array $dependencies): array
149139
return [];
150140
}
151141

152-
return array_unique(array_merge($missingPackages, $missingOptionalPackages));
142+
return array_unique([...$missingPackages, ...$missingOptionalPackages]);
153143
}
154144
}

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ class Configuration implements ConfigurationInterface
2222
public function getConfigTreeBuilder(): TreeBuilder
2323
{
2424
$treeBuilder = new TreeBuilder('maker');
25-
if (method_exists($treeBuilder, 'getRootNode')) {
26-
$rootNode = $treeBuilder->getRootNode();
27-
} else {
28-
// BC layer for symfony/config 4.1 and older
29-
$rootNode = $treeBuilder->root('maker');
30-
}
25+
$rootNode = $treeBuilder->getRootNode();
3126

3227
$rootNode
3328
->children()

src/Docker/DockerDatabaseServices.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,11 @@ public static function getSuggestedServiceVersion(string $name): string
8383

8484
public static function getMissingExtensionName(string $name): ?string
8585
{
86-
switch ($name) {
87-
case 'mariadb':
88-
case 'mysql':
89-
$driver = 'mysql';
90-
break;
91-
case 'postgres':
92-
$driver = 'pgsql';
93-
break;
94-
default:
95-
self::throwInvalidDatabase($name);
96-
}
86+
$driver = match ($name) {
87+
'mariadb', 'mysql' => 'mysql',
88+
'postgres' => 'pgsql',
89+
default => self::throwInvalidDatabase($name),
90+
};
9791

9892
if (!\in_array($driver, \PDO::getAvailableDrivers(), true)) {
9993
return $driver;

src/Doctrine/DoctrineHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function doesClassUseDriver(string $className, string $driverClass): bool
6868
try {
6969
/** @var EntityManagerInterface $em */
7070
$em = $this->getRegistry()->getManagerForClass($className);
71-
} catch (\ReflectionException $exception) {
71+
} catch (\ReflectionException) {
7272
// this exception will be thrown by the registry if the class isn't created yet.
7373
// an example case is the "make:entity" command, which needs to know which driver is used for the class to determine
7474
// if the class should be generated with attributes or annotations. If this exception is thrown, we will check based on the
@@ -167,7 +167,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
167167
if ($disconnected) {
168168
try {
169169
$loaded = $cmf->getAllMetadata();
170-
} catch (ORMMappingException|PersistenceMappingException $e) {
170+
} catch (ORMMappingException|PersistenceMappingException) {
171171
$loaded = $this->isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf->getLoadedMetadata() : [];
172172
}
173173

src/Doctrine/EntityDetails.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public function getFormFields(): array
5252

5353
if (!empty($this->metadata->embeddedClasses)) {
5454
foreach (array_keys($this->metadata->embeddedClasses) as $embeddedClassKey) {
55-
$fields = array_filter($fields, function ($v) use ($embeddedClassKey) {
56-
return 0 !== strpos($v, $embeddedClassKey.'.');
57-
});
55+
$fields = array_filter($fields, static fn ($v) => !str_starts_with($v, $embeddedClassKey.'.'));
5856
}
5957
}
6058

src/Doctrine/EntityRegenerator.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function regenerateEntities(string $classOrNamespace): void
3838
{
3939
try {
4040
$metadata = $this->doctrineHelper->getMetadata($classOrNamespace);
41-
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException $mappingException) {
41+
} catch (MappingException|LegacyCommonMappingException|PersistenceMappingException) {
4242
$metadata = $this->doctrineHelper->getMetadata($classOrNamespace, true);
4343
}
4444

@@ -72,7 +72,7 @@ public function regenerateEntities(string $classOrNamespace): void
7272
$embeddedClasses = [];
7373

7474
foreach ($classMetadata->embeddedClasses as $fieldName => $mapping) {
75-
if (false !== strpos($fieldName, '.')) {
75+
if (str_contains($fieldName, '.')) {
7676
continue;
7777
}
7878

@@ -91,7 +91,7 @@ public function regenerateEntities(string $classOrNamespace): void
9191

9292
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
9393
// skip embedded fields
94-
if (false !== strpos($fieldName, '.')) {
94+
if (str_contains($fieldName, '.')) {
9595
[$fieldName, $embeddedFiledName] = explode('.', $fieldName);
9696

9797
$operations[$embeddedClasses[$fieldName]]->addEntityField($embeddedFiledName, $mapping);
@@ -238,11 +238,11 @@ private function getMappedFieldsInEntity(ClassMetadata $classMetadata): array
238238
/** @var \ReflectionClass $classReflection */
239239
$classReflection = $classMetadata->reflClass;
240240

241-
$targetFields = array_merge(
242-
array_keys($classMetadata->fieldMappings),
243-
array_keys($classMetadata->associationMappings),
244-
array_keys($classMetadata->embeddedClasses)
245-
);
241+
$targetFields = [
242+
...array_keys($classMetadata->fieldMappings),
243+
...array_keys($classMetadata->associationMappings),
244+
...array_keys($classMetadata->embeddedClasses),
245+
];
246246

247247
if ($classReflection) {
248248
// exclude traits
@@ -257,10 +257,8 @@ private function getMappedFieldsInEntity(ClassMetadata $classMetadata): array
257257
$targetFields = array_diff($targetFields, $traitProperties);
258258

259259
// exclude inherited properties
260-
$targetFields = array_filter($targetFields, static function ($field) use ($classReflection) {
261-
return $classReflection->hasProperty($field) &&
262-
$classReflection->getProperty($field)->getDeclaringClass()->getName() == $classReflection->getName();
263-
});
260+
$targetFields = array_filter($targetFields, static fn ($field) => $classReflection->hasProperty($field) &&
261+
$classReflection->getProperty($field)->getDeclaringClass()->getName() === $classReflection->getName());
264262
}
265263

266264
return $targetFields;

src/Event/ConsoleErrorSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
final class ConsoleErrorSubscriber implements EventSubscriberInterface
2727
{
28-
private $setExitCode = false;
28+
private bool $setExitCode = false;
2929

3030
public function onConsoleError(ConsoleErrorEvent $event): void
3131
{

src/EventRegistry.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
class EventRegistry
4444
{
4545
// list of *known* events to always include (if they exist)
46-
private static $newEventsMap = [
46+
private static array $newEventsMap = [
4747
'kernel.exception' => ExceptionEvent::class,
4848
'kernel.request' => RequestEvent::class,
4949
'kernel.response' => ResponseEvent::class,
@@ -53,7 +53,7 @@ class EventRegistry
5353
'kernel.terminate' => TerminateEvent::class,
5454
];
5555

56-
private static $eventsMap = [
56+
private static array $eventsMap = [
5757
'console.command' => ConsoleCommandEvent::class,
5858
'console.terminate' => ConsoleTerminateEvent::class,
5959
'console.error' => ConsoleErrorEvent::class,
@@ -71,12 +71,9 @@ class EventRegistry
7171
'security.switch_user' => SwitchUserEvent::class,
7272
];
7373

74-
private $eventDispatcher;
75-
76-
public function __construct(EventDispatcherInterface $eventDispatcher)
77-
{
78-
$this->eventDispatcher = $eventDispatcher;
79-
74+
public function __construct(
75+
private EventDispatcherInterface $eventDispatcher,
76+
) {
8077
// Loop through the new event classes
8178
foreach (self::$newEventsMap as $eventName => $newEventClass) {
8279
// Check if the new event classes exist, if so replace the old one with the new.

0 commit comments

Comments
 (0)