Skip to content

Commit 23cf284

Browse files
committed
feature #561 Add more PHP CS Fixer rules (bocharsky-bw)
This PR was merged into the master branch. Discussion ---------- Add more PHP CS Fixer rules Commits ------- 5d7b7ae Add more PHP CS Fixer rules
2 parents 801279d + 5d7b7ae commit 23cf284

File tree

10 files changed

+20
-14
lines changed

10 files changed

+20
-14
lines changed

.php_cs.dist

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ return PhpCsFixer\Config::create()
2626
'@Symfony:risky' => true,
2727
'array_syntax' => ['syntax' => 'short'],
2828
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
29+
'linebreak_after_opening_tag' => true,
30+
'mb_str_functions' => true,
31+
'no_php4_constructor' => true,
32+
'no_unreachable_default_argument_value' => true,
2933
'no_useless_else' => true,
3034
'no_useless_return' => true,
3135
'ordered_imports' => true,
32-
'phpdoc_order' => true,
3336
'php_unit_strict' => true,
37+
'phpdoc_order' => true,
38+
'semicolon_after_instruction' => true,
3439
'strict_comparison' => true,
40+
'strict_param' => true,
3541
])
3642
->setFinder($finder)
3743
->setCacheFile(__DIR__.'/var/.php_cs.cache')

app/AppKernel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function registerBundles()
3838
// the unit and functional tests. Therefore, they are only registered
3939
// when the application runs in 'dev' or 'test' environments. This allows
4040
// to increase application performance in the production environment.
41-
if (in_array($this->getEnvironment(), ['dev', 'test'])) {
41+
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
4242
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
4343
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
4444
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

src/AppBundle/Command/AddUserCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
151151
$password = $console->ask($input, $output, $question);
152152
$input->setArgument('password', $password);
153153
} else {
154-
$output->writeln(' > <info>Password</info>: '.str_repeat('*', strlen($password)));
154+
$output->writeln(' > <info>Password</info>: '.str_repeat('*', mb_strlen($password)));
155155
}
156156

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

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

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

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

src/AppBundle/DataFixtures/FixturesTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function getRandomPostSummary($maxLength = 255)
127127
shuffle($phrases);
128128
$phrases = array_slice($phrases, 0, $numPhrases - 1);
129129

130-
while (strlen($summary = implode('. ', $phrases).'.') > $maxLength) {
130+
while (mb_strlen($summary = implode('. ', $phrases).'.') > $maxLength) {
131131
array_pop($phrases);
132132
}
133133

src/AppBundle/Entity/Comment.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct()
8686
*/
8787
public function isLegitComment()
8888
{
89-
$containsInvalidCharacters = false !== strpos($this->content, '@');
89+
$containsInvalidCharacters = false !== mb_strpos($this->content, '@');
9090

9191
return !$containsInvalidCharacters;
9292
}

src/AppBundle/EventListener/CheckRequirementsSubscriber.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function handleConsoleException(ConsoleExceptionEvent $event)
6767
{
6868
$commandNames = ['doctrine:fixtures:load', 'doctrine:database:create', 'doctrine:schema:create', 'doctrine:database:drop'];
6969

70-
if (in_array($event->getCommand()->getName(), $commandNames)) {
70+
if (in_array($event->getCommand()->getName(), $commandNames, true)) {
7171
if ($this->isSQLitePlatform() && !extension_loaded('sqlite3')) {
7272
$io = new SymfonyStyle($event->getInput(), $event->getOutput());
7373
$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.');

src/AppBundle/EventListener/RedirectToPreferredLocaleListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator, $locales, $defa
6060

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

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

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

src/AppBundle/Security/PostVoter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PostVoter extends Voter
3838
protected function supports($attribute, $subject)
3939
{
4040
// this voter is only executed for three specific permissions on Post objects
41-
return $subject instanceof Post && in_array($attribute, [self::SHOW, self::EDIT, self::DELETE]);
41+
return $subject instanceof Post && in_array($attribute, [self::SHOW, self::EDIT, self::DELETE], true);
4242
}
4343

4444
/**

src/CodeExplorerBundle/Twig/SourceCodeExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ private function unindentCode($code)
126126
$codeLines = explode("\n", $code);
127127

128128
$indentedLines = array_filter($codeLines, function ($lineOfCode) {
129-
return '' === $lineOfCode || ' ' === substr($lineOfCode, 0, 4);
129+
return '' === $lineOfCode || ' ' === mb_substr($lineOfCode, 0, 4);
130130
});
131131

132132
if (count($indentedLines) === count($codeLines)) {
133133
$formattedCode = array_map(function ($lineOfCode) {
134-
return substr($lineOfCode, 4);
134+
return mb_substr($lineOfCode, 4);
135135
}, $codeLines);
136136
$formattedCode = implode("\n", $formattedCode);
137137
}

web/app_dev.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// something more sophisticated.
2828
if (isset($_SERVER['HTTP_CLIENT_IP'])
2929
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
30-
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || PHP_SAPI === 'cli-server')
30+
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1'], true) || PHP_SAPI === 'cli-server')
3131
) {
3232
header('HTTP/1.0 403 Forbidden');
3333
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');

0 commit comments

Comments
 (0)