Example #1
0
 /**
  * @return array
  */
 public function analyze()
 {
     $options = $this->options;
     $i = $this->getPhpFilesIterator($options->getSubPath());
     $fixer = new CodeFixer();
     $this->instantReplacements = $fixer->getBasicFunctionRenames($this->maxVersion);
     $this->stats = array();
     $this->filesAnalyzed = 0;
     $functions = array();
     if ($options->isDeprecatedFunctionsTestEnabled()) {
         $functions = array_merge($functions, \code_review::getDeprecatedFunctionsList($options->getMaxVersion()));
     }
     if ($options->isPrivateFunctionsTestEnabled()) {
         $functions = array_merge($functions, \code_review::getPrivateFunctionsList());
     }
     foreach ($i as $filePath => $file) {
         if ($file instanceof \SplFileInfo) {
             $result = $this->processFile($filePath, $functions);
             $this->filesAnalyzed++;
             if (!empty($result['problems'])) {
                 $this->stats[$filePath] = $result;
             }
         }
     }
     return $this->stats;
 }
Example #2
0
 public function testGetBasicFunctionRenames()
 {
     $fixes = new CodeFixer();
     $renames = $fixes->getBasicFunctionRenames();
     $pattern = '/^[a-zA-Z_][\\sa-zA-Z_0-9\\(\\)\\->]*$/';
     foreach ($renames as $from => $to) {
         $this->assertNotEmpty($from);
         $this->assertNotEmpty($to);
         $this->assertRegExp($pattern, $from);
         $this->assertRegExp($pattern, $to);
     }
     /*
      * Check version filtering
      */
     // no results below 1.7
     $this->assertEmpty($fixes->getBasicFunctionRenames('1.6'));
     // version 1.7
     $renames = $fixes->getBasicFunctionRenames('1.7');
     $this->assertArrayHasKey('elgg_validate_action_url', $renames);
     $this->assertArrayNotHasKey('register_elgg_event_handler', $renames);
     $this->assertArrayNotHasKey('setup_db_connections', $renames);
     // version 1.8
     $renames = $fixes->getBasicFunctionRenames('1.8');
     $this->assertArrayHasKey('elgg_validate_action_url', $renames);
     $this->assertArrayHasKey('register_elgg_event_handler', $renames);
     $this->assertArrayNotHasKey('setup_db_connections', $renames);
     // version 1.9
     $renames = $fixes->getBasicFunctionRenames('1.9');
     $this->assertArrayHasKey('elgg_validate_action_url', $renames);
     $this->assertArrayHasKey('register_elgg_event_handler', $renames);
     $this->assertArrayHasKey('setup_db_connections', $renames);
     // all versions
     $renames = $fixes->getBasicFunctionRenames('');
     $this->assertArrayHasKey('elgg_validate_action_url', $renames);
     $this->assertArrayHasKey('register_elgg_event_handler', $renames);
     $this->assertArrayHasKey('setup_db_connections', $renames);
 }
<?php

echo elgg_view('code_review/navigation');
//fetch all
$functions = code_review::getDeprecatedFunctionsList('');
//group by versions
$groups = array();
foreach ($functions as $name => $data) {
    $version = isset($data['version']) ? $data['version'] : 'Unknown';
    if (!isset($groups[$version])) {
        $groups[$version] = array();
    }
    $groups[$version][$name] = $data;
}
ksort($groups);
$fixes = new CodeFixer();
$replaces = $fixes->getBasicFunctionRenames();
foreach ($groups as $version => $group) {
    $title = elgg_echo('code_review:deprecated_list:title', array($version));
    $body = "<table class=\"elgg-table-alt\">";
    $body .= "<tr>" . "<th><strong>" . elgg_echo('code_review:deprecated_list:name') . "</strong></th>" . "<th><strong>" . elgg_echo('code_review:deprecated_list:remarks') . "</strong></th>" . "<th><strong>" . elgg_echo('code_review:deprecated_list:solution') . "</strong></th>" . "</tr>";
    ksort($group, SORT_STRING);
    foreach ($group as $name => $data) {
        $fileLine = elgg_echo('code_review:deprecated_list:file_line', array($data['file'], $data['line']));
        $body .= "<tr><td><abbr title=\"{$fileLine}\">" . $data['name'] . "</abbr></td>";
        $body .= "<td>" . ($data['fixinfoshort'] ? $data['fixinfoshort'] : '') . '</td>';
        $solution = '';
        if (isset($replaces[$name])) {
            $solution = elgg_echo('code_review:solution:basic_replace_with', array($replaces[$name]));
        }
        $body .= "<td>" . $solution . "</td>" . "</tr>";