Skip to content

Commit

Permalink
feature #561 Add more PHP CS Fixer rules (bocharsky-bw)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Add more PHP CS Fixer rules

Commits
-------

5d7b7ae Add more PHP CS Fixer rules
  • Loading branch information
javiereguiluz committed May 10, 2017
2 parents 801279d + 5d7b7ae commit 23cf284
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .php_cs.dist
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
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
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
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
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
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
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
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
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
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 === 'cli-server')
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1'], true) || PHP_SAPI === '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

0 comments on commit 23cf284

Please sign in to comment.