the business logic ◦ Tests should focus on this group • Bugs in code ◦ Can be caught by Static code analysis class Foo { } $shoppingCart->add(new Foo());
Code is parsed into an AST and analysed directly. • Allows us to reason about all possible executions of a program. ◦ Gives assurance that the code is correct.
Code is parsed into an AST and analysed directly. • Allows us to reason about all possible executions of a program. ◦ Gives assurance that the code is correct. • Performed by compiler in static languages.
Code is parsed into an AST and analysed directly. • Allows us to reason about all possible executions of a program. ◦ Gives assurance that the code is correct. • Performed by compiler in static languages. ◦ Dynamic languages are not that easy to analyse.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops. • Existence and visibility of called methods and functions.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops. • Existence and visibility of called methods and functions. • Existence and visibility of accessed properties and constants.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops. • Existence and visibility of called methods and functions. • Existence and visibility of accessed properties and constants. • Correct types assigned to properties.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops. • Existence and visibility of called methods and functions. • Existence and visibility of accessed properties and constants. • Correct types assigned to properties. • Correct number and types of parameters passed to constructors, methods and functions.
in instanceof, catch, type hints, other language constructs and even annotations. • Existence of variables while respecting scopes of branches and loops. • Existence and visibility of called methods and functions. • Existence and visibility of accessed properties and constants. • Correct types assigned to properties. • Correct number and types of parameters passed to constructors, methods and functions. • Correct types returned from methods and functions.
to sprintf/printf calls based on format strings. • Useless casts like (string) 'foo'. • Unused constructor parameters. • That only objects are passed to the clone keyword.
to sprintf/printf calls based on format strings. • Useless casts like (string) 'foo'. • Unused constructor parameters. • That only objects are passed to the clone keyword. • And much more...
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct()
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct() ◦ Check unused constructor parameters
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct() ◦ Check unused constructor parameters ◦ Check existence of functions and methods
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct() ◦ Check unused constructor parameters ◦ Check existence of functions and methods ◦ Check correct number of parameters passed to sprintf/printf functions
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct() ◦ Check unused constructor parameters ◦ Check existence of functions and methods ◦ Check correct number of parameters passed to sprintf/printf functions ◦ Check unused closure uses
Check access to properties ◦ Check access to class constants ◦ Check existence of classes ◦ Check correct number of parameters passed to methods and functions ◦ Check that constructors call parent::__construct() ◦ Check unused constructor parameters ◦ Check existence of functions and methods ◦ Check correct number of parameters passed to sprintf/printf functions ◦ Check unused closure uses ◦ Check using $this outside a class or in a static method
Check types of items in typed arrays ◦ Check types assigned to properties (including defaults) ◦ Check return types from methods and functions (including anonymous ones) ◦ Check that only objects are passed into the clone keyword
Check passed function/methods argument types (only argument count is checked on lower levels) ◦ Check whether an argument for parameter passed by reference is a variable
Check passed function/methods argument types (only argument count is checked on lower levels) ◦ Check whether an argument for parameter passed by reference is a variable ◦ Check whether an argument passed to count() is an array or Countable
= []; public function __get($name) { return $this->data($name) ?? null; } public function __set($name, $value) { $this->data[$name] = $value; } } (new Foo())->bar = 1;