Replicated line - two ;+=´´)ú¨§ů-.,-*/+_:\\()\@&/|\#/
Replicated line - three ;+=´´)ú¨§ů-.,-*/+_:\\()\@&|\#/
\ No newline at end of file
diff --git a/tests/output/replicator.expected b/tests/output/replicator.expected
deleted file mode 100644
index f0c8ec7..0000000
--- a/tests/output/replicator.expected
+++ /dev/null
@@ -1 +0,0 @@
-Google link Github link
First title
Second title
Deregistered title
Number - one
Number - two
Number - three
Replicated line - one
Replicated line - two ;+=´´)ú¨§ů-.,-*/+_:\\()\@&|\#/
Replicated line - three ;+=´´)ú¨§ů-.,-*/+_:\\()\@&|\#/
\ No newline at end of file
From 5cdb19a2bfeec952616c95a81f3f756f031903d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vladim=C3=ADr=20Mach=C3=A1=C4=8Dek?= <8machy@seznam.cz>
Date: Tue, 29 Mar 2016 23:55:41 +0200
Subject: [PATCH 2/3] Fixed typos, improved annotations, removed unnecessary
use statements
---
src/Compiler.php | 6 +++---
src/Elements/Elements.php | 2 --
src/Elements/ElementsList.php | 2 --
src/Elements/ElementsSettings.php | 2 --
src/Loader.php | 8 ++------
src/LoaderLatte.php | 6 +-----
src/Macros/CoreMacros.php | 34 +++++++++++++++----------------
src/Macros/Macros.php | 2 --
src/Replicator/Register.php | 2 +-
src/Replicator/Replicator.php | 2 --
src/Setup.php | 16 +++++++--------
src/SetupLatte.php | 18 ++++++++--------
12 files changed, 40 insertions(+), 60 deletions(-)
diff --git a/src/Compiler.php b/src/Compiler.php
index 7fad4ee..447a313 100755
--- a/src/Compiler.php
+++ b/src/Compiler.php
@@ -132,12 +132,12 @@ private function getElement($txt) {
* HOW LEVELS WORKS
*
* method 1 = spaces
- * - is better to set the number of the constant SPACES_PER_INDENT on the number
- * you have in your editor setted as "spaces per indent"
+ * - is better to set the number of $spacesPerIndent on the same number
+ * as you have setted in your editor as "spaces per indent"
* method 2 = tabulators
* method 3 = combined
* - tabulators are always twice bigger
- * - Example:
+ * - example:
* - spaces per indent = 4 => tab size = 8
* - spaces per indent = 8 => tab size = 16
* - etc...
diff --git a/src/Elements/Elements.php b/src/Elements/Elements.php
index 7323d5c..7182952 100755
--- a/src/Elements/Elements.php
+++ b/src/Elements/Elements.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Elements;
-use Machy8\Macdom\Elements\ElementsSettings;
-
class Elements extends ElementsSettings {
/**
diff --git a/src/Elements/ElementsList.php b/src/Elements/ElementsList.php
index e954a04..22ec37c 100755
--- a/src/Elements/ElementsList.php
+++ b/src/Elements/ElementsList.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Elements;
-use Machy8\Macdom\Elements\BooleanAttributes;
-
class ElementsList extends BooleanAttributes {
/** @var array */
diff --git a/src/Elements/ElementsSettings.php b/src/Elements/ElementsSettings.php
index 207b702..30825df 100755
--- a/src/Elements/ElementsSettings.php
+++ b/src/Elements/ElementsSettings.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Elements;
-use Machy8\Macdom\Elements\ElementsList;
-
class ElementsSettings extends ElementsList {
/** @var array */
diff --git a/src/Loader.php b/src/Loader.php
index 5c79ba1..28b83c0 100755
--- a/src/Loader.php
+++ b/src/Loader.php
@@ -15,17 +15,13 @@
use Machy8\Macdom\Replicator\Replicator;
class Loader extends Setup {
-
- /**
- * @param string $file
- * @return string $compiled
- */
+
public function __construct() {
parent::__construct();
}
/**
- * @param sting $content
+ * @param string $content
* @return string
*/
public function compileContent($content) {
diff --git a/src/LoaderLatte.php b/src/LoaderLatte.php
index 08e919c..927ce05 100755
--- a/src/LoaderLatte.php
+++ b/src/LoaderLatte.php
@@ -15,11 +15,7 @@
use Machy8\Macdom\Replicator\Replicator;
class LoaderLatte extends SetupLatte {
-
- /**
- * @param string $file
- * @return string $compiled
- */
+
public function __construct() {
parent::__construct();
}
diff --git a/src/Macros/CoreMacros.php b/src/Macros/CoreMacros.php
index 2ea10b0..96f9f98 100755
--- a/src/Macros/CoreMacros.php
+++ b/src/Macros/CoreMacros.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Macros;
-use Machy8\Macdom\Macros\MacrosInstaller;
-
class CoreMacros extends MacrosInstaller {
public function __construct() {
@@ -58,14 +56,14 @@ public function macroDoctype5() {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroDoctype($line) {
return '';
}
/**
- * @return sring
+ * @return string
*/
public function macroUtf8() {
return '';
@@ -73,7 +71,7 @@ public function macroUtf8() {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroCharset($line) {
return '';
@@ -81,7 +79,7 @@ public function macroCharset($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroKeywords($line) {
return '';
@@ -89,7 +87,7 @@ public function macroKeywords($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroDescription($line) {
return '';
@@ -97,7 +95,7 @@ public function macroDescription($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroAuthor($line) {
return '';
@@ -105,7 +103,7 @@ public function macroAuthor($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroViewport($line) {
return '';
@@ -113,7 +111,7 @@ public function macroViewport($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroFacebook($line) {
$selected = strtok($line, " ");
@@ -123,7 +121,7 @@ public function macroFacebook($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroTwitter($line) {
$selected = strtok($line, " ");
@@ -133,7 +131,7 @@ public function macroTwitter($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroCss($line) {
return '';
@@ -141,7 +139,7 @@ public function macroCss($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroFavicon($line) {
return '';
@@ -149,7 +147,7 @@ public function macroFavicon($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroJs($line) {
return '';
@@ -157,7 +155,7 @@ public function macroJs($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroJsAsync($line) {
return '';
@@ -165,21 +163,21 @@ public function macroJsAsync($line) {
/**
* @param string $line
- * @return sring
+ * @return string
*/
public function macroInlineHtmlComment($line) {
return '';
}
/**
- * @return sring
+ * @return string
*/
public function macroOpenHtmlComment() {
return '';
diff --git a/src/Macros/Macros.php b/src/Macros/Macros.php
index df79389..2f697f5 100755
--- a/src/Macros/Macros.php
+++ b/src/Macros/Macros.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Macros;
-use Machy8\Macdom\Macros\CoreMacros;
-
class Macros extends CoreMacros {
/**
diff --git a/src/Replicator/Register.php b/src/Replicator/Register.php
index d9b2bae..cb6e2be 100755
--- a/src/Replicator/Register.php
+++ b/src/Replicator/Register.php
@@ -59,7 +59,7 @@ protected function deregisterLvl($lvl, $element) {
*/
protected function isRegistered($lvl, $element, $line, $registrationLine) {
$registered = $key = FALSE;
- $registereId = NULL;
+ $registerId = NULL;
if (!$registrationLine) {
if (array_key_exists($lvl . '-' . $element, $this->register)) {
$registered = $key = TRUE;
diff --git a/src/Replicator/Replicator.php b/src/Replicator/Replicator.php
index f4fe3f6..ab0edcc 100755
--- a/src/Replicator/Replicator.php
+++ b/src/Replicator/Replicator.php
@@ -12,8 +12,6 @@
namespace Machy8\Macdom\Replicator;
-use Machy8\Macdom\Replicator\Register;
-
class Replicator extends Register {
const
diff --git a/src/Setup.php b/src/Setup.php
index 07c04a2..fa3af96 100755
--- a/src/Setup.php
+++ b/src/Setup.php
@@ -38,8 +38,8 @@ public function __construct() {
}
/**
- * @param bool $value
- * @return \Machy8\Macdom\SetupLatte
+ * @param bool|null $compress
+ * @return Setup
*/
public function compressCode($compress = NULL) {
$this->compressCode = $compress ?: TRUE;
@@ -48,7 +48,7 @@ public function compressCode($compress = NULL) {
/**
* @param int $count
- * @return \Machy8\Macdom\Setup
+ * @return Setup
*/
public function spacesPerIndent($count) {
$this->spacesCount = $count;
@@ -57,7 +57,7 @@ public function spacesPerIndent($count) {
/**
* @param int $id
- * @return \Machy8\Macdom\Setup
+ * @return Setup
*/
public function indentMethod($id) {
$this->indentMethod = $id;
@@ -66,7 +66,7 @@ public function indentMethod($id) {
/**
* @param array $elements
- * @return \Machy8\Macdom\Setup
+ * @return Setup
*/
public function addElements($elements) {
$this->elements->addElements($elements);
@@ -75,7 +75,7 @@ public function addElements($elements) {
/**
* @param array $attributes
- * @return \Machy8\Macdom\Setup
+ * @return Setup
*/
public function addBooleanAttributes($attributes) {
$this->elements->addBooleanAttributes($attributes);
@@ -85,11 +85,11 @@ public function addBooleanAttributes($attributes) {
/**
* @param string $macroId
* @param function $function
- * @return \Machy8\Macdom\Setup
+ * @return Setup
*/
public function addMacro($macroId, $function) {
$this->macros->addCustomMacro($macroId, $function);
return $this;
}
-
}
+
diff --git a/src/SetupLatte.php b/src/SetupLatte.php
index 4c77b96..d6c1af2 100755
--- a/src/SetupLatte.php
+++ b/src/SetupLatte.php
@@ -18,10 +18,10 @@
class SetupLatte extends FileLoader {
- /** @var Elements\Elements */
+ /** @var Elements */
protected $elements;
- /** @var Macros\Macros */
+ /** @var Macros */
protected $macros;
/** @var bool */
@@ -39,8 +39,8 @@ public function __construct() {
}
/**
- * @param bool $value
- * @return \Machy8\Macdom\SetupLatte
+ * @param bool|null $compress
+ * @return SetupLatte
*/
public function compressCode($compress = NULL) {
$this->compressCode = $compress ?: TRUE;
@@ -49,7 +49,7 @@ public function compressCode($compress = NULL) {
/**
* @param int $count
- * @return \Machy8\Macdom\Setup
+ * @return SetupLatte
*/
public function spacesPerIndent($count) {
$this->spacesCount = $count;
@@ -58,7 +58,7 @@ public function spacesPerIndent($count) {
/**
* @param int $id
- * @return \Machy8\Macdom\Setup
+ * @return SetupLatte
*/
public function indentMethod($id) {
$this->indentMethod = $id;
@@ -67,7 +67,7 @@ public function indentMethod($id) {
/**
* @param array $elements
- * @return \Machy8\Macdom\Setup
+ * @return SetupLatte
*/
public function addElements($elements) {
$this->elements->addElements($elements);
@@ -76,7 +76,7 @@ public function addElements($elements) {
/**
* @param array $attributes
- * @return \Machy8\Macdom\Setup
+ * @return SetupLatte
*/
public function addBooleanAttributes($attributes) {
$this->elements->addBooleanAttributes($attributes);
@@ -86,7 +86,7 @@ public function addBooleanAttributes($attributes) {
/**
* @param string $macroId
* @param function $function
- * @return \Machy8\Macdom\Setup
+ * @return SetupLatte
*/
public function addMacro($macroId, $function) {
$this->macros->addCustomMacro($macroId, $function);
From ad76b250d7207297b2482e9842ee3c2d1fad65cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vladim=C3=ADr=20Mach=C3=A1=C4=8Dek?= <8machy@seznam.cz>
Date: Wed, 30 Mar 2016 14:16:16 +0200
Subject: [PATCH 3/3] Improved coding style, improved code annotation
---
src/Compiler.php | 166 +++++++++++++++--------------
src/Elements/BooleanAttributes.php | 3 +-
src/Elements/Elements.php | 18 ++--
src/Elements/ElementsList.php | 3 +-
src/Elements/ElementsSettings.php | 3 +-
src/Loader.php | 14 ++-
src/LoaderLatte.php | 17 ++-
src/Macros/CoreMacros.php | 60 +++++++----
src/Macros/Macros.php | 10 +-
src/Macros/MacrosInstaller.php | 28 +++--
src/Replicator/Register.php | 28 ++---
src/Replicator/Replicator.php | 28 ++---
src/Setup.php | 30 ++++--
src/SetupLatte.php | 29 +++--
14 files changed, 262 insertions(+), 175 deletions(-)
diff --git a/src/Compiler.php b/src/Compiler.php
index 447a313..31634be 100755
--- a/src/Compiler.php
+++ b/src/Compiler.php
@@ -12,7 +12,8 @@
namespace Machy8\Macdom;
-class Compiler {
+class Compiler
+{
/**
* The skip are tag
@@ -63,7 +64,8 @@ class Compiler {
* @param int $spacesPerIndent
* @param bool $compressCode
*/
- public function __construct($Elements, $Macros, $Replicator, $indentMethod, $spacesPerIndent, $compressCode) {
+ public function __construct($Elements, $Macros, $Replicator, $indentMethod, $spacesPerIndent, $compressCode)
+ {
$this->indentMethod = $indentMethod ?: 3;
$this->spacesPerIndent = $spacesPerIndent ?: 4;
$this->lnBreak = $compressCode ? '' : "\n";
@@ -76,7 +78,8 @@ public function __construct($Elements, $Macros, $Replicator, $indentMethod, $spa
* @param string $content
* @return string
*/
- public function compile($content) {
+ public function compile($content)
+ {
$lns = preg_split('/\n/', $content);
foreach ($lns as $key => $ln) {
@@ -119,32 +122,22 @@ public function compile($content) {
return $this->codeStorage;
}
- /**
- * @param string $txt
- * @return string
- */
- private function getElement($txt) {
- $element = explode(' ', trim($txt));
- return $element[0];
- }
-
/**
* HOW LEVELS WORKS
*
* method 1 = spaces
- * - is better to set the number of $spacesPerIndent on the same number
- * as you have setted in your editor as "spaces per indent"
* method 2 = tabulators
* method 3 = combined
- * - tabulators are always twice bigger
- * - example:
- * - spaces per indent = 4 => tab size = 8
- * - spaces per indent = 8 => tab size = 16
- * - etc...
+ * - tabulators are always twice bigger
+ * - example:
+ * - spaces per indent = 4 => tab size = 8
+ * - spaces per indent = 8 => tab size = 16
+ * - etc...
* @param string $ln
* @return int
*/
- private function getLnLvl($ln) {
+ private function getLnLvl($ln)
+ {
$method = $this->indentMethod;
preg_match('/^\s+/', $ln, $matches);
$whites = implode('', $matches);
@@ -165,15 +158,80 @@ private function getLnLvl($ln) {
* @param string $ln
* @return string
*/
- private function getLnTxt($ln) {
+ private function getLnTxt($ln)
+ {
return ltrim($ln);
}
/**
- * @param string $txt
- * @return array
+ * @param string $txt
+ * @return string
+ */
+ private function getElement($txt)
+ {
+ $element = explode(' ', trim($txt));
+ return $element[0];
+ }
+
+ /**
+ * @param string $element
+ * @return bool
*/
- private function getLnAttributes($txt) {
+ private function detectNoCompileArea($element)
+ {
+ $tagDetected = FALSE;
+ $areaClosed = $this->inNoCompileArea ? FALSE : NULL;
+
+ // For skip tag
+ $closeTag = '/' . self::AREA_TAG;
+ if ($element === self::AREA_TAG) {
+ $tagDetected = TRUE;
+ $this->inNoCompileArea = TRUE;
+ } elseif ($element === $closeTag) {
+ $tagDetected = TRUE;
+ $this->inNoCompileArea = FALSE;
+ }
+
+ // For style tag
+ $tag = 'style';
+ $open = '<' . $tag;
+ $close = '' . $tag . '>';
+ if ($element === $open . '>' || $element === $open) {
+ $this->inNoCompileArea = TRUE;
+ } elseif ($element === $close) {
+ $this->inNoCompileArea = FALSE;
+ }
+
+ // For script tag
+ $tag = 'script';
+ $open = '<' . $tag;
+ $close = '' . $tag . '>';
+ if ($element === $open . '>' || $element === $open) {
+ $this->inNoCompileArea = TRUE;
+ } elseif ($element === $close) {
+ $this->inNoCompileArea = FALSE;
+ }
+
+ // For php
+ $open = '';
+ $close = '?>';
+ if ($element === $open . 'php' || $element === $open) {
+ $this->inNoCompileArea = TRUE;
+ } elseif ($element === $close) {
+ $this->inNoCompileArea = FALSE;
+ }
+
+ // Set and return
+ $this->noCompileAreaClosed = $areaClosed;
+ return $tagDetected;
+ }
+
+ /**
+ * @param string $txt
+ * @return array
+ */
+ private function getLnAttributes($txt)
+ {
// Store the text from the first tag to the end of the line
$re = '/\<.*$/';
@@ -281,7 +339,8 @@ private function getLnAttributes($txt) {
* @param int $lvl
* @param array $attributes
*/
- private function addOpenTag($element, $lvl, $attributes) {
+ private function addOpenTag($element, $lvl, $attributes)
+ {
$elementSettings = $this->Elements->findElement($element, TRUE);
$openTag = '<' . $element;
if ($elementSettings['qkAttributes'] && $attributes['qkAttributes']) {
@@ -298,7 +357,7 @@ private function addOpenTag($element, $lvl, $attributes) {
}
} elseif (!in_array($withoutKey, $usedKeys)) {
$newAttr = $elementSettings['qkAttributes'][$withoutKey] . '="' . $attribute['value'] . '"';
- $withoutKey ++;
+ $withoutKey++;
}
if ($newAttr)
$openTag .= ' ' . $newAttr;
@@ -337,7 +396,8 @@ private function addOpenTag($element, $lvl, $attributes) {
}
/** @param int $lvl */
- private function addCloseTags($lvl) {
+ private function addCloseTags($lvl)
+ {
$length = count($this->closeTags);
$lastTag = $length;
if ($length > 0) {
@@ -352,56 +412,4 @@ private function addCloseTags($lvl) {
array_splice($this->closeTags, $lastTag);
}
}
-
- /**
- * @param string $element
- * @return bool
- */
- private function detectNoCompileArea($element) {
- $tagDetected = FALSE;
- $areaClosed = $this->inNoCompileArea ? FALSE : NULL;
-
- // For skip tag
- $closeTag = '/' . self::AREA_TAG;
- if ($element === self::AREA_TAG) {
- $tagDetected = TRUE;
- $this->inNoCompileArea = TRUE;
- } elseif ($element === $closeTag) {
- $tagDetected = TRUE;
- $this->inNoCompileArea = FALSE;
- }
-
- // For style tag
- $tag = 'style';
- $open = '<' . $tag;
- $close = '' . $tag . '>';
- if ($element === $open . '>' || $element === $open) {
- $this->inNoCompileArea = TRUE;
- } elseif ($element === $close) {
- $this->inNoCompileArea = FALSE;
- }
-
- // For script tag
- $tag = 'script';
- $open = '<' . $tag;
- $close = '' . $tag . '>';
- if ($element === $open . '>' || $element === $open) {
- $this->inNoCompileArea = TRUE;
- } elseif ($element === $close) {
- $this->inNoCompileArea = FALSE;
- }
-
- // For php
- $open = '';
- $close = '?>';
- if ($element === $open . 'php' || $element === $open) {
- $this->inNoCompileArea = TRUE;
- } elseif ($element === $close) {
- $this->inNoCompileArea = FALSE;
- }
-
- // Set and return
- $this->noCompileAreaClosed = $areaClosed;
- return $tagDetected;
- }
}
diff --git a/src/Elements/BooleanAttributes.php b/src/Elements/BooleanAttributes.php
index 1a51c6a..a319308 100755
--- a/src/Elements/BooleanAttributes.php
+++ b/src/Elements/BooleanAttributes.php
@@ -12,7 +12,8 @@
namespace Machy8\Macdom\Elements;
-class BooleanAttributes {
+class BooleanAttributes
+{
/** @var array */
protected $booleanAttributes = [
diff --git a/src/Elements/Elements.php b/src/Elements/Elements.php
index 7182952..7fbc08c 100755
--- a/src/Elements/Elements.php
+++ b/src/Elements/Elements.php
@@ -12,13 +12,15 @@
namespace Machy8\Macdom\Elements;
-class Elements extends ElementsSettings {
+class Elements extends ElementsSettings
+{
/**
* @param string $attribute
* @return bool
*/
- public function isBoolean($attribute) {
+ public function isBoolean($attribute)
+ {
return in_array($attribute, $this->booleanAttributes);
}
@@ -27,7 +29,8 @@ public function isBoolean($attribute) {
* @param string $returnSettings
* @return bool|array
*/
- public function findElement($el, $returnSettings) {
+ public function findElement($el, $returnSettings)
+ {
$return = FALSE;
if (in_array($el, $this->elements))
$return = $returnSettings ? $this->getElementSettings($el) : TRUE;
@@ -38,7 +41,8 @@ public function findElement($el, $returnSettings) {
* @param string $el
* @return array
*/
- private function getElementSettings($el) {
+ private function getElementSettings($el)
+ {
$qkAttributes = NULL;
$paired = TRUE;
$settings = $this->elementsSettings;
@@ -58,7 +62,8 @@ private function getElementSettings($el) {
}
/** @param array $elements */
- public function addElements($elements) {
+ public function addElements($elements)
+ {
if ($elements) {
foreach ($elements as $element => $settings) {
$settingsExists = TRUE;
@@ -82,7 +87,8 @@ public function addElements($elements) {
}
/** @param array $attributes */
- public function addBooleanAttributes($attributes) {
+ public function addBooleanAttributes($attributes)
+ {
if ($attributes && is_array($attributes)) {
if (count($attributes)) {
$merged = array_merge($this->booleanAttributes, $attributes);
diff --git a/src/Elements/ElementsList.php b/src/Elements/ElementsList.php
index 22ec37c..791ef98 100755
--- a/src/Elements/ElementsList.php
+++ b/src/Elements/ElementsList.php
@@ -12,7 +12,8 @@
namespace Machy8\Macdom\Elements;
-class ElementsList extends BooleanAttributes {
+class ElementsList extends BooleanAttributes
+{
/** @var array */
protected $elements = [
diff --git a/src/Elements/ElementsSettings.php b/src/Elements/ElementsSettings.php
index 30825df..9dfbf2a 100755
--- a/src/Elements/ElementsSettings.php
+++ b/src/Elements/ElementsSettings.php
@@ -12,7 +12,8 @@
namespace Machy8\Macdom\Elements;
-class ElementsSettings extends ElementsList {
+class ElementsSettings extends ElementsList
+{
/** @var array */
protected $elementsSettings = [
diff --git a/src/Loader.php b/src/Loader.php
index 28b83c0..c77f13f 100755
--- a/src/Loader.php
+++ b/src/Loader.php
@@ -14,9 +14,14 @@
use Machy8\Macdom\Replicator\Replicator;
-class Loader extends Setup {
-
- public function __construct() {
+class Loader extends Setup
+{
+
+ /**
+ * Loader constructor
+ */
+ public function __construct()
+ {
parent::__construct();
}
@@ -24,7 +29,8 @@ public function __construct() {
* @param string $content
* @return string
*/
- public function compileContent($content) {
+ public function compileContent($content)
+ {
$compiler = new Compiler($this->elements, $this->macros, new Replicator, $this->indentMethod, $this->spacesCount, $this->compressCode);
$compiled = $compiler->compile($content);
return $compiled;
diff --git a/src/LoaderLatte.php b/src/LoaderLatte.php
index 927ce05..e7b36ab 100755
--- a/src/LoaderLatte.php
+++ b/src/LoaderLatte.php
@@ -14,9 +14,14 @@
use Machy8\Macdom\Replicator\Replicator;
-class LoaderLatte extends SetupLatte {
-
- public function __construct() {
+class LoaderLatte extends SetupLatte
+{
+
+ /**
+ * LoaderLatte constructor
+ */
+ public function __construct()
+ {
parent::__construct();
}
@@ -24,7 +29,8 @@ public function __construct() {
* @param string $file
* @return string
*/
- public function getContent($file) {
+ public function getContent($file)
+ {
$content = parent::getContent($file);
$compiled = $this->compileContent($content);
return $compiled;
@@ -34,7 +40,8 @@ public function getContent($file) {
* @param string $content
* @return string
*/
- public function compileContent($content) {
+ public function compileContent($content)
+ {
$compiler = new Compiler($this->elements, $this->macros, new Replicator, $this->indentMethod, $this->spacesCount, $this->compressCode);
$compiled = $compiler->compile($content);
return $compiled;
diff --git a/src/Macros/CoreMacros.php b/src/Macros/CoreMacros.php
index 96f9f98..f64f387 100755
--- a/src/Macros/CoreMacros.php
+++ b/src/Macros/CoreMacros.php
@@ -12,9 +12,14 @@
namespace Machy8\Macdom\Macros;
-class CoreMacros extends MacrosInstaller {
+class CoreMacros extends MacrosInstaller
+{
- public function __construct() {
+ /**
+ * CoreMacros constructor
+ */
+ public function __construct()
+ {
// Doctype
$this->addMacro('doctype5', '!5');
$this->addMacro('doctype', '!DOCTYPE');
@@ -50,7 +55,8 @@ public function __construct() {
/**
* @return string
*/
- public function macroDoctype5() {
+ public function macroDoctype5()
+ {
return '';
}
@@ -58,14 +64,16 @@ public function macroDoctype5() {
* @param string $line
* @return string
*/
- public function macroDoctype($line) {
+ public function macroDoctype($line)
+ {
return '';
}
/**
* @return string
*/
- public function macroUtf8() {
+ public function macroUtf8()
+ {
return '';
}
@@ -73,7 +81,8 @@ public function macroUtf8() {
* @param string $line
* @return string
*/
- public function macroCharset($line) {
+ public function macroCharset($line)
+ {
return '';
}
@@ -81,7 +90,8 @@ public function macroCharset($line) {
* @param string $line
* @return string
*/
- public function macroKeywords($line) {
+ public function macroKeywords($line)
+ {
return '';
}
@@ -89,7 +99,8 @@ public function macroKeywords($line) {
* @param string $line
* @return string
*/
- public function macroDescription($line) {
+ public function macroDescription($line)
+ {
return '';
}
@@ -97,7 +108,8 @@ public function macroDescription($line) {
* @param string $line
* @return string
*/
- public function macroAuthor($line) {
+ public function macroAuthor($line)
+ {
return '';
}
@@ -105,7 +117,8 @@ public function macroAuthor($line) {
* @param string $line
* @return string
*/
- public function macroViewport($line) {
+ public function macroViewport($line)
+ {
return '';
}
@@ -113,7 +126,8 @@ public function macroViewport($line) {
* @param string $line
* @return string
*/
- public function macroFacebook($line) {
+ public function macroFacebook($line)
+ {
$selected = strtok($line, " ");
$content = preg_replace("/" . $selected . " /", "", $line);
return '';
@@ -123,7 +137,8 @@ public function macroFacebook($line) {
* @param string $line
* @return string
*/
- public function macroTwitter($line) {
+ public function macroTwitter($line)
+ {
$selected = strtok($line, " ");
$content = trim(preg_replace("/" . $selected . "/", "", $line));
return '';
@@ -133,7 +148,8 @@ public function macroTwitter($line) {
* @param string $line
* @return string
*/
- public function macroCss($line) {
+ public function macroCss($line)
+ {
return '';
}
@@ -141,7 +157,8 @@ public function macroCss($line) {
* @param string $line
* @return string
*/
- public function macroFavicon($line) {
+ public function macroFavicon($line)
+ {
return '';
}
@@ -149,7 +166,8 @@ public function macroFavicon($line) {
* @param string $line
* @return string
*/
- public function macroJs($line) {
+ public function macroJs($line)
+ {
return '';
}
@@ -157,7 +175,8 @@ public function macroJs($line) {
* @param string $line
* @return string
*/
- public function macroJsAsync($line) {
+ public function macroJsAsync($line)
+ {
return '';
}
@@ -165,21 +184,24 @@ public function macroJsAsync($line) {
* @param string $line
* @return string
*/
- public function macroInlineHtmlComment($line) {
+ public function macroInlineHtmlComment($line)
+ {
return '';
}
/**
* @return string
*/
- public function macroOpenHtmlComment() {
+ public function macroOpenHtmlComment()
+ {
return '';
}
}
diff --git a/src/Macros/Macros.php b/src/Macros/Macros.php
index 2f697f5..d4568af 100755
--- a/src/Macros/Macros.php
+++ b/src/Macros/Macros.php
@@ -12,21 +12,23 @@
namespace Machy8\Macdom\Macros;
-class Macros extends CoreMacros {
+class Macros extends CoreMacros
+{
/**
* @param string $macro
* @param string $ln
* @return array
*/
- public function replace($macro, $ln) {
+ public function replace($macro, $ln)
+ {
$replacement = NULL;
$exists = FALSE;
if (isset($this->macros[$macro])) {
$line = trim(strstr($ln, ' '));
$replacement = isset($this->macros[$macro]['function'])
- ? call_user_func($this->macros[$macro]['function'], $line)
- : $this->{'macro' . ucfirst($this->macros[$macro])}($line);
+ ? call_user_func($this->macros[$macro]['function'], $line)
+ : $this->{'macro' . ucfirst($this->macros[$macro])}($line);
$exists = TRUE;
}
return [
diff --git a/src/Macros/MacrosInstaller.php b/src/Macros/MacrosInstaller.php
index a5aab43..62be962 100755
--- a/src/Macros/MacrosInstaller.php
+++ b/src/Macros/MacrosInstaller.php
@@ -12,24 +12,20 @@
namespace Machy8\Macdom\Macros;
-class MacrosInstaller {
-
- protected $macros = [];
+class MacrosInstaller
+{
/**
- * @param string $fnName
- * @param string $macroId
+ * @var array
*/
- protected function addMacro($fnName, $macroId) {
- if (!in_array($macroId, $this->macros))
- $this->macros[$macroId] = $fnName;
- }
+ protected $macros = [];
/**
* @param string $macroId
- * @param function $function
+ * @param callable $function
*/
- public function addCustomMacro($macroId, $function) {
+ public function addCustomMacro($macroId, $function)
+ {
if ($macroId && $function) {
if (!in_array($macroId, $this->macros)) {
$this->macros[] = $macroId;
@@ -37,4 +33,14 @@ public function addCustomMacro($macroId, $function) {
}
}
}
+
+ /**
+ * @param string $fnName
+ * @param string $macroId
+ */
+ protected function addMacro($fnName, $macroId)
+ {
+ if (!in_array($macroId, $this->macros))
+ $this->macros[$macroId] = $fnName;
+ }
}
diff --git a/src/Replicator/Register.php b/src/Replicator/Register.php
index cb6e2be..4608d2f 100755
--- a/src/Replicator/Register.php
+++ b/src/Replicator/Register.php
@@ -12,16 +12,14 @@
namespace Machy8\Macdom\Replicator;
-class Register {
+class Register
+{
const
- /** @const regular expression */
- REG_EXP = '@([\S]*)',
- /** @const string */
- SUFFIX = '-x';
-
- /** @var REGEXP */
- protected $regExp;
+ /** @const regular expression */
+ REG_EXP = '@([\S]*)',
+ /** @const string */
+ SUFFIX = '-x';
/** @var array */
private $register = [];
@@ -31,7 +29,8 @@ class Register {
* @param string $element
* @return bool
*/
- protected function deregisterLvl($lvl, $element) {
+ protected function deregisterLvl($lvl, $element)
+ {
$unregistered = FALSE;
$match = preg_match('/^\/' . self::REG_EXP . '/', $element, $matches);
if ($match) {
@@ -57,7 +56,8 @@ protected function deregisterLvl($lvl, $element) {
* @param int $registrationLine
* @return array
*/
- protected function isRegistered($lvl, $element, $line, $registrationLine) {
+ protected function isRegistered($lvl, $element, $line, $registrationLine)
+ {
$registered = $key = FALSE;
$registerId = NULL;
if (!$registrationLine) {
@@ -87,13 +87,14 @@ protected function isRegistered($lvl, $element, $line, $registrationLine) {
* @param int $lvl
* @return array
*/
- private function registerLvl($element, $line, $lvl) {
+ private function registerLvl($element, $line, $lvl)
+ {
$registered = FALSE;
$registerId = NULL;
$match = preg_match('/^' . self::REG_EXP . '/', $element, $matches);
if ($match) {
$registerId = $lvl;
- $registerId .=!empty($matches[1]) ? '-' . $matches[1] : self::SUFFIX;
+ $registerId .= !empty($matches[1]) ? '-' . $matches[1] : self::SUFFIX;
$this->register[$registerId] = $line;
$registered = TRUE;
}
@@ -107,7 +108,8 @@ private function registerLvl($element, $line, $lvl) {
* @param string $registerId
* @return string $registeredLine
*/
- protected function getRegisteredLine($registerId) {
+ protected function getRegisteredLine($registerId)
+ {
return $this->register[$registerId];
}
}
diff --git a/src/Replicator/Replicator.php b/src/Replicator/Replicator.php
index ab0edcc..6341f31 100755
--- a/src/Replicator/Replicator.php
+++ b/src/Replicator/Replicator.php
@@ -12,14 +12,15 @@
namespace Machy8\Macdom\Replicator;
-class Replicator extends Register {
+class Replicator extends Register
+{
const
- /** @const regular expression */
- REG_EXP_A = '/\[(.*?)\]/',
+ /** @const regular expression */
+ REG_EXP_A = '/\[(.*?)\]/',
- /** @const regular expression */
- REG_EXP_B = '/\[\@\]/';
+ /** @const regular expression */
+ REG_EXP_B = '/\[\@\]/';
/**
* @param int $lvl
@@ -27,7 +28,8 @@ class Replicator extends Register {
* @param string $line
* @return array
*/
- public function detect($lvl, $element, $line) {
+ public function detect($lvl, $element, $line)
+ {
$replicate = $clearLine = FALSE;
$replacement = NULL;
$registrationLine = preg_match('/^' . parent::REG_EXP . '/', $line);
@@ -43,8 +45,8 @@ public function detect($lvl, $element, $line) {
// If the first word on line is also the part of the key in the register
$key = $isRegistered['key'];
$replacement = $key === TRUE
- ? $this->replicate($isRegistered['registerId'], $line, $element, $key)
- : $this->replicate($isRegistered['registerId'], $line);
+ ? $this->replicate($isRegistered['registerId'], $line, $element, $key)
+ : $this->replicate($isRegistered['registerId'], $line);
}
} else {
$clearLine = TRUE;
@@ -63,13 +65,14 @@ public function detect($lvl, $element, $line) {
* @param bool $key
* @return string $replicatedLine
*/
- private function replicate($registerId, $line, $element = NULL, $key = FALSE) {
+ private function replicate($registerId, $line, $element = NULL, $key = FALSE)
+ {
$contentArrays = preg_match_all(self::REG_EXP_A, $line, $matches);
if ($key)
$line = preg_replace('/' . preg_quote($element) . '/', '', $line, 1);
$replicatedline = $contentArrays
- ? $this->synchronizeLines($line, $registerId, $matches[1])
- : $this->synchronizeLines($line, $registerId);
+ ? $this->synchronizeLines($line, $registerId, $matches[1])
+ : $this->synchronizeLines($line, $registerId);
return $replicatedline;
}
@@ -79,7 +82,8 @@ private function replicate($registerId, $line, $element = NULL, $key = FALSE) {
* @param array $matches
* @return string $synchronizedLine
*/
- private function synchronizeLines($line, $registerId, $matches = NULL) {
+ private function synchronizeLines($line, $registerId, $matches = NULL)
+ {
$registeredLine = $this->getRegisteredLine($registerId);
if ($matches !== NULL) {
foreach ($matches as $key => $match) {
diff --git a/src/Setup.php b/src/Setup.php
index fa3af96..16ba4f0 100755
--- a/src/Setup.php
+++ b/src/Setup.php
@@ -15,7 +15,8 @@
use Machy8\Macdom\Elements\Elements;
use Machy8\Macdom\Macros\Macros;
-class Setup {
+class Setup
+{
/** @var Elements */
protected $elements;
@@ -32,7 +33,11 @@ class Setup {
/** @var int */
protected $spacesCount;
- public function __construct() {
+ /**
+ * Setup constructor
+ */
+ public function __construct()
+ {
$this->elements = new Elements;
$this->macros = new Macros;
}
@@ -41,7 +46,8 @@ public function __construct() {
* @param bool|null $compress
* @return Setup
*/
- public function compressCode($compress = NULL) {
+ public function compressCode($compress = NULL)
+ {
$this->compressCode = $compress ?: TRUE;
return $this;
}
@@ -50,7 +56,8 @@ public function compressCode($compress = NULL) {
* @param int $count
* @return Setup
*/
- public function spacesPerIndent($count) {
+ public function spacesPerIndent($count)
+ {
$this->spacesCount = $count;
return $this;
}
@@ -59,7 +66,8 @@ public function spacesPerIndent($count) {
* @param int $id
* @return Setup
*/
- public function indentMethod($id) {
+ public function indentMethod($id)
+ {
$this->indentMethod = $id;
return $this;
}
@@ -68,7 +76,8 @@ public function indentMethod($id) {
* @param array $elements
* @return Setup
*/
- public function addElements($elements) {
+ public function addElements($elements)
+ {
$this->elements->addElements($elements);
return $this;
}
@@ -77,19 +86,20 @@ public function addElements($elements) {
* @param array $attributes
* @return Setup
*/
- public function addBooleanAttributes($attributes) {
+ public function addBooleanAttributes($attributes)
+ {
$this->elements->addBooleanAttributes($attributes);
return $this;
}
/**
* @param string $macroId
- * @param function $function
+ * @param callable $function
* @return Setup
*/
- public function addMacro($macroId, $function) {
+ public function addMacro($macroId, $function)
+ {
$this->macros->addCustomMacro($macroId, $function);
return $this;
}
}
-
diff --git a/src/SetupLatte.php b/src/SetupLatte.php
index d6c1af2..ef23ceb 100755
--- a/src/SetupLatte.php
+++ b/src/SetupLatte.php
@@ -16,7 +16,8 @@
use Machy8\Macdom\Elements\Elements;
use Machy8\Macdom\Macros\Macros;
-class SetupLatte extends FileLoader {
+class SetupLatte extends FileLoader
+{
/** @var Elements */
protected $elements;
@@ -33,7 +34,11 @@ class SetupLatte extends FileLoader {
/** @var int */
protected $spacesCount;
- public function __construct() {
+ /**
+ * SetupLatte constructor
+ */
+ public function __construct()
+ {
$this->elements = new Elements;
$this->macros = new Macros;
}
@@ -42,7 +47,8 @@ public function __construct() {
* @param bool|null $compress
* @return SetupLatte
*/
- public function compressCode($compress = NULL) {
+ public function compressCode($compress = NULL)
+ {
$this->compressCode = $compress ?: TRUE;
return $this;
}
@@ -51,7 +57,8 @@ public function compressCode($compress = NULL) {
* @param int $count
* @return SetupLatte
*/
- public function spacesPerIndent($count) {
+ public function spacesPerIndent($count)
+ {
$this->spacesCount = $count;
return $this;
}
@@ -60,7 +67,8 @@ public function spacesPerIndent($count) {
* @param int $id
* @return SetupLatte
*/
- public function indentMethod($id) {
+ public function indentMethod($id)
+ {
$this->indentMethod = $id;
return $this;
}
@@ -69,7 +77,8 @@ public function indentMethod($id) {
* @param array $elements
* @return SetupLatte
*/
- public function addElements($elements) {
+ public function addElements($elements)
+ {
$this->elements->addElements($elements);
return $this;
}
@@ -78,17 +87,19 @@ public function addElements($elements) {
* @param array $attributes
* @return SetupLatte
*/
- public function addBooleanAttributes($attributes) {
+ public function addBooleanAttributes($attributes)
+ {
$this->elements->addBooleanAttributes($attributes);
return $this;
}
/**
* @param string $macroId
- * @param function $function
+ * @param callable $function
* @return SetupLatte
*/
- public function addMacro($macroId, $function) {
+ public function addMacro($macroId, $function)
+ {
$this->macros->addCustomMacro($macroId, $function);
return $this;
}