function LocalFile::__construct
Creates a LocalFile object and sets the content.
Parameters
string $path The absolute path to the file.:
\PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.:
\PHP_CodeSniffer\Config $config The config data for the run.:
Return value
void
Overrides File::__construct
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Files/ LocalFile.php, line 30
Class
Namespace
PHP_CodeSniffer\FilesCode
public function __construct($path, Ruleset $ruleset, Config $config) {
$this->path = trim($path);
if (Common::isReadable($this->path) === false) {
parent::__construct($this->path, $ruleset, $config);
$error = 'Error opening file; file no longer exists or you do not have access to read the file';
$this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', [], 5, false);
$this->ignored = true;
return;
}
// Before we go and spend time tokenizing this file, just check
// to see if there is a tag up top to indicate that the whole
// file should be ignored. It must be on one of the first two lines.
if ($config->annotations === true) {
$handle = fopen($this->path, 'r');
if ($handle !== false) {
$firstContent = fgets($handle);
$firstContent .= fgets($handle);
fclose($handle);
if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false || stripos($firstContent, 'phpcs:ignorefile') !== false) {
// We are ignoring the whole file.
$this->ignored = true;
return;
}
}
}
$this->reloadContent();
parent::__construct($this->path, $ruleset, $config);
}