Conform to new rules
This commit is contained in:
13
phpcs.xml
13
phpcs.xml
@@ -2,8 +2,9 @@
|
||||
<ruleset name="Roots">
|
||||
<description>Roots Coding Standards</description>
|
||||
|
||||
<!-- Use PSR-2 as a base -->
|
||||
<rule ref="PSR2"/>
|
||||
<!-- Scan these files -->
|
||||
<file>functions.php</file>
|
||||
<file>src</file>
|
||||
|
||||
<!-- Show colors in console -->
|
||||
<arg value="-colors"/>
|
||||
@@ -11,7 +12,9 @@
|
||||
<!-- Show sniff codes in all reports -->
|
||||
<arg value="s"/>
|
||||
|
||||
<!-- Scan these files -->
|
||||
<file>functions.php</file>
|
||||
<file>src</file>
|
||||
<!-- Use PSR-2 as a base -->
|
||||
<rule ref="PSR2">
|
||||
<!-- Allow braces on same line for procedural functions -->
|
||||
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
||||
@@ -7,7 +7,8 @@ use Roots\Sage\Assets\ManifestInterface;
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class Asset {
|
||||
class Asset
|
||||
{
|
||||
public static $dist = '/dist';
|
||||
|
||||
/** @var ManifestInterface Currently used manifest */
|
||||
@@ -28,7 +29,7 @@ class Asset {
|
||||
}
|
||||
|
||||
public function getUri() {
|
||||
$file = self::$dist . '/' . $this->dir . '/' . ($this->manifest ? $this->manifest->get($this->asset) : $this->asset);
|
||||
return get_template_directory_uri() . $file;
|
||||
$file = ($this->manifest ? $this->manifest->get($this->asset) : $this->asset);
|
||||
return get_template_directory_uri() . self::$dist . '/' . $this->dir . '/' . $file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class JsonManifest implements ManifestInterface {
|
||||
class JsonManifest implements ManifestInterface
|
||||
{
|
||||
/** @var array */
|
||||
protected $manifest = [];
|
||||
|
||||
@@ -13,17 +14,20 @@ class JsonManifest implements ManifestInterface {
|
||||
* JsonManifest constructor
|
||||
* @param string $manifestPath Local filesystem path to JSON-encoded manifest
|
||||
*/
|
||||
public function __construct($manifestPath) {
|
||||
public function __construct($manifestPath)
|
||||
{
|
||||
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : [];
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function get($file) {
|
||||
public function get($file)
|
||||
{
|
||||
return isset($this->manifest[$file]) ? $this->manifest[$file] : $file;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function getAll() {
|
||||
public function getAll()
|
||||
{
|
||||
return $this->manifest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
interface ManifestInterface {
|
||||
interface ManifestInterface
|
||||
{
|
||||
/**
|
||||
* Get the cache-busted filename
|
||||
*
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class Wrapper implements WrapperInterface {
|
||||
class Wrapper implements WrapperInterface
|
||||
{
|
||||
/** @var string Wrapper slug */
|
||||
protected $slug;
|
||||
|
||||
@@ -24,7 +25,8 @@ class Wrapper implements WrapperInterface {
|
||||
* @param string $template Template file, as from Template Heirarchy; e.g., `page.php`, `single.php`, `singular.php`
|
||||
* @param string $base Wrapper's base template, this is what will wrap around $template
|
||||
*/
|
||||
public function __construct($template, $base = 'layouts/base.php') {
|
||||
public function __construct($template, $base = 'layouts/base.php')
|
||||
{
|
||||
$this->slug = sanitize_title(basename($base, '.php'));
|
||||
$this->wrapper = [$base];
|
||||
$this->template = $template;
|
||||
@@ -36,23 +38,27 @@ class Wrapper implements WrapperInterface {
|
||||
* @return string
|
||||
* @see getTemplate
|
||||
*/
|
||||
public function __toString() {
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getTemplate();
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getWrapper() {
|
||||
public function getWrapper()
|
||||
{
|
||||
$wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrapper) ?: $this->wrapper;
|
||||
return locate_template($wrappers);
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getSlug() {
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getTemplate() {
|
||||
public function getTemplate()
|
||||
{
|
||||
$template = apply_filters('sage/unwrap_' . $this->slug, $this->template) ?: $this->template;
|
||||
return locate_template($template);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,24 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class WrapperCollection {
|
||||
class WrapperCollection
|
||||
{
|
||||
/** @var $this */
|
||||
protected static $instance;
|
||||
/** @var WrapperInterface[] $wrappers */
|
||||
protected $wrappers = [];
|
||||
|
||||
/** Singleton */
|
||||
// @codingStandardsIgnoreStart
|
||||
private function __construct() {}
|
||||
private function __clone() {}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function instance() {
|
||||
public static function instance()
|
||||
{
|
||||
isset(self::$instance) || self::$instance = new static;
|
||||
return self::$instance;
|
||||
}
|
||||
@@ -30,7 +34,8 @@ class WrapperCollection {
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function add(WrapperInterface $wrapper, $slug = '', $overwriteIfExists = false) {
|
||||
public static function add(WrapperInterface $wrapper, $slug = '', $overwriteIfExists = false)
|
||||
{
|
||||
$slug = $slug ?: $wrapper->getSlug();
|
||||
if (self::instance()->exists($slug) && !$overwriteIfExists) {
|
||||
throw new \Exception("Wrapper $slug already exists.");
|
||||
@@ -43,7 +48,8 @@ class WrapperCollection {
|
||||
* @param string $slug
|
||||
* @return $this
|
||||
*/
|
||||
public static function remove($slug) {
|
||||
public static function remove($slug)
|
||||
{
|
||||
unset(self::instance()->wrappers[$slug]);
|
||||
return self::instance();
|
||||
}
|
||||
@@ -52,14 +58,16 @@ class WrapperCollection {
|
||||
* @param string $slug
|
||||
* @return null|WrapperInterface
|
||||
*/
|
||||
public static function get($slug) {
|
||||
public static function get($slug)
|
||||
{
|
||||
return isset(self::instance()->wrappers[$slug]) ? self::instance()->wrappers[$slug] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Slugs of wrappers in collection
|
||||
*/
|
||||
public static function wrappers() {
|
||||
public static function wrappers()
|
||||
{
|
||||
return array_keys(self::instance()->wrappers);
|
||||
}
|
||||
|
||||
@@ -67,7 +75,8 @@ class WrapperCollection {
|
||||
* @param $slug
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($slug) {
|
||||
public static function exists($slug)
|
||||
{
|
||||
return isset(self::instance()->wrappers[$slug]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
interface WrapperInterface {
|
||||
interface WrapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get wrapper template file
|
||||
|
||||
Reference in New Issue
Block a user