-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bleeding edge - no implicit wildcard in FileExcluder
- Loading branch information
1 parent
35a2f57
commit e19e6e5
Showing
13 changed files
with
261 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\DependencyInjection; | ||
|
||
use Exception; | ||
use function implode; | ||
|
||
class InvalidExcludePathsException extends Exception | ||
{ | ||
|
||
/** | ||
* @param string[] $errors | ||
*/ | ||
public function __construct(private array $errors) | ||
{ | ||
parent::__construct(implode("\n", $this->errors)); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getErrors(): array | ||
{ | ||
return $this->errors; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\DependencyInjection; | ||
|
||
use Nette\DI\CompilerExtension; | ||
use PHPStan\File\FileExcluder; | ||
use function array_key_exists; | ||
use function array_merge; | ||
use function array_unique; | ||
use function count; | ||
use function is_dir; | ||
use function is_file; | ||
use function sprintf; | ||
|
||
class ValidateExcludePathsExtension extends CompilerExtension | ||
{ | ||
|
||
/** | ||
* @throws InvalidExcludePathsException | ||
*/ | ||
public function loadConfiguration(): void | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
if (!$builder->parameters['__validate']) { | ||
return; | ||
} | ||
|
||
$excludePaths = $builder->parameters['excludePaths']; | ||
if ($excludePaths === null) { | ||
return; | ||
} | ||
|
||
$noImplicitWildcard = $builder->parameters['featureToggles']['noImplicitWildcard']; | ||
if (!$noImplicitWildcard) { | ||
return; | ||
} | ||
|
||
$paths = []; | ||
if (array_key_exists('analyse', $excludePaths)) { | ||
$paths = $excludePaths['analyse']; | ||
} | ||
if (array_key_exists('analyseAndScan', $excludePaths)) { | ||
$paths = array_merge($paths, $excludePaths['analyseAndScan']); | ||
} | ||
|
||
$errors = []; | ||
foreach (array_unique($paths) as $path) { | ||
if (is_dir($path)) { | ||
continue; | ||
} | ||
if (is_file($path)) { | ||
continue; | ||
} | ||
if (FileExcluder::isFnmatchPattern($path)) { | ||
continue; | ||
} | ||
|
||
$errors[] = sprintf('Path %s is neither a directory, nor a file path, nor a fnmatch pattern.', $path); | ||
} | ||
|
||
if (count($errors) === 0) { | ||
return; | ||
} | ||
|
||
throw new InvalidExcludePathsException($errors); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.