Merge pull request #13267 from seamuslee001/copywrite_year_update
[civicrm-core.git] / CRM / Core / CodeGen / BaseTask.php
index 73bf72a5d7ac656027fde5e2cd936eab0dc2cae7..c58a32ac15aa06b6fd140bcfd522402b37549c6a 100644 (file)
@@ -57,4 +57,28 @@ abstract class CRM_Core_CodeGen_BaseTask implements CRM_Core_CodeGen_ITask {
     }
   }
 
+  /**
+   * Determine if two snippets of PHP code are approximately equivalent.
+   *
+   * This includes exceptions to equivalence for (a) whitespace and (b)
+   * the token "GenCodeChecksum".
+   *
+   * This is useful for determining if someone has manually mucked with
+   * one the files. However, it's not perfect -- because whitespace changes
+   * are not detected. Hence, it's good to use in combination with another
+   * heuristic.
+   *
+   * @param $actual
+   * @param $expected
+   * @return bool
+   */
+  protected function isApproxPhpMatch($actual, $expected) {
+    foreach (['actual', 'expected'] as $var) {
+      $$var = CRM_Core_CodeGen_Util_ArraySyntaxConverter::convert($$var);
+      $$var = preg_replace(';\(GenCodeChecksum:([a-zA-Z0-9]+)\);', '', $$var);
+      $$var = strtolower(preg_replace(';[ \r\n\t];', '', $$var));
+    }
+    return $actual === $expected;
+  }
+
 }