Insphpect

This tool is currently proof-of-concept. Your feedback and evaluation is valuable in helping to improve it and ensure its reports are meaninful.

Please click here to complete a short survey to tell us what you think. It should take less than 5 minutes and help further this research project!

Transphporm\TSSValidator

Detected issues

Issue Method Line number

Code

Click highlighted lines for details

<?php/* @description     Transformation Style Sheets - Revolutionising PHP templating    * * @author          Tom Butler tom@r.je                                             * * @copyright       2017 Tom Butler <tom@r.je> | https://r.je/                      * * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License * * @version         1.2                                                             */namespace Transphporm;use Transphporm\Parser\Tokenizer;class TSSValidator {    private $error;    public function validate($tss) {        $this->error = null;        $tokens = $this->tokenize($tss);        foreach ($tokens as $token)            if (!$this->validateRule($token)) return false;        return true;    }    private function validateRule($token) {        if ($token['type'] !== Tokenizer::OPEN_BRACE) return true;        return $this->checkBraces($token) && $this->checkSemicolons($token)            && $this->checkParenthesis($token);    }    private function checkBraces($token) {        return strpos($token['string'], '{') === false;    }    private function checkSemicolons($braceToken) {        $splitTokens = $braceToken['value']->splitOnToken(Tokenizer::COLON);        array_shift($splitTokens); array_pop($splitTokens);        foreach ($splitTokens as $tokens)            if (!in_array(Tokenizer::SEMI_COLON, array_column(iterator_to_array($tokens), 'type'))) return false;        return true;    }    private function checkParenthesis($token) {        return substr_count($token['string'], '(') === substr_count($token['string'], ')');    }    private function tokenize($tss) {        if (is_file($tss)) $tss = file_get_contents($tss);        return (new Parser\Tokenizer($tss))->getTokens();    }}