Skip to content

Commit

Permalink
pkp/pkp-lib#5678 Add PHP-CS formatter and pre-commit hook to format c…
Browse files Browse the repository at this point in the history
…ommitted changes
  • Loading branch information
NateWr committed Apr 20, 2021
1 parent 4b7a0cd commit a8ed772
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,6 +8,7 @@ temp
.buildpath
.settings
.DS_Store
.php_cs.cache
node_modules
js/build.js
js/hot-updates
Expand Down
50 changes: 50 additions & 0 deletions .php_cs
@@ -0,0 +1,50 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

// Apply formatting to all plugins that are not git submodules
$pluginsDir = __DIR__ . DIRECTORY_SEPARATOR . 'plugins';
$files = scandir($pluginsDir);
foreach ($files as $file) {
$categoryDir = $pluginsDir . DIRECTORY_SEPARATOR . $file;
if (!in_array($file, ['.', '..']) && is_dir($categoryDir)) {
$pluginDirs = scandir($categoryDir);
foreach ($pluginDirs as $pluginDir) {
$fullPluginPath = join(DIRECTORY_SEPARATOR, [$categoryDir, $pluginDir]);
$gitPath = join(DIRECTORY_SEPARATOR, [$fullPluginPath, '.git']);
if (!in_array($pluginDir, ['.', '..']) && is_dir($fullPluginPath) && !file_exists($gitPath)) {
$finder->in($fullPluginPath);
}
}
}
}

$finder->exclude([
'cache',
'cypress',
'dbscripts',
'docs',
'js',
'lib/pkp',
'lib/ui-library',
'locale',
'node_modules',
'public',
'plugins',
'registry',
'schemas',
'styles',
'templates',
])
->name('*.php')
->name('_ide_helper')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

$rules = include './lib/pkp/.php_cs_rules';

$config = new PhpCsFixer\Config();
return $config->setRules($rules)
->setFinder($finder);

0 comments on commit a8ed772

Please sign in to comment.