Skip to content

Commit 47d390c

Browse files
committed
feature #24 Add missing typehint, remove unused imports and remove extra spaces (yceruto)
This PR was merged into the 1.0-dev branch. Discussion ---------- Add missing typehint, remove unused imports and remove extra spaces Commits ------- d04a677 Add missing typehint, remove unused imports and remove extra spaces
2 parents d1d5f36 + d04a677 commit 47d390c

17 files changed

+40
-54
lines changed

src/Command/AbstractCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public function __construct(Generator $generator)
4444
* Returns the parameters used to parse the file templates, to generate the
4545
* file names, etc.
4646
*/
47-
abstract protected function getParameters() : array;
47+
abstract protected function getParameters(): array;
4848

4949
/**
5050
* Returns the list of files to generate and the templates used to do that.
5151
*/
52-
abstract protected function getFiles(array $params) : array;
52+
abstract protected function getFiles(array $params): array;
5353

5454
/**
5555
* Override to add a final "next steps" message.

src/Command/MakeCommandCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function getParameters(): array
5050
protected function getFiles(array $params): array
5151
{
5252
return [
53-
__DIR__.'/../Resources/skeleton/command/Command.php.txt' => 'src/Command/'.$params['command_class_name'].'.php'
53+
__DIR__.'/../Resources/skeleton/command/Command.php.txt' => 'src/Command/'.$params['command_class_name'].'.php',
5454
];
5555
}
5656

src/Command/MakeControllerCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function getParameters(): array
5555
return [
5656
'controller_class_name' => $controllerClassName,
5757
'route_path' => Str::asRoutePath(str_replace('Controller', '', $controllerClassName)),
58-
'route_name' => Str::asRouteName(str_replace('Controller', '', $controllerClassName))
58+
'route_name' => Str::asRouteName(str_replace('Controller', '', $controllerClassName)),
5959
];
6060
}
6161

@@ -64,7 +64,7 @@ protected function getFiles(array $params): array
6464
$skeletonFile = $this->isTwigInstalled() ? 'ControllerWithTwig.php.txt' : 'Controller.php.txt';
6565

6666
return [
67-
__DIR__.'/../Resources/skeleton/controller/'.$skeletonFile => 'src/Controller/'.$params['controller_class_name'].'.php'
67+
__DIR__.'/../Resources/skeleton/controller/'.$skeletonFile => 'src/Controller/'.$params['controller_class_name'].'.php',
6868
];
6969
}
7070

src/Command/MakeEntityCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Command;
1313

14+
use Doctrine\ORM\Mapping\Column;
1415
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1516
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1617
use Symfony\Bundle\MakerBundle\Str;
1718
use Symfony\Bundle\MakerBundle\Validator;
1819
use Symfony\Component\Console\Input\InputArgument;
19-
use Doctrine\ORM\Mapping\Column;
2020

2121
/**
2222
* @author Javier Eguiluz <[email protected]>

src/Command/MakeFormCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function getParameters(): array
5151
protected function getFiles(array $params): array
5252
{
5353
return [
54-
__DIR__.'/../Resources/skeleton/form/Type.php.txt' => 'src/Form/'.$params['form_class_name'].'.php'
54+
__DIR__.'/../Resources/skeleton/form/Type.php.txt' => 'src/Form/'.$params['form_class_name'].'.php',
5555
];
5656
}
5757

src/Command/MakeSubscriberCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function getParameters(): array
9191
protected function getFiles(array $params): array
9292
{
9393
return [
94-
__DIR__.'/../Resources/skeleton/event/Subscriber.php.txt' => 'src/EventSubscriber/'.$params['subscriber_class_name'].'.php'
94+
__DIR__.'/../Resources/skeleton/event/Subscriber.php.txt' => 'src/EventSubscriber/'.$params['subscriber_class_name'].'.php',
9595
];
9696
}
9797

src/Command/MakeUnitTestCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,4 @@ protected function configureDependencies(DependencyBuilder $dependencies)
6363
{
6464
// TODO: Implement configureDependencies() method.
6565
}
66-
67-
6866
}

src/Command/MakeVoterCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function getParameters(): array
4848
protected function getFiles(array $params): array
4949
{
5050
return [
51-
__DIR__.'/../Resources/skeleton/security/Voter.php.txt' => 'src/Security/Voter/'.$params['voter_class_name'].'.php'
51+
__DIR__.'/../Resources/skeleton/security/Voter.php.txt' => 'src/Security/Voter/'.$params['voter_class_name'].'.php',
5252
];
5353
}
5454

src/DependencyBuilder.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@ final class DependencyBuilder
1212
* If the dependency is *optional*, then it will only be reported to
1313
* the user if other required dependencies are missing. An example
1414
* is the "validator" when trying to work with forms.
15-
*
16-
* @param string $class
17-
* @param string $package
18-
* @param bool $required
1915
*/
20-
public function addClassDependency($class, $package, $required = true)
16+
public function addClassDependency(string $class, string $package, bool $required = true)
2117
{
2218
$this->dependencies[$class] = [
2319
'name' => $package,
24-
'required' => $required
20+
'required' => $required,
2521
];
2622
}
2723

28-
public function getMissingDependencies()
24+
public function getMissingDependencies(): array
2925
{
3026
$missingPackages = [];
3127
$missingOptionalPackages = [];
@@ -48,4 +44,4 @@ public function getMissingDependencies()
4844

4945
return array_merge($missingPackages, $missingOptionalPackages);
5046
}
51-
}
47+
}

src/DependencyInjection/MakerExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\DependencyInjection;
1313

14-
use Symfony\Component\DependencyInjection\ContainerBuilder;
1514
use Symfony\Component\Config\FileLocator;
16-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Loader;
17+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1818

1919
/**
2020
* This is the class that loads and manages your bundle configuration.

src/Event/ConsoleErrorSubscriber.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function getSubscribedEvents()
5757
{
5858
return [
5959
ConsoleEvents::ERROR => 'onConsoleError',
60-
ConsoleEvents::TERMINATE => 'onConsoleTerminate'
60+
ConsoleEvents::TERMINATE => 'onConsoleTerminate',
6161
];
6262
}
63-
}
63+
}

src/EventRegistry.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
4949

5050
/**
5151
* Returns all known event names in the system.
52-
*
53-
* @return array
5452
*/
55-
public function getAllActiveEvents()
53+
public function getAllActiveEvents(): array
5654
{
5755
$activeEvents = [];
5856
foreach (self::$eventsMap as $eventName => $eventClass) {
@@ -73,19 +71,16 @@ public function getAllActiveEvents()
7371

7472
/**
7573
* Attempts to get the event class for a given event.
76-
*
77-
* @param string $event
78-
* @return null|string
7974
*/
80-
public function getEventClassName($event)
75+
public function getEventClassName(string $event): ?string
8176
{
8277
if (isset(self::$eventsMap[$event])) {
8378
return self::$eventsMap[$event];
8479
}
8580

8681
$listeners = $this->eventDispatcher->getListeners($event);
8782
if (empty($listeners)) {
88-
return;
83+
return null;
8984
}
9085

9186
foreach ($listeners as $listener) {

src/FileManager.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@
2020
*/
2121
class FileManager
2222
{
23-
/** @var Filesystem */
2423
private $fs;
24+
private $rootDirectory;
2525
/** @var SymfonyStyle */
2626
private $io;
27-
private $rootDirectory;
2827

29-
public function __construct(Filesystem $fs, $rootDirectory = null)
28+
public function __construct(Filesystem $fs, string $rootDirectory = null)
3029
{
3130
$this->fs = $fs;
3231
$this->rootDirectory = $rootDirectory ?: getcwd();
3332
}
3433

35-
public function setIO(SymfonyStyle $io)
34+
public function setIO(SymfonyStyle $io): void
3635
{
3736
$this->io = $io;
3837
}
3938

40-
public function parseTemplate(string $templatePath, array $parameters) : string
39+
public function parseTemplate(string $templatePath, array $parameters): string
4140
{
4241
$keys = array_keys($parameters);
4342
$values = array_values($parameters);
@@ -48,18 +47,18 @@ public function parseTemplate(string $templatePath, array $parameters) : string
4847
return str_replace($placeholders, $values, file_get_contents($templatePath));
4948
}
5049

51-
public function dumpFile(string $filename, string $content)
50+
public function dumpFile(string $filename, string $content): void
5251
{
5352
$this->fs->dumpFile($this->absolutizePath($filename), $content);
5453
$this->io->comment(sprintf('<fg=green>created</>: %s', $this->relativizePath($filename)));
5554
}
5655

57-
public function fileExists($path)
56+
public function fileExists($path): bool
5857
{
5958
return file_exists($this->absolutizePath($path));
6059
}
6160

62-
private function absolutizePath($path)
61+
private function absolutizePath($path): string
6362
{
6463
if ('/' === substr($path, 0, 1)) {
6564
return $path;
@@ -68,7 +67,7 @@ private function absolutizePath($path)
6867
return sprintf('%s/%s', $this->rootDirectory, $path);
6968
}
7069

71-
private function relativizePath($absolutePath)
70+
private function relativizePath($absolutePath): string
7271
{
7372
$relativePath = str_replace($this->rootDirectory, '.', $absolutePath);
7473

src/Generator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\MakerBundle;
1313

1414
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
15-
use Symfony\Component\Console\Exception\RuntimeException;
1615
use Symfony\Component\Console\Style\SymfonyStyle;
1716

1817
/**
@@ -35,7 +34,7 @@ public function setIO(SymfonyStyle $io)
3534
$this->fileManager->setIO($io);
3635
}
3736

38-
public function generate(array $parameters, array $files) : void
37+
public function generate(array $parameters, array $files): void
3938
{
4039
// check if any of the files to be generated already exists
4140
foreach ($files as $target) {

src/Str.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class Str
2020
/**
2121
* Looks for suffixes in a case-insensitive way.
2222
*/
23-
public static function hasSuffix(string $value, string $suffix) : bool
23+
public static function hasSuffix(string $value, string $suffix): bool
2424
{
2525
return 0 === strcasecmp($suffix, substr($value, -strlen($suffix)));
2626
}
@@ -29,7 +29,7 @@ public static function hasSuffix(string $value, string $suffix) : bool
2929
* Ensures that the given string ends with the given suffix. It works in a
3030
* case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand'
3131
*/
32-
public static function addSuffix(string $value, string $suffix) : string
32+
public static function addSuffix(string $value, string $suffix): string
3333
{
3434
return self::removeSuffix($value, $suffix).$suffix;
3535
}
@@ -38,7 +38,7 @@ public static function addSuffix(string $value, string $suffix) : string
3838
* Ensures that the given string doesn't end with the given suffix. It works in a
3939
* case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'Foo'
4040
*/
41-
public static function removeSuffix(string $value, string $suffix) : string
41+
public static function removeSuffix(string $value, string $suffix): string
4242
{
4343
return self::hasSuffix($value, $suffix) ? substr($value, 0, -strlen($suffix)) : $value;
4444
}
@@ -47,7 +47,7 @@ public static function removeSuffix(string $value, string $suffix) : string
4747
* Transforms the given string into the format commonly used by PHP classes
4848
* (e.g. `app:do_this-and_that` -> `AppDoThisAndThat`)
4949
*/
50-
public static function asClassName(string $value, string $suffix = '') : string
50+
public static function asClassName(string $value, string $suffix = ''): string
5151
{
5252
$value = trim($value);
5353
$value = str_replace(['-', '_', '.', ':'], ' ', $value);
@@ -63,7 +63,7 @@ public static function asClassName(string $value, string $suffix = '') : string
6363
* Transforms the given string into the format commonly used by Twig variables
6464
* (e.g. `BlogPostType` -> `blog_post_type`)
6565
*/
66-
public static function asTwigVariable(string $value) : string
66+
public static function asTwigVariable(string $value): string
6767
{
6868
$value = trim($value);
6969
$value = preg_replace('/[^a-zA-Z0-9_]/', '_', $value);
@@ -74,27 +74,27 @@ public static function asTwigVariable(string $value) : string
7474
return $value;
7575
}
7676

77-
public static function asRoutePath(string $value) : string
77+
public static function asRoutePath(string $value): string
7878
{
7979
return '/'.str_replace('_', '/', self::asTwigVariable($value));
8080
}
8181

82-
public static function asRouteName(string $value) : string
82+
public static function asRouteName(string $value): string
8383
{
8484
return self::asTwigVariable($value);
8585
}
8686

87-
public static function asCommand(string $value) : string
87+
public static function asCommand(string $value): string
8888
{
8989
return str_replace('_', '-', self::asTwigVariable($value));
9090
}
9191

92-
public static function asEventMethod(string $eventName) : string
92+
public static function asEventMethod(string $eventName): string
9393
{
9494
return sprintf('on%s', self::asClassName($eventName));
9595
}
9696

97-
public static function getRandomTerm() : string
97+
public static function getRandomTerm(): string
9898
{
9999
$adjectives = [
100100
'tiny',

src/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class Validator
1919
{
20-
public static function validateClassName(string $className, string $errorMessage = '') : void
20+
public static function validateClassName(string $className, string $errorMessage = ''): void
2121
{
2222
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $className)) {
2323
$errorMessage = $errorMessage ?: sprintf('"%s" is not valid as a PHP class name (it must start with a letter or underscore, followed by any number of letters, numbers, or underscores)', $className);

tests/EventRegistryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Bundle\MakerBundle\EventRegistry;
7-
use Symfony\Bundle\MakerBundle\Str;
87
use Symfony\Component\EventDispatcher\Event;
98
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
109
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;

0 commit comments

Comments
 (0)