Skip to content

Commit

Permalink
Rename "whitelisted files" to "excluded files" (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Jan 30, 2022
1 parent 371c66d commit 7106c5e
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
- [Prefix](docs/configuration.md#prefix)
- [Finders and paths](docs/configuration.md#finders-and-paths)
- [Patchers](docs/configuration.md#patchers)
- [Whitelisted files](docs/configuration.md#whitelisted-files)
- [Excluded files](docs/configuration.md#excluded-files)
- [Excluded Symbols](docs/configuration.md#excluded-symbols)
- [Exposed Symbols](docs/configuration.md#exposed-symbols)
- [Exposing classes](docs/configuration.md#exposing-classes)
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [Prefix](#prefix)
- [Finders and paths](#finders-and-paths)
- [Patchers](#patchers)
- [Whitelisted files](#whitelisted-files)
- [Excluded files](#excluded-files)
- [Excluded Symbols](#excluded-symbols)
- [Exposed Symbols](#exposed-symbols)
- [Exposing classes](#exposing-classes)
Expand Down Expand Up @@ -169,7 +169,7 @@ return [
```


### Whitelisted files
### Excluded files

For the files listed in `files-whitelist`, their content will be left
untouched during the scoping process.
Expand Down
2 changes: 1 addition & 1 deletion fixtures/set020-infection/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
);

return [
'files-whitelist' => [
'exclude-files' => [
...$polyfillsBootstraps,
...$polyfillsStubs,
],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/set021-composer2/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'whitelist' => [
'Symfony\\Polyfill\\*',
],
'files-whitelist' => [
'exclude-files' => [
...$polyfillsBootstraps,
...$polyfillsStubs,
],
Expand Down
2 changes: 1 addition & 1 deletion scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
Finder::class,
'Symfony\\Polyfill\\*',
],
'files-whitelist' => [
'exclude-files' => [
...$jetBrainStubs,
...$polyfillsBootstraps,
...$polyfillsStubs,
Expand Down
18 changes: 9 additions & 9 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ final class Configuration
private ?string $path;
private string $prefix;
private array $filesWithContents;
private array $whitelistedFilesWithContents;
private array $excludedFilesWithContents;
private Patcher $patcher;
private SymbolsConfiguration $symbolsConfiguration;

/**
* @param string|null $path Absolute path to the configuration file loaded.
* @param string $prefix The prefix applied.
* @param array<string, array{string, string}> $filesWithContents Array of tuple with the
* @param string|null $path Absolute path to the configuration file loaded.
* @param string $prefix The prefix applied.
* @param array<string, array{string, string}> $filesWithContents Array of tuple with the
* first argument being the file path and the second
* its contents
* @param array<string, array{string, string}> $whitelistedFilesWithContents Array of tuple
* @param array<string, array{string, string}> $excludedFilesWithContents Array of tuple
* with the first argument being the file path and
* the second its contents
* @param SymbolsConfiguration $symbolsConfiguration
Expand All @@ -45,7 +45,7 @@ public function __construct(
?string $path,
string $prefix,
array $filesWithContents,
array $whitelistedFilesWithContents,
array $excludedFilesWithContents,
Patcher $patcher,
SymbolsConfiguration $symbolsConfiguration
) {
Expand All @@ -56,7 +56,7 @@ public function __construct(
$this->filesWithContents = $filesWithContents;
$this->patcher = $patcher;
$this->symbolsConfiguration = $symbolsConfiguration;
$this->whitelistedFilesWithContents = $whitelistedFilesWithContents;
$this->excludedFilesWithContents = $excludedFilesWithContents;
}

public function getPath(): ?string
Expand Down Expand Up @@ -90,9 +90,9 @@ public function getSymbolsConfiguration(): SymbolsConfiguration
/**
* @return array<string, array{string, string}>
*/
public function getWhitelistedFilesWithContents(): array
public function getExcludedFilesWithContents(): array
{
return $this->whitelistedFilesWithContents;
return $this->excludedFilesWithContents;
}

private static function validatePrefix(string $prefix): void
Expand Down
30 changes: 15 additions & 15 deletions src/Configuration/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function create(?string $path = null, array $paths = []): Configuration

$prefix = self::retrievePrefix($config);

$whitelistedFiles = null === $path
$excludedFiles = null === $path
? []
: $this->retrieveWhitelistedFiles(
: $this->retrieveExcludedFiles(
dirname($path),
$config,
);
Expand All @@ -104,7 +104,7 @@ public function create(?string $path = null, array $paths = []): Configuration
$path,
$prefix,
$filesWithContents,
self::retrieveFilesWithContents($whitelistedFiles),
self::retrieveFilesWithContents($excludedFiles),
new PatcherChain($patchers),
$symbolsConfiguration,
);
Expand All @@ -130,7 +130,7 @@ public function createWithPaths(Configuration $config, array $paths): Configurat
$config->getFilesWithContents(),
$filesWithContents,
),
$config->getWhitelistedFilesWithContents(),
$config->getExcludedFilesWithContents(),
$config->getPatcher(),
$config->getSymbolsConfiguration(),
);
Expand All @@ -144,7 +144,7 @@ public function createWithPrefix(Configuration $config, string $prefix): Configu
$config->getPath(),
$prefix,
$config->getFilesWithContents(),
$config->getWhitelistedFilesWithContents(),
$config->getExcludedFilesWithContents(),
$config->getPatcher(),
$config->getSymbolsConfiguration(),
);
Expand Down Expand Up @@ -269,28 +269,28 @@ private static function retrievePatchers(array $config): array
/**
* @return string[] Absolute paths
*/
private function retrieveWhitelistedFiles(string $dirPath, array $config): array
private function retrieveExcludedFiles(string $dirPath, array $config): array
{
if (!array_key_exists(ConfigurationKeys::WHITELISTED_FILES_KEYWORD, $config)) {
if (!array_key_exists(ConfigurationKeys::EXCLUDED_FILES_KEYWORD, $config)) {
return [];
}

$whitelistedFiles = $config[ConfigurationKeys::WHITELISTED_FILES_KEYWORD];
$excludedFiles = $config[ConfigurationKeys::EXCLUDED_FILES_KEYWORD];

if (!is_array($whitelistedFiles)) {
if (!is_array($excludedFiles)) {
throw new InvalidArgumentException(
sprintf(
'Expected whitelisted files to be an array of strings, found "%s" instead.',
gettype($whitelistedFiles),
'Expected excluded files to be an array of strings, found "%s" instead.',
gettype($excludedFiles),
),
);
}

foreach ($whitelistedFiles as $index => $file) {
foreach ($excludedFiles as $index => $file) {
if (!is_string($file)) {
throw new InvalidArgumentException(
sprintf(
'Expected whitelisted files to be an array of string, the "%d" element is not.',
'Expected excluded files to be an array of string, the "%d" element is not.',
$index,
),
);
Expand All @@ -300,10 +300,10 @@ private function retrieveWhitelistedFiles(string $dirPath, array $config): array
$file = $dirPath.DIRECTORY_SEPARATOR.$file;
}

$whitelistedFiles[$index] = realpath($file);
$excludedFiles[$index] = realpath($file);
}

return array_filter($whitelistedFiles);
return array_filter($excludedFiles);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/ConfigurationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
final class ConfigurationKeys
{
public const PREFIX_KEYWORD = 'prefix';
public const WHITELISTED_FILES_KEYWORD = 'files-whitelist';
public const EXCLUDED_FILES_KEYWORD = 'exclude-files';
public const FINDER_KEYWORD = 'finders';
public const PATCHERS_KEYWORD = 'patchers';
public const WHITELIST_KEYWORD = 'whitelist';
Expand All @@ -29,7 +29,7 @@ final class ConfigurationKeys

public const KEYWORDS = [
self::PREFIX_KEYWORD,
self::WHITELISTED_FILES_KEYWORD,
self::EXCLUDED_FILES_KEYWORD,
self::FINDER_KEYWORD,
self::PATCHERS_KEYWORD,
self::WHITELIST_KEYWORD,
Expand Down
6 changes: 3 additions & 3 deletions src/Console/ConsoleScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ private function scopeFiles(
private static function getFiles(Configuration $config, string $outputDir): array
{
$filesWithContent = $config->getFilesWithContents();
$whitelistedFilesWithContent = $config->getWhitelistedFilesWithContents();
$excludedFilesWithContents = $config->getExcludedFilesWithContents();

$commonPath = get_common_path(
[
...array_keys($filesWithContent),
...array_keys($whitelistedFilesWithContent),
...array_keys($excludedFilesWithContents),
],
);

Expand All @@ -165,7 +165,7 @@ private static function getFiles(Configuration $config, string $outputDir): arra
),
array_map(
$mapFiles,
$whitelistedFilesWithContent,
$excludedFilesWithContents,
),
];
}
Expand Down
7 changes: 4 additions & 3 deletions src/scoper.inc.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ return [
]),
],

// Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving
// a file untouched.
// List of excluded files, i.e. files for which the content will be left untouched.
// Paths are relative to the configuration file unless if they are already absolute
'files-whitelist' => [
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#patchers
'exclude-files' => [
'src/a-whitelisted-file.php',
],

Expand Down
6 changes: 3 additions & 3 deletions tests/Configuration/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function test_it_can_be_created_without_a_file(): void
{
$configuration = $this->configFactory->create();

self::assertSame([], $configuration->getWhitelistedFilesWithContents());
self::assertSame([], $configuration->getExcludedFilesWithContents());
self::assertEquals(
SymbolsConfiguration::create(),
$configuration->getSymbolsConfiguration(),
Expand Down Expand Up @@ -88,7 +88,7 @@ public function test_it_can_create_a_complete_configuration(): void
return [
'prefix' => 'MyPrefix',
'files-whitelist' => ['file1', 'file2'],
'exclude-files' => ['file1', 'file2'],
'patchers' => [],
'finders' => [],
Expand Down Expand Up @@ -131,7 +131,7 @@ public function test_it_can_create_a_complete_configuration(): void
'',
],
],
$configuration->getWhitelistedFilesWithContents(),
$configuration->getExcludedFilesWithContents(),
);
self::assertEquals(
new PatcherChain([
Expand Down
2 changes: 1 addition & 1 deletion vendor-hotfix/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,7 @@ static function (string $path) use ($basePath): string {
return make_path_relative($path, $basePath);
},
array_keys(
$phpScoperConfig->getWhitelistedFilesWithContents(),
$phpScoperConfig->getExcludedFilesWithContents(),
),
)
)
Expand Down
2 changes: 1 addition & 1 deletion vendor-hotfix/SimpleScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
$scoperConfig->getPath(),
$scoperConfig->getPrefix(),
$scoperConfig->getFilesWithContents(),
$scoperConfig->getWhitelistedFilesWithContents(),
$scoperConfig->getExcludedFilesWithContents(),
self::createSerializablePatchers($scoperConfig->getPatcher()),
$scoperConfig->getSymbolsConfiguration(),
);
Expand Down

0 comments on commit 7106c5e

Please sign in to comment.