Skip to content

Commit b869a5c

Browse files
authored
Merge branch 'master' into fix-entity-regeneration-traits-ms
2 parents e6c640b + 319a73d commit b869a5c

17 files changed

+60
-70
lines changed

src/Command/MakerCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function configure()
5656
protected function initialize(InputInterface $input, OutputInterface $output)
5757
{
5858
$this->io = new ConsoleStyle($input, $output);
59-
$this->fileManager->setIo($this->io);
59+
$this->fileManager->setIO($this->io);
6060

6161
if ($this->checkDependencies) {
6262
$dependencies = new DependencyBuilder();
@@ -75,7 +75,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
7575
continue;
7676
}
7777

78-
if (in_array($argument->getName(), $this->inputConfig->getNonInteractiveArguments(), true)) {
78+
if (\in_array($argument->getName(), $this->inputConfig->getNonInteractiveArguments(), true)) {
7979
continue;
8080
}
8181

src/DependencyBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getMissingPackagesMessage(string $commandName): string
8484
return '';
8585
}
8686

87-
$packagesCount = count($packages) + count($packagesDev);
87+
$packagesCount = \count($packages) + \count($packagesDev);
8888

8989
$message = sprintf(
9090
"Missing package%s: to use the %s command, run:\n",
@@ -103,7 +103,7 @@ public function getMissingPackagesMessage(string $commandName): string
103103
return $message;
104104
}
105105

106-
private function getRequiredDependencyNames(array $dependencies)
106+
private function getRequiredDependencyNames(array $dependencies): array
107107
{
108108
$packages = [];
109109
foreach ($dependencies as $package) {
@@ -116,7 +116,7 @@ private function getRequiredDependencyNames(array $dependencies)
116116
return array_unique($packages);
117117
}
118118

119-
private function calculateMissingDependencies(array $dependencies)
119+
private function calculateMissingDependencies(array $dependencies): array
120120
{
121121
$missingPackages = [];
122122
$missingOptionalPackages = [];

src/Doctrine/DoctrineHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
125125
if (null === $classOrNamespace) {
126126
$metadata[$m->getName()] = $m;
127127
} else {
128-
if ($m->getName() == $classOrNamespace) {
128+
if ($m->getName() === $classOrNamespace) {
129129
return $m;
130130
}
131131

src/Doctrine/EntityRegenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ final class EntityRegenerator
2828
private $doctrineHelper;
2929
private $fileManager;
3030
private $generator;
31-
private $projectDirectory;
3231
private $overwrite;
3332

3433
public function __construct(DoctrineHelper $doctrineHelper, FileManager $fileManager, Generator $generator, string $projectDirectory, bool $overwrite)
3534
{
3635
$this->doctrineHelper = $doctrineHelper;
3736
$this->fileManager = $fileManager;
3837
$this->generator = $generator;
39-
$this->projectDirectory = $projectDirectory;
4038
$this->overwrite = $overwrite;
4139
}
4240

@@ -105,7 +103,7 @@ public function regenerateEntities(string $classOrNamespace)
105103
}
106104

107105
$getIsNullable = function (array $mapping) {
108-
if (!isset($mapping['joinColumns'][0]) || !isset($mapping['joinColumns'][0]['nullable'])) {
106+
if (!isset($mapping['joinColumns'][0]['nullable'])) {
109107
// the default for relationships IS nullable
110108
return true;
111109
}

src/Doctrine/EntityRelation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class EntityRelation
3939

4040
public function __construct(string $type, string $owningClass, string $inverseClass)
4141
{
42-
if (!in_array($type, self::getValidRelationTypes())) {
42+
if (!\in_array($type, self::getValidRelationTypes())) {
4343
throw new \Exception(sprintf('Invalid relation type "%s"', $type));
4444
}
4545

src/EventRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function getEventClassName(string $event)
9696
}
9797

9898
foreach ($listeners as $listener) {
99-
if (!is_array($listener) || 2 !== count($listener)) {
99+
if (!\is_array($listener) || 2 !== \count($listener)) {
100100
continue;
101101
}
102102

src/FileManager.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(Filesystem $fs, AutoloaderUtil $autoloaderUtil, stri
3636
// update EntityRegeneratorTest to mock the autoloader
3737
$this->fs = $fs;
3838
$this->autoloaderUtil = $autoloaderUtil;
39-
$this->rootDirectory = rtrim($this->realpath($this->normalizeSlashes($rootDirectory)), '/');
39+
$this->rootDirectory = rtrim($this->realPath($this->normalizeSlashes($rootDirectory)), '/');
4040
}
4141

4242
public function setIO(SymfonyStyle $io)
@@ -196,8 +196,7 @@ private function realPath($absolutePath): string
196196
$finalPath = implode('/', $finalParts);
197197
// Normalize: // => /
198198
// Normalize: /./ => /
199-
$finalPath = str_replace('//', '/', $finalPath);
200-
$finalPath = str_replace('/./', '/', $finalPath);
199+
$finalPath = str_replace(['//', '/./'], '/', $finalPath);
201200

202201
return $finalPath;
203202
}

src/Maker/MakeEntity.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
9898
continue;
9999
}
100100

101-
$classes[] = str_replace('/', '\\', str_replace('.php', '', $item->getRelativePathname()));
101+
$classes[] = str_replace(['.php', '/'], ['', '\\'], $item->getRelativePathname());
102102
}
103103

104104
$argument = $command->getDefinition()->getArgument('name');
@@ -191,7 +191,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
191191
$fileManagerOperations = [];
192192
$fileManagerOperations[$entityPath] = $manipulator;
193193

194-
if (is_array($newField)) {
194+
if (\is_array($newField)) {
195195
$annotationOptions = $newField;
196196
unset($annotationOptions['fieldName']);
197197
$manipulator->addEntityField($newField['fieldName'], $annotationOptions);
@@ -254,7 +254,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
254254
}
255255

256256
foreach ($fileManagerOperations as $path => $manipulatorOrMessage) {
257-
if (is_string($manipulatorOrMessage)) {
257+
if (\is_string($manipulatorOrMessage)) {
258258
$io->comment($manipulatorOrMessage);
259259
} else {
260260
$this->fileManager->dumpFile($path, $manipulatorOrMessage->getSourceCode());
@@ -300,28 +300,29 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
300300
return $name;
301301
}
302302

303-
if (in_array($name, $fields)) {
303+
if (\in_array($name, $fields)) {
304304
throw new \InvalidArgumentException(sprintf('The "%s" property already exists.', $name));
305305
}
306306

307307
return Validator::validateDoctrineFieldName($name, $this->doctrineHelper->getRegistry());
308308
});
309309

310310
if (!$fieldName) {
311-
return;
311+
return null;
312312
}
313313

314314
$defaultType = 'string';
315315
// try to guess the type by the field name prefix/suffix
316316
// convert to snake case for simplicity
317317
$snakeCasedField = Str::asSnakeCase($fieldName);
318-
if ('_at' == substr($snakeCasedField, -3)) {
318+
319+
if ('_at' === $suffix = substr($snakeCasedField, -3)) {
319320
$defaultType = 'datetime';
320-
} elseif ('_id' == substr($snakeCasedField, -3)) {
321+
} elseif ('_id' === $suffix) {
321322
$defaultType = 'integer';
322-
} elseif ('is_' == substr($snakeCasedField, 0, 3)) {
323+
} elseif (0 === strpos($snakeCasedField, 'is_')) {
323324
$defaultType = 'boolean';
324-
} elseif ('has_' == substr($snakeCasedField, 0, 4)) {
325+
} elseif (0 === strpos($snakeCasedField, 'has_')) {
325326
$defaultType = 'boolean';
326327
}
327328

@@ -341,7 +342,7 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
341342
$io->writeln('');
342343

343344
$type = null;
344-
} elseif (!in_array($type, $allValidTypes)) {
345+
} elseif (!\in_array($type, $allValidTypes)) {
345346
$this->printAvailableTypes($io);
346347
$io->error(sprintf('Invalid type "%s".', $type));
347348
$io->writeln('');
@@ -350,7 +351,7 @@ private function askForNextField(ConsoleStyle $io, array $fields, string $entity
350351
}
351352
}
352353

353-
if ('relation' === $type || in_array($type, EntityRelation::getValidRelationTypes())) {
354+
if ('relation' === $type || \in_array($type, EntityRelation::getValidRelationTypes())) {
354355
return $this->askRelationDetails($io, $entityClass, $type, $fieldName);
355356
}
356357

@@ -414,9 +415,9 @@ private function printAvailableTypes(ConsoleStyle $io)
414415
unset($allTypes[$mainType]);
415416
$line = sprintf(' * <comment>%s</comment>', $mainType);
416417

417-
if (is_string($subTypes) && $subTypes) {
418+
if (\is_string($subTypes) && $subTypes) {
418419
$line .= sprintf(' (%s)', $subTypes);
419-
} elseif (is_array($subTypes) && !empty($subTypes)) {
420+
} elseif (\is_array($subTypes) && !empty($subTypes)) {
420421
$line .= sprintf(' (or %s)', implode(', ', array_map(function ($subType) {
421422
return sprintf('<comment>%s</comment>', $subType);
422423
}, $subTypes)));
@@ -560,7 +561,7 @@ function ($name) use ($targetClass) {
560561
}
561562

562563
// recommend an inverse side, except for OneToOne, where it's inefficient
563-
$recommendMappingInverse = EntityRelation::ONE_TO_ONE === $relation->getType() ? false : true;
564+
$recommendMappingInverse = EntityRelation::ONE_TO_ONE !== $relation->getType();
564565

565566
$getterMethodName = 'get'.Str::asCamelCase(Str::getShortClassName($relation->getOwningClass()));
566567
if (EntityRelation::ONE_TO_ONE !== $relation->getType()) {
@@ -742,7 +743,7 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
742743
));
743744
$question->setAutocompleterValues(EntityRelation::getValidRelationTypes());
744745
$question->setValidator(function ($type) {
745-
if (!in_array($type, EntityRelation::getValidRelationTypes())) {
746+
if (!\in_array($type, EntityRelation::getValidRelationTypes())) {
746747
throw new \InvalidArgumentException(sprintf('Invalid type: use one of: %s', implode(', ', EntityRelation::getValidRelationTypes())));
747748
}
748749

@@ -801,7 +802,7 @@ private function doesEntityUseAnnotationMapping(string $className): bool
801802
return false;
802803
}
803804

804-
$className = (reset($otherClassMetadatas))->getName();
805+
$className = reset($otherClassMetadatas)->getName();
805806
}
806807

807808
$driver = $this->doctrineHelper->getMappingDriverForClass($className);

src/Maker/MakeValidator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Bundle\MakerBundle\Generator;
1717
use Symfony\Bundle\MakerBundle\InputConfiguration;
1818
use Symfony\Bundle\MakerBundle\Str;
19-
use Symfony\Bundle\MakerBundle\Validator;
2019
use Symfony\Component\Console\Command\Command;
2120
use Symfony\Component\Console\Input\InputArgument;
2221
use Symfony\Component\Console\Input\InputInterface;

src/Resources/doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ can be improved and new commands can be added.
6464

6565
For that reason, in general, the generated code cannot be modified. In many cases,
6666
adding your *own* maker command is so easy, that we recommend that. However, if there
67-
is some extension point that you'd like, please open an issue do we can discuss!
67+
is some extension point that you'd like, please open an issue so we can discuss!
6868

6969
.. _`SensioGeneratorBundle`: https://github.com/sensiolabs/SensioGeneratorBundle
7070
.. _`Symfony Flex`: https://symfony.com/doc/current/setup/flex.html

0 commit comments

Comments
 (0)