Skip to content

Commit

Permalink
Added staticCalls test file. Tests for static calls (using pattern ma…
Browse files Browse the repository at this point in the history
…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
SamMousa committed Jul 23, 2012
1 parent e454acc commit 0b94332
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions application/tests/staticCalls.php
@@ -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";
}
?>

0 comments on commit 0b94332

Please sign in to comment.