Skip to content

Commit

Permalink
All function braces need to be on new line
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t authored and retlehs committed Mar 11, 2016
1 parent 9e2917e commit b491f76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* themes/sage/index.php also contains some self-correcting code, just in case the template option gets reset
*/
add_filter('stylesheet', function ($stylesheet) {
return dirname($stylesheet);
return dirname($stylesheet);
});
add_action('after_switch_theme', function () {
$stylesheet = get_option('stylesheet');
basename($stylesheet) == 'templates' || update_option('stylesheet', $stylesheet . '/templates');
$stylesheet = get_option('stylesheet');
basename($stylesheet) == 'templates' || update_option('stylesheet', $stylesheet . '/templates');
});

/**
Expand Down
15 changes: 12 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
<arg value="s"/>

<!-- Use PSR-2 as a base -->
<rule ref="PSR2">
<!-- Allow braces on same line for named functions -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
<rule ref="PSR2"/>

<!-- Exclusions below are for templates/ folder -->

<!-- Allow php files without any PHP in them -->
<rule ref="Internal.NoCodeFound">
<exclude-pattern>templates</exclude-pattern>
</rule>

<!-- Allow braces on same line for named functions -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<exclude-pattern>templates</exclude-pattern>
</rule>

<!-- Allow closing braces to be on the same line -->
Expand Down
15 changes: 10 additions & 5 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* @throws \Exception
* @SuppressWarnings(PHPMD.StaticAccess) This is a helper function, so we can suppress this warning
*/
function template_wrap(WrapperInterface $wrapper, $slug = 'base') {
function template_wrap(WrapperInterface $wrapper, $slug = 'base')
{
WrapperCollection::add($wrapper, $slug);
return $wrapper->getWrapper();
}
Expand All @@ -21,15 +22,17 @@ function template_wrap(WrapperInterface $wrapper, $slug = 'base') {
* @param string $slug
* @return string
*/
function template_unwrap($slug = 'base') {
function template_unwrap($slug = 'base')
{
return WrapperCollection::get($slug)->getTemplate();
}

/**
* @param $filename
* @return string
*/
function asset_path($filename) {
function asset_path($filename)
{
static $manifest;
isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json');
return (string) new Asset($filename, $manifest);
Expand All @@ -39,7 +42,8 @@ function asset_path($filename) {
* Determine whether to show the sidebar
* @return bool
*/
function display_sidebar() {
function display_sidebar()
{
static $display;
isset($display) || $display = apply_filters('sage/display_sidebar', true);
return $display;
Expand All @@ -49,7 +53,8 @@ function display_sidebar() {
* Page titles
* @return string
*/
function title() {
function title()
{
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
return get_the_title($home);
Expand Down
9 changes: 6 additions & 3 deletions src/lib/Sage/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ class Asset

protected $dir;

public function __construct($file, ManifestInterface $manifest = null) {
public function __construct($file, ManifestInterface $manifest = null)
{
$this->manifest = $manifest;
$this->asset = basename($file);
$this->dir = dirname($file) != '.' ? dirname($file) : '';
}

public function __toString() {
public function __toString()
{
return $this->getUri();
}

public function getUri() {
public function getUri()
{
$file = ($this->manifest ? $this->manifest->get($this->asset) : $this->asset);
return get_template_directory_uri() . self::$dist . '/' . $this->dir . '/' . $file;
}
Expand Down

0 comments on commit b491f76

Please sign in to comment.