@Override public void visitToken(SyntaxToken token) { if (token.is(Kind.INLINE_HTML_TOKEN)) { inlineHTMLCounter++; isOnlyClosingTag = CheckUtils.isClosingTag(token); lastInlineHTMLToken = token; } }
public static int getNumberOfLine(AstNode functionNode) { if (CheckUtils.isAbstractMethod(functionNode)) { return 0; } AstNode functionBlock = getFunctionBlock(functionNode); int firstLine = functionBlock.getFirstChild(PHPPunctuator.LCURLYBRACE).getTokenLine(); int lastLine = functionBlock.getFirstChild(PHPPunctuator.RCURLYBRACE).getTokenLine(); return lastLine - firstLine + 1; }
@Override public void visitNode(Tree tree) { FunctionTree declaration = (FunctionTree) tree; int nbLines = getNumberOfLines(declaration); if (nbLines > max) { context() .newIssue( this, String.format(MESSAGE, CheckUtils.getFunctionName(declaration), nbLines, max)) .tree(declaration); } }
private void checkAssignment(AstNode astNode) { AstNode memberExpr = astNode.getFirstChild(); AstNode variable = memberExpr.getFirstChild(); if (memberExpr.getNumberOfChildren() == 1 && variable.is(PHPGrammar.VARIABLE_WITHOUT_OBJECTS)) { String varName = variable.getTokenOriginalValue(); if (memberExpr.getTokens().size() == 1 && !CheckUtils.isSuperGlobal(varName) && !globalVariableNames.contains(varName)) { getContext().createLineViolation(this, "Move this variable into a class.", astNode); globalVariableNames.add(varName); } } }
@Override public void visitNode(AstNode astNode) { int nbLines = getNumberOfLine(astNode); if (nbLines > max) { getContext() .createLineViolation( this, "This function {0} has {1} lines, which is greater than the {2} lines authorized. Split it into smaller functions.", astNode, CheckUtils.getFunctionName(astNode), nbLines, max); } }