Skip to content

Commit 6796ba3

Browse files
authored
Use symfony/finder
1 parent b737b79 commit 6796ba3

12 files changed

+387
-313
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ use MathiasReker\PhpChmod\Scanner;
5757

5858
require __DIR__ . '/vendor/autoload.php';
5959

60-
$result = (new Scanner())
60+
(new Scanner())
6161
->setDefaultFileMode(0644)
6262
->setDefaultDirectoryMode(0755)
6363
->setExcludedFileModes([0400, 0444, 0640])
6464
->setExcludedDirectoryModes([0750])
6565
->scan([__DIR__])
6666
->fix();
67-
68-
var_dump($result); // bool
6967
```
7068

7169
### Documentation
@@ -99,10 +97,22 @@ skipped:
9997
$result->setExcludedDirectoryModes([0750]);
10098
```
10199

102-
`setExcludedNames` excludes a list of file/directory names (not paths):
100+
`setExcludedNames` exclude files by a custom pattern. Glob and RegEx are supported:
101+
102+
```php
103+
$result->setExcludedNames(['*.rb', '*.py']);
104+
```
105+
106+
`setNames` includes files by a custom pattern and exclude any other files. Glob and RegEx are supported:
107+
108+
```php
109+
$result->setNames(['*.php']);
110+
```
111+
112+
`getExcludedPaths` excludes a list of file/directory paths:
103113

104114
```php
105-
$result->setExcludedNames(['.docker']);
115+
$result->getExcludedPaths(['first/dir', 'other/dir']);
106116
```
107117

108118
`scan` finds all the concerned files/directories:
@@ -123,7 +133,7 @@ $result->setConcernedPaths($paths);
123133
$result->dryRun();
124134
```
125135

126-
`fix` changes the concerned file/directory permissions to the default mode:
136+
`fix` changes the concerned file/directory permissions to the default permission:
127137

128138
```php
129139
$result->fix();

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
],
1818
"homepage": "https://github.com/mathiasreker/php-chmod",
1919
"require": {
20-
"php": ">=7.4.0",
21-
"ext-mbstring": "*"
20+
"php": ">=7.4",
21+
"ext-mbstring": "*",
22+
"symfony/finder": "^5.4"
2223
},
2324
"require-dev": {
2425
"ergebnis/composer-normalize": "^2.28",
@@ -33,7 +34,7 @@
3334
},
3435
"autoload-dev": {
3536
"psr-4": {
36-
"Tests\\": "tests/"
37+
"MathiasReker\\PhpChmod\\Tests\\": "tests/"
3738
}
3839
},
3940
"config": {

src/Model/Iterator.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Model/Scanner.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ final class Scanner
2323

2424
private ?int $defaultDirectoryModes = null;
2525

26+
private array $getExcludedPaths = [];
27+
2628
/**
2729
* @var int[]
2830
*/
@@ -43,6 +45,11 @@ final class Scanner
4345
*/
4446
private array $excludedNames = [];
4547

48+
/**
49+
* @var string[]
50+
*/
51+
private array $names = [];
52+
4653
public function setDefaultFileMode(int $defaultFileModes): self
4754
{
4855
if (!$this->isValidMode($defaultFileModes)) {
@@ -74,12 +81,23 @@ public function getExcludedFileModes(): array
7481
}
7582

7683
/**
77-
* @param int[] $excludedFileModes
84+
* @param string[] $getExcludedPaths
7885
*/
79-
public function setExcludedFileModes(array $excludedFileModes): self
86+
public function setExcludedPaths(array $getExcludedPaths): self
8087
{
81-
foreach ($excludedFileModes as $excludedModeFile) {
82-
if (!$this->isValidMode($excludedModeFile)) {
88+
$this->getExcludedPaths = $getExcludedPaths;
89+
90+
return $this;
91+
}
92+
93+
/**
94+
* @param int[] $excludedFileModes
95+
*/
96+
public function setExcludedFileModes(
97+
array $excludedFileModes
98+
): self {
99+
foreach ($excludedFileModes as $excludedFileMode) {
100+
if (!$this->isValidMode($excludedFileMode)) {
83101
throw new InvalidArgumentException(self::INVALID_PERMISSION);
84102
}
85103
}
@@ -140,6 +158,32 @@ public function getExcludedNames(): array
140158
return $this->excludedNames;
141159
}
142160

161+
/**
162+
* @return string[]
163+
*/
164+
public function getNames(): array
165+
{
166+
return $this->names;
167+
}
168+
169+
/**
170+
* @param string[] $names
171+
*/
172+
public function setNames(array $names): self
173+
{
174+
$this->names = $names;
175+
176+
return $this;
177+
}
178+
179+
/**
180+
* @return string[]
181+
*/
182+
public function getExcludedPaths(): array
183+
{
184+
return $this->getExcludedPaths;
185+
}
186+
143187
/**
144188
* @param string[] $excludedNames
145189
*/

src/Scanner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace MathiasReker\PhpChmod;
1212

13-
use MathiasReker\PhpChmod\Service\Impl\ScannerServiceImpl;
13+
use MathiasReker\PhpChmod\Service\ScannerService;
1414

15-
final class Scanner extends ScannerServiceImpl
15+
final class Scanner extends ScannerService
1616
{
1717
}

src/Service/Impl/IteratorServiceImpl.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)