Dear Lazyweb,
the `Controler' part of my main codebase consists of interwoven PHP and MySQL. Is there static analysis tool that understands both, one in relation to the other?
the `Controler' part of my main codebase consists of interwoven PHP and MySQL. Is there static analysis tool that understands both, one in relation to the other?
public Statement ageFilter(int minimalAge) throws SQLException {
Connection conn = getConnection();
String sql = "SELECT name FROM people WHERE nmae IS NOT NULL";
if (minimalAge > 0)
sql += "AND (age >= " + minimalAge + ")";
return conn.prepareStatement(sql);
}
There are a lot of really interesting challenges in doing this. Their tool uses a powerful technique called "abstract parsing" which can analyze all possible parse trees created by running the SQL parser on a string produced by Java string operations. It's pretty impressive what modern static analysis can do, and just how weak the linters we've gotten used to are in comparison.I also find getting a good set of rules for phpcs is extremely helpful in PHP. You can use its sniffs to catch past mistakes and enforce consistent coding standards.
Imagine a tool that could analyze this:
//sql table T having columns int x, string y
//php
$data = sql_fetch_from_column(T)
//javascript
var d = <?=json_encode($data)?>
for(a in d)
var b = a.x / a.y; //Type error, int division by string not defined