Skip to content

Commit

Permalink
Bug/9/globbing (#11)
Browse files Browse the repository at this point in the history
* WIP TASK: Refactor getfile method to be able to get files from directories

* TASK: Refactor getFiles method to work correctly\n\ncloses #9

* TASK: Adjust readme
  • Loading branch information
mstruebing authored Feb 1, 2017
1 parent cae04cf commit 33cc357
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ Then you could create a script in your `composer.json` like this:

```json
"scripts": {
"check-editorconfig": "editorconfig-checker src/**/.php"
"check-editorconfig": "editorconfig-checker src/*.php"
}
```

Or any other [glob](http://php.net/manual/en/function.glob.php) you want. You could also check single files.
Attention!: You could not use shell-like globbing like `src/**/*.php` to find all files.
You have to explicitly specify the directory under which is searched for certain files.
So the above example would become to `src/*.php` to find all `.php` files in the src directory.

At the current state all files which are ending with a dot(.) or dotdot(..) are left out.

You could also check for single files with explicit call them e.g. `editorconfig-checker src/index.php`

If you installed it manually you would have to do something like this:

```
<PATH/TO/ROOT/OF/THIS/REPOS>/src/editorconfig-checker src/**/.php
<PATH/TO/ROOT/OF/THIS/REPOS>/src/editorconfig-checker src/*.php
```

The exit value is 0 if no error occurred and 1 to 254 - every error adds 1 to the exit value.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mstruebing/editorconfig-checker",
"description": "A tool to verify that your files follow the rules of your .editorconfig",
"license": "MIT",
"version": "1.1.2",
"version": "1.1.3",
"authors": [
{
"name": "Max Strübing",
Expand All @@ -21,9 +21,9 @@
},
"scripts": {
"post-install-cmd": "cd .git/hooks/ && ln -sf ../../Build/GitHooks/pre-commit .",
"lint": "composer run-script check-psr2 && composer run-script checkception",
"lint": "composer run-script check-psr2 && composer run-script self-check",
"check-psr2": "phpcs --standard=PSR2 src/MStruebing/**",
"checkception": "src/editorconfig-checker \"src/**/**/**/*.php\" \"src/**/**/*.php\""
"self-check": "src/editorconfig-checker src/*"
},
"bin": [
"src/editorconfig-checker"
Expand Down
30 changes: 23 additions & 7 deletions src/MStruebing/EditorconfigChecker/Cli/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public function run($argv)
protected function checkFiles($editorconfig, $files)
{
foreach ($files as $file) {
if (isset($file[0])) {
$rules = $this->getRulesForFiletype($editorconfig, $file[0]);
$this->processCheckForSingleFile($rules, $file[0]);
}
$rules = $this->getRulesForFiletype($editorconfig, $file);
$this->processCheckForSingleFile($rules, $file);
}
}

Expand Down Expand Up @@ -332,9 +330,27 @@ protected function getFiles($fileGlobs)
{
$files = array();
foreach ($fileGlobs as $fileGlob) {
$file = glob($fileGlob, GLOB_BRACE + GLOB_MARK);
if (substr($file[0], -1) !== '/') {
array_push($files, $file);
$dirPattern = pathinfo($fileGlob, PATHINFO_DIRNAME);
$fileType = pathinfo($fileGlob, PATHINFO_EXTENSION);

if (is_dir($dirPattern)) {
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirPattern));
foreach ($objects as $fileName => $object) {
/* currently all files which are ending with . or .. are left out */
if (substr($fileName, -1) !== '.' && substr($fileName, -2) !== '..') {
if ($fileType && $fileType === pathinfo($fileName, PATHINFO_EXTENSION)) {
/* if I not specify a file extension as argv I get files twice */
if (!in_array($fileName, $files)) {
array_push($files, $fileName);
}
} elseif (!strlen($fileType)) {
/* if I not specify a file extension as argv I get files twice */
if (!in_array($fileName, $files)) {
array_push($files, $fileName);
}
}
}
}
}
}

Expand Down

0 comments on commit 33cc357

Please sign in to comment.