Skip to content

Add more PHP CS Fixer rules #561

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
May 10, 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
8 changes: 7 additions & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ return PhpCsFixer\Config::create()
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'no_php4_constructor' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder($finder)
->setCacheFile(__DIR__.'/var/.php_cs.cache')
Expand Down
2 changes: 1 addition & 1 deletion app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function registerBundles()
// the unit and functional tests. Therefore, they are only registered
// when the application runs in 'dev' or 'test' environments. This allows
// to increase application performance in the production environment.
if (in_array($this->getEnvironment(), ['dev', 'test'])) {
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
Expand Down
6 changes: 3 additions & 3 deletions src/AppBundle/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
$password = $console->ask($input, $output, $question);
$input->setArgument('password', $password);
} else {
$output->writeln(' > <info>Password</info>: '.str_repeat('*', strlen($password)));
$output->writeln(' > <info>Password</info>: '.str_repeat('*', mb_strlen($password)));
}

// Ask for the email if it's not defined
Expand Down Expand Up @@ -233,7 +233,7 @@ public function passwordValidator($plainPassword)
throw new \Exception('The password can not be empty.');
}

if (strlen(trim($plainPassword)) < 6) {
if (mb_strlen(trim($plainPassword)) < 6) {
throw new \Exception('The password must be at least 6 characters long.');
}

Expand All @@ -249,7 +249,7 @@ public function emailValidator($email)
throw new \Exception('The email can not be empty.');
}

if (false === strpos($email, '@')) {
if (false === mb_strpos($email, '@')) {
throw new \Exception('The email should look like a real email.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/DataFixtures/FixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function getRandomPostSummary($maxLength = 255)
shuffle($phrases);
$phrases = array_slice($phrases, 0, $numPhrases - 1);

while (strlen($summary = implode('. ', $phrases).'.') > $maxLength) {
while (mb_strlen($summary = implode('. ', $phrases).'.') > $maxLength) {
array_pop($phrases);
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct()
*/
public function isLegitComment()
{
$containsInvalidCharacters = false !== strpos($this->content, '@');
$containsInvalidCharacters = false !== mb_strpos($this->content, '@');

return !$containsInvalidCharacters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function handleConsoleException(ConsoleExceptionEvent $event)
{
$commandNames = ['doctrine:fixtures:load', 'doctrine:database:create', 'doctrine:schema:create', 'doctrine:database:drop'];

if (in_array($event->getCommand()->getName(), $commandNames)) {
if (in_array($event->getCommand()->getName(), $commandNames, true)) {
if ($this->isSQLitePlatform() && !extension_loaded('sqlite3')) {
$io = new SymfonyStyle($event->getInput(), $event->getOutput());
$io->error('This command requires to have the "sqlite3" PHP extension enabled because, by default, the Symfony Demo application uses SQLite to store its information.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator, $locales, $defa

$this->defaultLocale = $defaultLocale ?: $this->locales[0];

if (!in_array($this->defaultLocale, $this->locales)) {
if (!in_array($this->defaultLocale, $this->locales, true)) {
throw new \UnexpectedValueException(sprintf('The default locale ("%s") must be one of "%s".', $this->defaultLocale, $locales));
}

Expand All @@ -84,7 +84,7 @@ public function onKernelRequest(GetResponseEvent $event)
}
// Ignore requests from referrers with the same HTTP host in order to prevent
// changing language for users who possibly already selected it for this application.
if (0 === stripos($request->headers->get('referer'), $request->getSchemeAndHttpHost())) {
if (0 === mb_stripos($request->headers->get('referer'), $request->getSchemeAndHttpHost())) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Security/PostVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PostVoter extends Voter
protected function supports($attribute, $subject)
{
// this voter is only executed for three specific permissions on Post objects
return $subject instanceof Post && in_array($attribute, [self::SHOW, self::EDIT, self::DELETE]);
return $subject instanceof Post && in_array($attribute, [self::SHOW, self::EDIT, self::DELETE], true);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/CodeExplorerBundle/Twig/SourceCodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ private function unindentCode($code)
$codeLines = explode("\n", $code);

$indentedLines = array_filter($codeLines, function ($lineOfCode) {
return '' === $lineOfCode || ' ' === substr($lineOfCode, 0, 4);
return '' === $lineOfCode || ' ' === mb_substr($lineOfCode, 0, 4);
});

if (count($indentedLines) === count($codeLines)) {
$formattedCode = array_map(function ($lineOfCode) {
return substr($lineOfCode, 4);
return mb_substr($lineOfCode, 4);
}, $codeLines);
$formattedCode = implode("\n", $formattedCode);
}
Expand Down
2 changes: 1 addition & 1 deletion web/app_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1'], true) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
Expand Down