From 78fd50212d75bc72f31d9a4836fc4edcf1c39920 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 24 Jan 2015 00:24:52 -0600 Subject: [PATCH 1/4] Add Roots coding standards based on PSR-2 --- ruleset.xml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ruleset.xml diff --git a/ruleset.xml b/ruleset.xml new file mode 100644 index 0000000..3ae92ca --- /dev/null +++ b/ruleset.xml @@ -0,0 +1,45 @@ + + + Roots Coding Standards + + + + + + + + + + + + + + + + + + + + + + templates/* + + + + + templates/* + 404.php + index.php + page.php + single.php + template-custom.php + + + + + + + + + + From 33fe490cb0e6c0be93adddae5080972d474742c6 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 24 Jan 2015 00:25:59 -0600 Subject: [PATCH 2/4] Add PHPCS to Travis --- .travis.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0aad9a3..b5b0111 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,17 @@ sudo: false language: php cache: npm php: - - 5.6 - - 5.5 - - 5.4 +- '5.6' +- '5.5' +- '5.4' + before_install: - npm install -g bower - npm install + - pyrus install pear/PHP_CodeSniffer + - phpenv rehash + script: - npm run build - npm run jshint + - phpcs --standard=ruleset.xml --extensions=php -n -s . From f4d64d23c9565f3cbf0164eacd9fcefb1d267d94 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 24 Jan 2015 00:48:50 -0600 Subject: [PATCH 3/4] Update PHP files to pass coding standards --- base.php | 2 ++ lib/assets.php | 2 +- lib/config.php | 3 ++- lib/nav.php | 16 ++++++++-------- lib/sidebar.php | 12 ++++++------ lib/wrapper.php | 14 +++++++------- templates/comments.php | 6 +++--- templates/header.php | 6 +++--- 8 files changed, 32 insertions(+), 29 deletions(-) diff --git a/base.php b/base.php index 80bb5fc..5bab6b1 100644 --- a/base.php +++ b/base.php @@ -1,8 +1,10 @@ diff --git a/lib/assets.php b/lib/assets.php index 553f660..23996a9 100644 --- a/lib/assets.php +++ b/lib/assets.php @@ -93,7 +93,7 @@ function google_analytics() { e=o.createElement(i);r=o.getElementsByTagName(i)[0]; e.src='//www.google-analytics.com/analytics.js'; r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); - + function ga() { if (window.console) { console.log('Google Analytics: ' + [].slice.call(arguments)); diff --git a/lib/config.php b/lib/config.php index 6e9b735..c51d360 100644 --- a/lib/config.php +++ b/lib/config.php @@ -1,6 +1,7 @@ Home *
  • Sample PageHome
  • * */ -class Sage_Nav_Walker extends \Walker_Nav_Menu { - function check_current($classes) { +class SageNavWalker extends \Walker_Nav_Menu { + public function checkCurrent($classes) { return preg_match('/(current[-_])|active|dropdown/', $classes); } + // @codingStandardsIgnoreStart function start_lvl(&$output, $depth = 0, $args = []) { $output .= "\n
      \n"; } @@ -29,11 +30,9 @@ class Sage_Nav_Walker extends \Walker_Nav_Menu { if ($item->is_dropdown && ($depth === 0)) { $item_html = str_replace('', ' ', $item_html); - } - elseif (stristr($item_html, 'li class="divider')) { + } elseif (stristr($item_html, 'li class="divider')) { $item_html = preg_replace('/]*>.*?<\/a>/iU', '', $item_html); - } - elseif (stristr($item_html, 'li class="dropdown-header')) { + } elseif (stristr($item_html, 'li class="dropdown-header')) { $item_html = preg_replace('/]*>(.*)<\/a>/iU', '$1', $item_html); } @@ -50,6 +49,7 @@ class Sage_Nav_Walker extends \Walker_Nav_Menu { parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); } + // @codingStandardsIgnoreEnd } /** @@ -82,7 +82,7 @@ add_filter('nav_menu_item_id', '__return_null'); * Clean up wp_nav_menu_args * * Remove the container - * Use Sage_Nav_Walker() by default + * Use SageNavWalker() by default */ function nav_menu_args($args = '') { $nav_menu_args = []; diff --git a/lib/sidebar.php b/lib/sidebar.php index 5a976ed..c1f9699 100644 --- a/lib/sidebar.php +++ b/lib/sidebar.php @@ -14,25 +14,25 @@ namespace Roots\Sage\Sidebar; * * @return boolean True will display the sidebar, False will not */ -class Sage_Sidebar { +class SageSidebar { private $conditionals; private $templates; public $display = true; - function __construct($conditionals = [], $templates = []) { + public function __construct($conditionals = [], $templates = []) { $this->conditionals = $conditionals; $this->templates = $templates; - $conditionals = array_map([$this, 'check_conditional_tag'], $this->conditionals); - $templates = array_map([$this, 'check_page_template'], $this->templates); + $conditionals = array_map([$this, 'checkConditionalTag'], $this->conditionals); + $templates = array_map([$this, 'checkPageTemplate'], $this->templates); if (in_array(true, $conditionals) || in_array(true, $templates)) { $this->display = false; } } - private function check_conditional_tag($conditional_tag) { + private function checkConditionalTag($conditional_tag) { $conditional_arg = is_array($conditional_tag) ? $conditional_tag[1] : false; $conditional_tag = $conditional_arg ? $conditional_tag[0] : $conditional_tag; @@ -43,7 +43,7 @@ class Sage_Sidebar { } } - private function check_page_template($page_template) { + private function checkPageTemplate($page_template) { return is_page_template($page_template); } } diff --git a/lib/wrapper.php b/lib/wrapper.php index 4b4c904..cb3b6d0 100644 --- a/lib/wrapper.php +++ b/lib/wrapper.php @@ -10,14 +10,14 @@ namespace Roots\Sage\Wrapper; */ function template_path() { - return Sage_Wrapping::$main_template; + return SageWrapping::$main_template; } function sidebar_path() { - return new Sage_Wrapping('templates/sidebar.php'); + return new SageWrapping('templates/sidebar.php'); } -class Sage_Wrapping { +class SageWrapping { // Stores the full path to the main template file public static $main_template; @@ -28,7 +28,7 @@ class Sage_Wrapping { public $templates; // Stores the base name of the template file; e.g. 'page' for 'page.php' etc. - static $base; + public static $base; public function __construct($template = 'base.php') { $this->slug = basename($template, '.php'); @@ -45,7 +45,7 @@ class Sage_Wrapping { return locate_template($this->templates); } - static function wrap($main) { + public static function wrap($main) { // Check for other filters returning null if (!is_string($main)) { return $main; @@ -58,7 +58,7 @@ class Sage_Wrapping { self::$base = false; } - return new Sage_Wrapping(); + return new SageWrapping(); } } -add_filter('template_include', [__NAMESPACE__ . '\\Sage_Wrapping', 'wrap'], 99); +add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 99); diff --git a/templates/comments.php b/templates/comments.php index 5452fa2..167a4d1 100644 --- a/templates/comments.php +++ b/templates/comments.php @@ -1,7 +1,7 @@
      diff --git a/templates/header.php b/templates/header.php index 8ad5cc5..010379a 100644 --- a/templates/header.php +++ b/templates/header.php @@ -14,9 +14,9 @@ From 0b98a1e41a979f18244487af0f1b478074e3db24 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sat, 24 Jan 2015 01:11:38 -0600 Subject: [PATCH 4/4] [skip ci] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7057ec2..c4ae76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### 8.0.0: TBD * Change theme name from Roots to Sage * Bump required PHP version to >=5.4 +* Add coding standards based on PSR-2 * Add namespace * Use short array syntax * Use short echo syntax