-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
definedIn?:string|list<string>
config option (#198)
To further specify/limit files where the function or method should be defined to be disallowed. Close #194
- Loading branch information
Showing
56 changed files
with
569 additions
and
105 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
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
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,50 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\File; | ||
|
||
use PHPStan\File\FileHelper; | ||
|
||
class FilePath | ||
{ | ||
|
||
/** @var FileHelper */ | ||
private $fileHelper; | ||
|
||
/** @var string|null */ | ||
private $rootDir; | ||
|
||
|
||
public function __construct(FileHelper $fileHelper, ?string $rootDir = null) | ||
{ | ||
$this->fileHelper = $fileHelper; | ||
$this->rootDir = $rootDir !== null ? $this->fileHelper->normalizePath($fileHelper->absolutizePath($rootDir)) : null; | ||
} | ||
|
||
|
||
public function fnMatch(string $path, string $file): bool | ||
{ | ||
return fnmatch($this->absolutizePath($path, $this->rootDir), $this->absolutizePath($file, null), FNM_NOESCAPE); | ||
} | ||
|
||
|
||
/** | ||
* Make path absolute unless it starts with a wildcard, then return as is. | ||
* | ||
* @param string $path | ||
* @param string|null $rootDir | ||
* @return string | ||
*/ | ||
private function absolutizePath(string $path, ?string $rootDir): string | ||
{ | ||
if (strpos($path, '*') === 0) { | ||
return $path; | ||
} | ||
|
||
if ($rootDir !== null) { | ||
$path = rtrim($rootDir, '/') . '/' . ltrim($path, '/'); | ||
} | ||
return $this->fileHelper->normalizePath($this->fileHelper->absolutizePath($path)); | ||
} | ||
|
||
} |
Oops, something went wrong.