Checks a given file for modifications and triggers CSS generation

@param SplFileInfo $file A file
@param bool $force Whether to process file independently of any modifications
500949
protected function checkFile(SplFileInfo $file, $force) {
        $scssPath = $file->getPathname();
        $scssMod = $file->getMTime();
        $scssName = preg_replace('/^.+(\/|\\\\)([^\/\\\\]+)$/', '\\2', $scssPath);

        // don't compile `_`-prefixed system files
        if (substr($scssName, 0, 1) === '_') {
            $this->sysMod = max($this->sysMod, $scssMod);
            return;
        }

        $cssPath = preg_replace('/(\.|\/|\\\\)scss($|\/|\\\\)/', '\\1css\\2', $scssPath);
        $cssMod = is_file($cssPath) ? filemtime($cssPath) : 0;
        $this->oldestMod = min($this->oldestMod, $cssMod);

        $isModified = $scssMod - $cssMod > 0 ? true : false;

        if ($isModified || $force) {
            $this->generateCss($scssPath, $cssPath);
        }
        
        // Possibly imported mixin/sys file changed, update all CSS files
        if (!$force && $this->sysMod > $this->oldestMod) {
            $this->checkFiles(true);
            $this->oldestMod = $this->sysMod;
        }        
    }
178109
private function getConfigurationNesting(SplFileInfo $file)
	{
		$directory = dirname($file->getPathname());

		if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR))
		{
			$tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree).'.';
		}

		return $tree;
	}
1173529
private static function read($file, $force = false)
    {
        if($force === false && isset(self::$history[$file]))
        {
            return self::$history[$file];
        }

        $path = self::$configDirectory . $file . '.php';

        if(file_exists($path))
        {
            $contents = include $path;

            if(is_array($contents) || is_string($contents))
            {
                return self::$history[$file] = $contents;
            }

            return false;
        }

        return false;
    }
144596
protected function processLines(SplFileObject $file)
    {
        $extension = $file->getExtension();

        $totalLines = 0;
        $totalBlankLines = 0;
        $totalComments = 0;
        $isMultilines = false;
        while ($file->valid()) {
            $currentLine = $file->fgets();
            $trimLine = trim($currentLine);

            // Ignoring the last new line
            if ($file->eof() && empty($trimLine)) {
                break;
            }

            $totalLines ++;
            if (empty($trimLine)) {
                $totalBlankLines ++;
            }

            // Detecting comments
            if (strpos($trimLine, '//') === 0
                || strpos($trimLine, '#') === 0) {
                $totalComments ++;
            }

            // Detecting multilines comments
            if (strpos($trimLine, '/*') === 0) {
                $isMultilines = true;
            }
            if ($isMultilines) {
                $totalComments ++;
            }
            if (strpos($trimLine, '*/') === 0) {
                $isMultilines = false;
            }
        }

        if (!isset($this->extensions[$extension])) {
            return;
        }

        $this->setStats($extension, [
            'language' => $this->extensions[$extension],
            'files' => 1,
            'blank' => $totalBlankLines,
            'comment' => $totalComments,
            'code' => $totalLines - ($totalBlankLines + $totalComments),
        ]);
    }
594470
public function filter(\SplFileInfo $file)
    {
        $content = file_get_contents($file);
        $result = preg_match_all('/class\s+([^\s|\{]+)[\s\{]/im', $content, $results, PREG_PATTERN_ORDER);
        unset($content);

        if (!$result) {
            return false;
        }

        if (count($results[0]) > 1) {
            return false;
        }

        return true;
    }
795491
public final function resourceCheck(File $file) {
        if ($this->resourcePathMatch($file)) {
            if (is_null($this->getParentProject()->getResourceByFile($file)) && !is_null($resource = $this->resourceFactory($file))) {
                $this->getParentProject()->registerResource($resource);
            }
            return TRUE;
        } else {
            return FALSE;
        }
    }
763400
private function processFile(SplFileInfo $file, $replaceExisting, $dryRun)
    {
        if ($file->isDir()) {
            return;
        }

        $tokens = token_get_all($file->getContents());

        $licenseTokenIndex = $this->getLicenseTokenIndex($tokens);

        if (null !== $licenseTokenIndex && true === $replaceExisting) {
            $this->removeExistingLicense($file, $tokens, $licenseTokenIndex, $dryRun);
        }

        if (null === $licenseTokenIndex || true === $replaceExisting) {
            $this->log(sprintf('<fg=green>[+]</> Adding license header for <options=bold>%s</>', $file->getRealPath()));

            if (true === $dryRun) {
                return;
            }

            $license = $this->getLicenseAsComment();
            $content = preg_replace('/<\?php/', '<?php' . PHP_EOL . PHP_EOL . $license, $file->getContents(), 1);
            file_put_contents($file->getRealPath(), $content);
        } else {
            $this->log(sprintf('<fg=cyan>[S]</> Skipping <options=bold>%s</>', $file->getRealPath()));
        }
    }
1281821
public function filter(\SplFileInfo $file)
    {
        $fh = fopen($file->getPathName(), 'r');
        $content = fread($fh, $this->length);
        fclose($fh);

        return false !== strpos($content, $this->contains);
    }
1071868
protected function getFilePath(SplFileInfo $file)
	{
		$location = $file->getPathname();
		$path = $this->removePathPrefix($location);

		return \trim(\str_replace('\\', '/', $path), '/');
	}
1070192
private function convertResource(Resource $resource, \SplFileInfo $file)
    {
        return new Resource(
            array_merge(
                $resource->getMetadata(),
                [
                    'file' => $file->getRealpath(),
                ]
            ),
            $resource->getMetadata('type')
        );
    }
65006
private function checkFile(\SplFileInfo $fileInfo, string $annotation): void
    {
        $contents = (string)file_get_contents($fileInfo->getPathname());
        if ($this->isAnnotationInClassDocBlock($contents, $annotation) === true) {
            return;
        }

        $matches  = [];
        preg_match_all(
            <<<REGEXP
%(?<docblock>/\*(?:[^*]|\n|(?:\*(?:[^/]|\n)))*\*/|\n)\s+?public\s+?function\s+?(?<method>.+?)\(%
REGEXP
            . 'si',
            $contents,
            $matches
        );
        if ('' === $matches[0]) {
            $this->errors[$fileInfo->getFilename()][] = 'Failed finding any doc blocks';

            return;
        }
        foreach ($matches['method'] as $key => $method) {
            $docblock = $matches['docblock'][$key];
            /* Found the annotation - continue */
            if (false !== \strpos($docblock, '@' . $annotation)) {
                continue;
            }
            /* No @test annotation found & method not beginning test =  not a test, so continue */
            if (false === \strpos($docblock, '@test') && false === \strpos($method, 'test')) {
                continue;
            }
            $this->errors[$fileInfo->getFilename()][] =
                'Failed finding @' . $annotation . ' for method: ' . $method;
        }
    }
492624
protected function normalizeFileInfo(SplFileInfo $file)
    {
        if (! $file->isLink()) {
            $normalized = [
                'type'      => $file->getType(),
                'path'      => $this->getFilePath($file),
                'timestamp' => $file->getMTime()
            ];

            if ($normalized['type'] === 'file') {
                $normalized['size'] = $file->getSize();
            }

            return $normalized;
        }
    }
133985
public function create(\SplFileInfo $file)
    {
        $extension = $file->getExtension();
        switch ($extension) {
            case 'css':
                return new StylesheetDocument();
            case 'js':
                return new JavascriptDocument();
            default:
                if (strstr($this->getMimeType($file), 'image')) {
                    return new ImageDocument();
                }

                return new FileDocument();
        }
    }
881562
protected function getFileName(SplFileInfo $file = null)
    {
        $file = $file ?: $this->file;

        return str_replace(['.blade.php', '.php', '.md'], '', $file->getBasename());
    }
894850
function load(string $file = null)
    {
        if ($file == null) {
            $file = static::$configFile;
        }
        if (!file_exists($file)) {
            return false;
        }

        $a = json_decode(file_get_contents($file));

        if (isset($a->css)) {
            $this->css = $a->css;
        }

        if (isset($a->js)) {
            $this->js = $a->js;
        }
        
        if (isset($a->jss)) {
            $this->jss = $a->jss;
        }
        
        return true;
    }
65492
public function setCssFile($cssFile)
    {
        if (!$this->cssFileIsCached($cssFile)) {
            $absoluteFileName = GeneralUtility::getFileAbsFileName($cssFile);
            if (($cssFile !== '') && is_readable($absoluteFileName)
            ) {
                self::$cssFileCache[$cssFile] = file_get_contents($absoluteFileName);
            } else {
                self::$cssFileCache[$cssFile] = '';
            }
        }

        $this->setAsString('cssFile', self::$cssFileCache[$cssFile]);
    }
1095461
public function filter(\SplFileInfo $file)
    {
        if ($this->minsize !== null && $this->minsize > $file->getSize()) {
            return false;
        }
        if ($this->maxsize !== null && $this->maxsize < $file->getSize()) {
            return false;
        }

        return true;
    }