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