From d94905eaa6dd62c48f43e519ac7795aa3e8cce03 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 7 Nov 2009 10:50:21 -0500 Subject: [PATCH] strict warnings cleanup and phpunit.xml setup --- .gitignore | 4 +++- classes/ComicPress.inc | 5 +++-- classes/ComicPressComicPost.inc | 17 +++++++++++++++-- classes/ComicPressStoryline.inc | 16 +++++++++++----- test/ComicPressAdminTest.php | 8 +++++--- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 4971ac3..7cbcfba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *~ .directory - +.buildpath +.project +.settings/ diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 3e03079..cdeb337 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -234,7 +234,7 @@ class ComicPress { "Layout Name", "Sidebars" ) as $field) { if (preg_match('#/\*.*' . $field . ': ([^\n]+).*\*/#s', $content, $matches) > 0) { - if (!is_array($this->layouts[$basename])) { + if (!isset($this->layouts[$basename])) { $this->layouts[$basename] = array(); } $this->layouts[$basename][$field] = $matches[1]; @@ -292,7 +292,8 @@ class ComicPress { $sorted_categories = array(); foreach ($this->category_tree as $node) { - $category_id = end(explode("/", $node)); + $parts = explode("/", $node); + $category_id = end($parts); if (in_array($category_id, $categories)) { $sorted_categories[] = $category_id; } diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 733397e..15b4e56 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -79,7 +79,11 @@ class ComicPressComicPost { $dimensions = array(); if (isset($this->comicpress->comicpress_options["${type}_dimensions"])) { - list($width, $height) = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]); + $parts = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]); + switch (count($parts)) { + case 1: list($width) = $parts; break; + case 2: list($width, $height) = $parts; break; + } $dimensions = compact('width', 'height'); } @@ -145,6 +149,7 @@ class ComicPressComicPost { } foreach ($remaining_posts_to_sort as $type => $posts) { + if (!isset($comic_image_ordering[$type])) { $comic_image_ordering[$type] = array(); } if (is_array($comic_image_ordering[$type])) { $comic_image_ordering[$type] = array_merge($comic_image_ordering[$type], $posts); } else { @@ -158,8 +163,16 @@ class ComicPressComicPost { return false; } + /** + * Sort the remaining comic images by file date. + * @param object $a + * @param object $b + * @return int + */ function sort_remaining_comic_images($a, $b) { - return strtotime($a->post_date) - strtotime($b->post_date); + $a_date = isset($a->post_date) ? $a->post_date : 0; + $b_date = isset($b->post_date) ? $b->post_date : 0; + return $a_date - $b_date; } /** diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 08a3155..cd863ef 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -58,7 +58,11 @@ class ComicPressStoryline { $structure = explode(',', $structure); } else { if (is_array($structure)) { - $key = implode(',', $structure); + $fixed_structure = array(); + foreach ($structure as $s) { + if (!is_array($s)) { $fixed_structure[] = $s; } + } + $key = implode(',', $fixed_structure); } } @@ -383,10 +387,12 @@ class ComicPressStoryline { $found_children = false; foreach ($this->_structure as $category_id => $info) { if (!in_array($category_id, $children)) { - if (in_array($info['parent'], $children)) { - $children[] = $category_id; - $found_children = true; - } + if (isset($info['parent'])) { + if (in_array($info['parent'], $children)) { + $children[] = $category_id; + $found_children = true; + } + } } } } while ($found_children); diff --git a/test/ComicPressAdminTest.php b/test/ComicPressAdminTest.php index 8a6841f..6ee0a0a 100644 --- a/test/ComicPressAdminTest.php +++ b/test/ComicPressAdminTest.php @@ -149,8 +149,10 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { $_POST = $change; - $this->admin->handle_update_comicpress_options($_POST['cp']); - + if (isset($_POST['cp'])) { + $this->admin->handle_update_comicpress_options($_POST['cp']); + } + foreach ($new as $key => $value) { $this->assertEquals($value, $this->admin->comicpress->comicpress_options[$key]); } @@ -273,7 +275,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { $this->admin->handle_update_override_partial(array_merge(compact('code', 'action'), array('partial' => 'index'))); - if ($result && $action == "Update partial") { + if ($action == "Update partial") { $this->assertEquals($code, $this->admin->comicpress->comicpress_options['override_partials']['index']); } }