8000 Merge remote branch 'brikou/check_cs' · 77web/symfony@391d952 · GitHub
[go: up one dir, main page]

Skip to content

Commit 391d952

Browse files
committed
Merge remote branch 'brikou/check_cs'
* brikou/check_cs: fixed shebash declaration fixed chmod added a script to clean up the code and follow CS
2 parents 0af4743 + 2d52bf9 commit 391d952

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

check_cs.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/*
4+
* Coding Standards (a.k.a. CS)
5+
*
6+
* This script is designed to clean up the source files and thus follow coding
7+
* conventions.
8+
*
9+
* @see http://symfony.com/doc/2.0/contributing/code/standards.html
10+
*
11+
*/
12+
13+
require_once __DIR__.'/autoload.php.dist';
14+
15+
use Symfony\Component\Finder\Finder;
16+
17+
$finder = new Finder();
18+
$finder
19+
->files()
20+
->name('*.md')
21+
->name('*.php')
22+
->name('*.php.dist')
23+
->name('*.twig')
24+
->name('*.xml')
25+
->name('*.xml.dist')
26+
->name('*.yml')
27+
->in(__DIR__)
28+
->notName(basename(__FILE__))
29+
->exclude('.git')
30+
->exclude('vendor')
31+
;
32+
33+
foreach ($finder as $file) { /* @var $file Symfony\Component\Finder\SplFileInfo */
34+
35+
// These files are skipped because tests would break
36+
if (in_array($file->getRelativePathname(), array(
37+
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
38+
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php',
39+
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/includes/foo.php',
40+
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php',
41< 8000 /code>+
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml',
42+
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php',
43+
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php',
44+
'tests/Symfony/Tests/Component/Yaml/Fixtures/sfTests.yml',
45+
))) {
46+
continue;
47+
}
48+
49+
$old = file_get_contents($file->getRealpath());
50+
51+
$new = $old;
52+
53+
// [Structure] Never use short tags (<?);
54+
$new = str_replace('<? ', '<?php ', $new);
55+
56+
// [Structure] Indentation is done by steps of four spaces (tabs are never allowed);
57+
$new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) {
58+
return $matches[1] . str_repeat(' ', strlen($matches[2]));
59+
}, $new);
60+
61+
// [Structure] Use the linefeed character (0x0A) to end lines;
62+
$new = str_replace("\r\n", "\n", $new);
63+
64+
// [Structure] Don't add trailing spaces at the end of lines;
65+
$new = preg_replace('/[ \t]*$/m', '', $new);
66+
67+
// [Structure] Add a blank line before return statements;
68+
$new = preg_replace('/([^ {|\n]$)(\n return .+?$\n \}$)/m', '$1'."\n".'$2', $new);
69+
70+
if ($new != $old) {
71+
file_put_contents($file->getRealpath(), $new);
72+
echo $file->getRelativePathname() . PHP_EOL;
73+
}
74+
}

0 commit comments

Comments
 (0)
0