mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-06-10 12:29:26 -04:00
Make sure that helper functions are all static. Add new
File_Structure_Test to make sure we don't regress. According to the PHP docs, the "public" keyword is implied on static functions, so remove it. Also, require private static functions to start with an _. http://php.net/manual/en/language.oop5.visibility.php
This commit is contained in:
@@ -21,7 +21,6 @@ class File_Structure_Test extends Unit_Test_Case {
|
||||
public function no_trailing_closing_php_tag_test() {
|
||||
$dir = new GalleryCodeFilterIterator(
|
||||
new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
|
||||
$incorrect = array();
|
||||
foreach ($dir as $file) {
|
||||
if (!preg_match("|\.html\.php$|", $file->getPathname())) {
|
||||
$this->assert_false(
|
||||
@@ -86,15 +85,14 @@ class File_Structure_Test extends Unit_Test_Case {
|
||||
}
|
||||
|
||||
public function no_tabs_in_our_code_test() {
|
||||
$dir = new GalleryCodeFilterIterator(
|
||||
new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
|
||||
$incorrect = array();
|
||||
$dir = new PhpCodeFilterIterator(
|
||||
new GalleryCodeFilterIterator(
|
||||
new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator(DOCROOT))));
|
||||
foreach ($dir as $file) {
|
||||
if (substr($file->getFilename(), -4) == ".php") {
|
||||
$this->assert_false(
|
||||
preg_match('/\t/', file_get_contents($file)),
|
||||
"{$file->getPathname()} has tabs in it");
|
||||
}
|
||||
$this->assert_false(
|
||||
preg_match('/\t/', file_get_contents($file)),
|
||||
"{$file->getPathname()} has tabs in it");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +107,30 @@ class File_Structure_Test extends Unit_Test_Case {
|
||||
}
|
||||
return $copy;
|
||||
}
|
||||
|
||||
public function helpers_are_static_test() {
|
||||
$dir = new PhpCodeFilterIterator(
|
||||
new GalleryCodeFilterIterator(
|
||||
new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator(DOCROOT))));
|
||||
foreach ($dir as $file) {
|
||||
if (basename(dirname($file)) == "helpers") {
|
||||
foreach (file($file) as $line) {
|
||||
$this->assert_true(
|
||||
!preg_match("/\sfunction\s.*\(/", $line) ||
|
||||
preg_match("/^\s*(private static function _|static function)/", $line),
|
||||
"should be \"static function foo\" or \"private static function _foo\":\n" .
|
||||
"$file\n$line\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PhpCodeFilterIterator extends FilterIterator {
|
||||
public function accept() {
|
||||
return substr($this->getInnerIterator()->getPathName(), -4) == ".php";
|
||||
}
|
||||
}
|
||||
|
||||
class GalleryCodeFilterIterator extends FilterIterator {
|
||||
|
||||
Reference in New Issue
Block a user