Skip to content

Add missing typehint, remove unused imports and remove extra spaces #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function __construct(Generator $generator)
* Returns the parameters used to parse the file templates, to generate the
* file names, etc.
*/
abstract protected function getParameters() : array;
abstract protected function getParameters(): array;

/**
* Returns the list of files to generate and the templates used to do that.
*/
abstract protected function getFiles(array $params) : array;
abstract protected function getFiles(array $params): array;

/**
* Override to add a final "next steps" message.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MakeCommandCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getParameters(): array
protected function getFiles(array $params): array
{
return [
__DIR__.'/../Resources/skeleton/command/Command.php.txt' => 'src/Command/'.$params['command_class_name'].'.php'
__DIR__.'/../Resources/skeleton/command/Command.php.txt' => 'src/Command/'.$params['command_class_name'].'.php',
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/MakeControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function getParameters(): array
return [
'controller_class_name' => $controllerClassName,
'route_path' => Str::asRoutePath(str_replace('Controller', '', $controllerClassName)),
'route_name' => Str::asRouteName(str_replace('Controller', '', $controllerClassName))
'route_name' => Str::asRouteName(str_replace('Controller', '', $controllerClassName)),
];
}

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

return [
__DIR__.'/../Resources/skeleton/controller/'.$skeletonFile => 'src/Controller/'.$params['controller_class_name'].'.php'
__DIR__.'/../Resources/skeleton/controller/'.$skeletonFile => 'src/Controller/'.$params['controller_class_name'].'.php',
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/MakeEntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace Symfony\Bundle\MakerBundle\Command;

use Doctrine\ORM\Mapping\Column;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Input\InputArgument;
use Doctrine\ORM\Mapping\Column;

/**
* @author Javier Eguiluz <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MakeFormCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function getParameters(): array
protected function getFiles(array $params): array
{
return [
__DIR__.'/../Resources/skeleton/form/Type.php.txt' => 'src/Form/'.$params['form_class_name'].'.php'
__DIR__.'/../Resources/skeleton/form/Type.php.txt' => 'src/Form/'.$params['form_class_name'].'.php',
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/MakeSubscriberCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function getParameters(): array
protected function getFiles(array $params): array
{
return [
__DIR__.'/../Resources/skeleton/event/Subscriber.php.txt' => 'src/EventSubscriber/'.$params['subscriber_class_name'].'.php'
__DIR__.'/../Resources/skeleton/event/Subscriber.php.txt' => 'src/EventSubscriber/'.$params['subscriber_class_name'].'.php',
];
}

Expand Down
2 changes: 0 additions & 2 deletions src/Command/MakeUnitTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@ protected function configureDependencies(DependencyBuilder $dependencies)
{
// TODO: Implement configureDependencies() method.
}


}
2 changes: 1 addition & 1 deletion src/Command/MakeVoterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getParameters(): array
protected function getFiles(array $params): array
{
return [
__DIR__.'/../Resources/skeleton/security/Voter.php.txt' => 'src/Security/Voter/'.$params['voter_class_name'].'.php'
__DIR__.'/../Resources/skeleton/security/Voter.php.txt' => 'src/Security/Voter/'.$params['voter_class_name'].'.php',
];
}

Expand Down
12 changes: 4 additions & 8 deletions src/DependencyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ final class DependencyBuilder
* If the dependency is *optional*, then it will only be reported to
* the user if other required dependencies are missing. An example
* is the "validator" when trying to work with forms.
*
* @param string $class
* @param string $package
* @param bool $required
*/
public function addClassDependency($class, $package, $required = true)
public function addClassDependency(string $class, string $package, bool $required = true)
{
$this->dependencies[$class] = [
'name' => $package,
'required' => $required
'required' => $required,
];
}

public function getMissingDependencies()
public function getMissingDependencies(): array
{
$missingPackages = [];
$missingOptionalPackages = [];
Expand All @@ -48,4 +44,4 @@ public function getMissingDependencies()

return array_merge($missingPackages, $missingOptionalPackages);
}
}
}
4 changes: 2 additions & 2 deletions src/DependencyInjection/MakerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Symfony\Bundle\MakerBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/Event/ConsoleErrorSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function getSubscribedEvents()
{
return [
ConsoleEvents::ERROR => 'onConsoleError',
ConsoleEvents::TERMINATE => 'onConsoleTerminate'
ConsoleEvents::TERMINATE => 'onConsoleTerminate',
];
}
}
}
11 changes: 3 additions & 8 deletions src/EventRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public function __construct(EventDispatcherInterface $eventDispatcher)

/**
* Returns all known event names in the system.
*
* @return array
*/
public function getAllActiveEvents()
public function getAllActiveEvents(): array
{
$activeEvents = [];
foreach (self::$eventsMap as $eventName => $eventClass) {
Expand All @@ -73,19 +71,16 @@ public function getAllActiveEvents()

/**
* Attempts to get the event class for a given event.
*
* @param string $event
* @return null|string
*/
public function getEventClassName($event)
public function getEventClassName(string $event): ?string
{
if (isset(self::$eventsMap[$event])) {
return self::$eventsMap[$event];
}

$listeners = $this->eventDispatcher->getListeners($event);
if (empty($listeners)) {
return;
return null;
}

foreach ($listeners as $listener) {
Expand Down
17 changes: 8 additions & 9 deletions src/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
*/
class FileManager
{
/** @var Filesystem */
private $fs;
private $rootDirectory;
/** @var SymfonyStyle */
private $io;
private $rootDirectory;

public function __construct(Filesystem $fs, $rootDirectory = null)
public function __construct(Filesystem $fs, string $rootDirectory = null)
{
$this->fs = $fs;
$this->rootDirectory = $rootDirectory ?: getcwd();
}

public function setIO(SymfonyStyle $io)
public function setIO(SymfonyStyle $io): void
{
$this->io = $io;
}

public function parseTemplate(string $templatePath, array $parameters) : string
public function parseTemplate(string $templatePath, array $parameters): string
{
$keys = array_keys($parameters);
$values = array_values($parameters);
Expand All @@ -48,18 +47,18 @@ public function parseTemplate(string $templatePath, array $parameters) : string
return str_replace($placeholders, $values, file_get_contents($templatePath));
}

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

public function fileExists($path)
public function fileExists($path): bool
{
return file_exists($this->absolutizePath($path));
}

private function absolutizePath($path)
private function absolutizePath($path): string
{
if ('/' === substr($path, 0, 1)) {
return $path;
Expand All @@ -68,7 +67,7 @@ private function absolutizePath($path)
return sprintf('%s/%s', $this->rootDirectory, $path);
}

private function relativizePath($absolutePath)
private function relativizePath($absolutePath): string
{
$relativePath = str_replace($this->rootDirectory, '.', $absolutePath);

Expand Down
3 changes: 1 addition & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\MakerBundle;

use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
Expand All @@ -35,7 +34,7 @@ public function setIO(SymfonyStyle $io)
$this->fileManager->setIO($io);
}

public function generate(array $parameters, array $files) : void
public function generate(array $parameters, array $files): void
{
// check if any of the files to be generated already exists
foreach ($files as $target) {
Expand Down
20 changes: 10 additions & 10 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Str
/**
* Looks for suffixes in a case-insensitive way.
*/
public static function hasSuffix(string $value, string $suffix) : bool
public static function hasSuffix(string $value, string $suffix): bool
{
return 0 === strcasecmp($suffix, substr($value, -strlen($suffix)));
}
Expand All @@ -29,7 +29,7 @@ public static function hasSuffix(string $value, string $suffix) : bool
* Ensures that the given string ends with the given suffix. It works in a
* case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand'
*/
public static function addSuffix(string $value, string $suffix) : string
public static function addSuffix(string $value, string $suffix): string
{
return self::removeSuffix($value, $suffix).$suffix;
}
Expand All @@ -38,7 +38,7 @@ public static function addSuffix(string $value, string $suffix) : string
* Ensures that the given string doesn't end with the given suffix. It works in a
* case-insensitive way (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'Foo'
*/
public static function removeSuffix(string $value, string $suffix) : string
public static function removeSuffix(string $value, string $suffix): string
{
return self::hasSuffix($value, $suffix) ? substr($value, 0, -strlen($suffix)) : $value;
}
Expand All @@ -47,7 +47,7 @@ public static function removeSuffix(string $value, string $suffix) : string
* Transforms the given string into the format commonly used by PHP classes
* (e.g. `app:do_this-and_that` -> `AppDoThisAndThat`)
*/
public static function asClassName(string $value, string $suffix = '') : string
public static function asClassName(string $value, string $suffix = ''): string
{
$value = trim($value);
$value = str_replace(['-', '_', '.', ':'], ' ', $value);
Expand All @@ -63,7 +63,7 @@ public static function asClassName(string $value, string $suffix = '') : string
* Transforms the given string into the format commonly used by Twig variables
* (e.g. `BlogPostType` -> `blog_post_type`)
*/
public static function asTwigVariable(string $value) : string
public static function asTwigVariable(string $value): string
{
$value = trim($value);
$value = preg_replace('/[^a-zA-Z0-9_]/', '_', $value);
Expand All @@ -74,27 +74,27 @@ public static function asTwigVariable(string $value) : string
return $value;
}

public static function asRoutePath(string $value) : string
public static function asRoutePath(string $value): string
{
return '/'.str_replace('_', '/', self::asTwigVariable($value));
}

public static function asRouteName(string $value) : string
public static function asRouteName(string $value): string
{
return self::asTwigVariable($value);
}

public static function asCommand(string $value) : string
public static function asCommand(string $value): string
{
return str_replace('_', '-', self::asTwigVariable($value));
}

public static function asEventMethod(string $eventName) : string
public static function asEventMethod(string $eventName): string
{
return sprintf('on%s', self::asClassName($eventName));
}

public static function getRandomTerm() : string
public static function getRandomTerm(): string
{
$adjectives = [
'tiny',
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class Validator
{
public static function validateClassName(string $className, string $errorMessage = '') : void
public static function validateClassName(string $className, string $errorMessage = ''): void
{
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $className)) {
$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);
Expand Down
1 change: 0 additions & 1 deletion tests/EventRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\EventRegistry;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
Expand Down