HippoPHP\Hippo\Checks\Naming\EncodingCheck::checkFileInternal PHP Method

checkFileInternal() protected method

checkFileInternal(): defined by AbstractCheck.
See also: AbstractCheck::checkFileInternal()
protected checkFileInternal ( CheckContext $checkContext, Config $config )
$checkContext HippoPHP\Hippo\CheckContext
$config HippoPHP\Hippo\Config\Config
    protected function checkFileInternal(CheckContext $checkContext, Config $config)
    {
        $file = $checkContext->getFile();
        if (!function_exists('mb_detect_encoding')) {
            $this->addViolation($file, 0, 0, 'PHP MB extension is disabled. Cannot detect file encoding.', Violation::SEVERITY_WARNING);
            return;
        }
        $this->setEncodingType($config->get('encoding', $this->encoding));
        $this->setWithBOM($config->get('bom', $this->bom));
        $encoding = mb_detect_encoding($file->getSource(), $this->encoding, true);
        if ($encoding !== $this->encoding) {
            $this->addViolation($file, 0, 0, sprintf('File encoding should be %s. Currently using %s', $this->encoding, $encoding), Violation::SEVERITY_INFO);
            // Are we checking for BOM too?
            if ($this->bom) {
                if (false === strpos($file->getSource, self::BOM)) {
                    $this->addViolation($file, 0, 0, 'Files should be saved with BOM.', Violation::SEVERITY_INFO);
                }
            }
        }
    }