PHP_CodeSniffer::shouldIgnoreFile PHP Method

shouldIgnoreFile() public method

Checks filtering rules to see if a file should be ignored.
public shouldIgnoreFile ( string $path, string $basedir ) : boolean
$path string The path to the file being checked.
$basedir string The directory to use for relative path checks.
return boolean
    public function shouldIgnoreFile($path, $basedir)
    {
        $relativePath = $path;
        if (strpos($path, $basedir) === 0) {
            // The +1 cuts off the directory separator as well.
            $relativePath = substr($path, strlen($basedir) + 1);
        }
        foreach ($this->ignorePatterns as $pattern => $type) {
            if (is_array($type) === true) {
                // A sniff specific ignore pattern.
                continue;
            }
            // Maintains backwards compatibility in case the ignore pattern does
            // not have a relative/absolute value.
            if (is_int($pattern) === true) {
                $pattern = $type;
                $type = 'absolute';
            }
            $replacements = array('\\,' => ',', '*' => '.*');
            // We assume a / directory separator, as do the exclude rules
            // most developers write, so we need a special case for any system
            // that is different.
            if (DIRECTORY_SEPARATOR === '\\') {
                $replacements['/'] = '\\\\';
            }
            $pattern = strtr($pattern, $replacements);
            if ($type === 'relative') {
                $testPath = $relativePath;
            } else {
                $testPath = $path;
            }
            $pattern = '`' . $pattern . '`i';
            if (preg_match($pattern, $testPath) === 1) {
                return true;
            }
        }
        //end foreach
        return false;
    }

Usage Example

Esempio n. 1
0
 /**
  * @param string $filename
  * @param string $extension
  * @param string $dir
  * @return bool
  */
 public function shouldIgnoreFile($filename, $extension, $dir)
 {
     return $this->phpcs->shouldIgnoreFile($filename, "./");
 }