Code quality is not just for christmas, it is a daily part of the job. So, what do you do when you’re handed with a five feet long pole a million lines of code that must be vetted ? You call static analysis to the rescue. During one hour, we’ll be reviewing totally unknown code code : no name, no usage, not a clue. We’ll apply a wide range of tools, reaching for anything that helps us understand the code and form an opinion on it. Can we break this mystery and learn how everyone else is looking at our code ?
3. Review some PHP code
We don't know what it does
We have never heard about it
We don't run it
We don't know the authors
Can we have an opinion?
4. Review the code
Reading code is humanly possible : its an art
Unit test are not adapted for review
Dynamic analysis is not fit for review
We need to explore code
We can only rely on the current state
32. Various AST
PHP7mar : nikic/php5-ast
PHAN : ext/ast (PHP 7 only)
Exakat : AST in a graph database
SonarQube : Java-build AST
PHPstorm : internal IDE AST
Reflexion / Better Reflexion
33. PHAN
PhanTypeMismatchArgument Argument 2 (order) is false but EGroupwareApi
Hooks::process() takes array|string defined at
Total : 11999 results / 96 types
1679 issues
PhanTypeArraySuspiciousNullable Suspicious array access to nullable ?array|null
1256 issues
PhanUndeclaredClassMethod Call to method decode from undeclared class Horde_Mime
1247 issues
PhanUndeclaredProperty Reference to undeclared property calendar_bo->total
PhanTypeInvalidDimOffset Invalid offset "timeformat" of array type array{tz:mixed}
999 issues
668 issues
34. PHP 7 helps static analysis
Type hint, return type hint, scalar typehint
Usage of PHPDOC
Consistent behavior of PHP operators
Dynamic code is very difficult to analyze
35. PHP LINT
php -l <fichier.php>
Paralell executions
jakub-onderka/php-paralell-lint
Various versions of PHP : 7.0, 7.1, 7.2, 7.3, 5.6, 5.5
38. What does this app do?
Inventories of the application
Names for classes, methods, traits, variables,
interfaces…
List of literal in the code
Integers, real, arrays, strings