PHPSA\Context::notice PHP Méthode

notice() public méthode

Creates a notice message.
public notice ( string $type, string $message, NodeAbstract $expr, integer $status = Check::CHECK_SAFE ) : boolean
$type string
$message string
$expr PhpParser\NodeAbstract
$status integer
Résultat boolean
    public function notice($type, $message, \PhpParser\NodeAbstract $expr, $status = Check::CHECK_SAFE)
    {
        $analyzerConfig = $this->application->getConfiguration()->getValue('analyzers');
        if ($type == "language_error" && !$analyzerConfig['language_error']['enabled']) {
            return true;
        }
        $filepath = $this->filepath;
        $code = file($filepath);
        $this->output->writeln('<comment>Notice:  ' . $message . " in {$filepath} on {$expr->getLine()} [{$type}]</comment>");
        $this->output->writeln('');
        if ($this->application->getConfiguration()->valueIsTrue('blame')) {
            exec("git blame --show-email -L {$expr->getLine()},{$expr->getLine()} " . $filepath, $result);
            if ($result && isset($result[0])) {
                $result[0] = trim($result[0]);
                $this->output->writeln("<comment>\t {$result[0]}</comment>");
            }
        } else {
            $code = trim($code[$expr->getLine() - 1]);
            $this->output->writeln("<comment>\t {$code} </comment>");
        }
        $this->output->writeln('');
        $issueCollector = $this->application->getIssuesCollector();
        $issueCollector->addIssue(new Issue($type, $message, new IssueLocation($this->filepath, $expr->getLine() - 1)));
        return true;
    }

Usage Example

Exemple #1
0
 /**
  * @param \PhpParser\Node\Expr\BinaryOp\Concat $expr
  * @param Context $context
  * @return CompiledExpression
  */
 protected function compile($expr, Context $context)
 {
     $compiler = new Expression($context);
     $leftExpression = $compiler->compile($expr->left);
     $rightExpression = $compiler->compile($expr->right);
     switch ($leftExpression->getType()) {
         case CompiledExpression::ARR:
             $context->notice('unsupported-operand-types', 'Unsupported operand types -{array}', $expr);
             break;
     }
     switch ($rightExpression->getType()) {
         case CompiledExpression::ARR:
             $context->notice('unsupported-operand-types', 'Unsupported operand types -{array}', $expr);
             break;
     }
     switch ($leftExpression->getType()) {
         case CompiledExpression::STRING:
         case CompiledExpression::NUMBER:
         case CompiledExpression::INTEGER:
         case CompiledExpression::DOUBLE:
             switch ($rightExpression->getType()) {
                 case CompiledExpression::STRING:
                 case CompiledExpression::NUMBER:
                 case CompiledExpression::INTEGER:
                 case CompiledExpression::DOUBLE:
                     return new CompiledExpression(CompiledExpression::STRING, $leftExpression->getValue() . $rightExpression->getValue());
                     break;
             }
             break;
     }
     return new CompiledExpression(CompiledExpression::NULL);
 }
All Usage Examples Of PHPSA\Context::notice