Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added staticCalls test file. Tests for static calls (using pattern ma…
…tching). Uses a whitelist; correct calls must be added manually. At the moment all calls have been marked correct except CHTTPRequest and CController. When finding an incorrect call you can use sed / awk to recursively fix the errors.
- Loading branch information
Showing
1 changed file
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
$dir = realpath(dirname(__FILE__) . "/.."); | ||
|
||
|
||
$dir = new RecursiveDirectoryIterator($dir); | ||
|
||
|
||
iterateList($dir); | ||
|
||
function ignore($entry) | ||
{ | ||
// Check if directory is ignored. | ||
if (substr($entry, -9, 9) == 'libraries') return true; | ||
} | ||
|
||
function iterateList(Iterator $i) | ||
{ | ||
foreach ($i as $entry) | ||
{ | ||
|
||
if ($i->hasChildren() && !ignore($entry)) | ||
{ | ||
iterateList($i->getChildren()); | ||
} | ||
else | ||
{ | ||
if (substr($entry, -4, 4) == '.php') | ||
{ | ||
checkFile($entry); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Get all static calls in file. | ||
function checkFile($filename) | ||
{ | ||
if ($filename == __FILE__) | ||
{ | ||
return; | ||
} | ||
$file = file($filename, FILE_IGNORE_NEW_LINES); | ||
$file = array_filter($file, "checkStatic"); | ||
|
||
if (!empty($file)) | ||
{ | ||
pr($filename); | ||
print_r($file); | ||
} | ||
} | ||
|
||
function checkStatic($line) | ||
{ | ||
$validStatics = array( | ||
'Yii::', | ||
'parent::', | ||
'LimeExpressionManager::', | ||
'Answers::', | ||
'Questions::', | ||
'Survey::', | ||
'Groups::', | ||
'self::', | ||
'PDO::', | ||
'Participants::', | ||
'Survey_links::', | ||
'Participant_attribute::', | ||
'Tokens::', | ||
'User_groups::', | ||
'Tokens_dynamic::', | ||
'Conditions::', | ||
'Survey_Common_Action::', | ||
'Quota::', | ||
'Survey_url_parameters::', | ||
'Survey_languagesettings::', | ||
'Survey_permissions::', | ||
'Saved_control::', | ||
'Quota_members::', | ||
'Quota_languagesettings::', | ||
'ParticipantAttributeNames::', | ||
'User::', | ||
'Surveys_languagesettings::', | ||
'Question_attributes::', | ||
'Assessment::', | ||
'CDbConnection::', | ||
'ParticipantShares::', | ||
'\'{INSERTANS::', | ||
'Defaultvalues::', | ||
'CHtml::', | ||
'ExpressionManager::', | ||
'\'::\'', | ||
'Labelsets::', | ||
'Survey_dynamic::', | ||
'PEAR::', | ||
'Settings_global::', | ||
'Zend_Http_Client::', | ||
'Zend_XmlRpc_Value::', | ||
'Templates_rights_model::', | ||
'Zend_XmlRpc_Server_Fault::', | ||
'Zend_XmlRpc_Value::', | ||
'Zend_Server_Cache::', | ||
'Zend_XmlRpc_Server_Cache::', | ||
'Label::', | ||
'Assessments::', | ||
'XMLReader::', | ||
'LEM::', | ||
'Question::', | ||
'DateTime::', | ||
'Installer::', | ||
'Sessions::', | ||
'dataentry::', | ||
'Assessments::', | ||
'Zend_Server_Reflection::', | ||
'Participants::', | ||
'jsonRPCServer::', | ||
'Failed_login_attempts::', | ||
'survey::', | ||
'tokens::', | ||
'questiongroup::', | ||
'printanswers::', | ||
'imagick::', | ||
':: ', | ||
'Assessments::', | ||
'InstallerConfigForm::', | ||
'Database::', | ||
'User_in_groups::', | ||
'Usergroups::', | ||
'Survey_timings::', | ||
'::regClass', | ||
'surveypermission::', | ||
'Template::', | ||
'templates::', | ||
'Templates_rights::', | ||
'register::', | ||
'::first', | ||
'::before', | ||
'::after', | ||
'::reg', | ||
'text::', | ||
'httpCache::' | ||
); | ||
$replacements = array_pad(array(), count($validStatics), ''); | ||
$line = str_replace($validStatics, $replacements, $line); | ||
|
||
return strpos($line, '::') !== false; | ||
|
||
} | ||
function pr($msg) | ||
{ | ||
echo $msg . "\n"; | ||
} | ||
?> |