How to test if a variable is been sanitized?
Your answer is already in the comments by @Geoff and @Clive above. If there was a way to unambiguously detect sanitation status of variables in PHP then the Coder module (and probably some IDE:s) would have incorporated it already.

But in some (not all) instances you can name your variables according to their sanitation status, to make it easier to keep track of which variables are sanitised and which are not.

&lt;?php
  $myVar_raw = some_source();
  $myVar_safe = check_plain($myVar_raw);
  unset($myVar_raw); // Optional, to make sure raw variable is not used again later
?&gt;