Skip to content

Commit

Permalink
Merge pull request #25 from Airmanbzh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Airmanbzh authored Dec 27, 2017
2 parents 78c7971 + 25a6156 commit 627a2ce
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 56 deletions.
36 changes: 34 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
language: php
dist: trusty
php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.0'

matrix:
include:
- php: 5.3
dist: precise

before_script:
## PHP_CodeSniffer
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then pear install pear/PHP_CodeSniffer; fi
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then phpenv rehash; fi
## PHP Copy/Paste Detector
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector
## - pear config-set preferred_state beta
## - printf "\n" | pecl install imagick
## - pear channel-discover pear.phpmd.org
## - pear channel-discover pear.pdepend.org
## - pear install --alldeps phpmd/PHP_PMD
## - phpenv rehash
## PHPLOC
- curl -o phploc.phar https://phar.phpunit.de/phploc.phar

script:
## PHP_CodeSniffer
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then phpcs --standard=PSR1 src/ -v; fi
- if [[ ${TRAVIS_PHP_VERSION:0:1} != "7" ]]; then phpcs --standard=PSR2 src/ -v; fi
## PHP Copy/Paste Detector
- php phpcpd.phar --verbose src/
## PHP Mess Detector
## - phpmd src/ text codesize,unusedcode,naming,design
## PHPLOC
- php phploc.phar src/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"autoload": {
"psr-4": {"HtmlGenerator\\": ""}
"psr-4": {"HtmlGenerator\\": "src/"}
},
"autoload-dev": {
"psr-4": { "HtmlGenerator\\Tests\\": "tests/" }
Expand Down
9 changes: 5 additions & 4 deletions HtmlTag.php → src/HtmlTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*/
namespace HtmlGenerator;

if (!defined('ENT_HTML5'))
{
define('ENT_HTML5', 48);
if (!defined('ENT_HTML5')) {
define('ENT_HTML5', 48);
}

class HtmlTag extends Markup
{
/** @var int The language convention used for XSS avoiding */
/**
* @var int The language convention used for XSS avoiding
*/
public static $outputLanguage = ENT_HTML5;

protected $autocloseTagsList = array(
Expand Down
70 changes: 33 additions & 37 deletions Markup.php → src/Markup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use ArrayAccess;

if (!defined('ENT_XML1'))
{
define('ENT_XML1', 16);
if (!defined('ENT_XML1')) {
define('ENT_XML1', 16);
}
if (!defined('ENT_XHTML'))
{
define('ENT_XHTML', 32);
if (!defined('ENT_XHTML')) {
define('ENT_XHTML', 32);
}


Expand All @@ -24,10 +22,10 @@ class Markup implements ArrayAccess
/** @var int The language convention used for XSS avoiding */
public static $outputLanguage = ENT_XML1;

protected static $_instance = null;
protected static $instance = null;

protected $_top = null;
protected $_parent = null;
protected $top = null;
protected $parent = null;

protected $tag = null;
public $attributeList = null;
Expand All @@ -49,7 +47,7 @@ class Markup implements ArrayAccess
protected function __construct($tag, $top = null)
{
$this->tag = $tag;
$this->_top =& $top;
$this->top =& $top;
$this->attributeList = array();
$this->classList = array();
$this->content = array();
Expand Down Expand Up @@ -101,8 +99,8 @@ public function __invoke()
*/
public static function createElement($tag = '')
{
self::$_instance = new static($tag);
return self::$_instance;
self::$instance = new static($tag);
return self::$instance;
}

/**
Expand All @@ -113,9 +111,9 @@ public static function createElement($tag = '')
*/
public function addElement($tag = '')
{
$htmlTag = (is_object($tag) && $tag instanceof self) ? $tag : new static($tag);
$htmlTag->_top = $this->getTop();
$htmlTag->_parent = &$this;
$htmlTag = (is_object($tag) && $tag instanceof self) ? clone $tag : new static($tag);
$htmlTag->top = $this->getTop();
$htmlTag->parent = &$this;

$this->content[] = $htmlTag;
return $htmlTag;
Expand All @@ -129,7 +127,7 @@ public function addElement($tag = '')
*/
public function set($attribute, $value = null)
{
if(is_array($attribute)) {
if (is_array($attribute)) {
foreach ($attribute as $key => $value) {
$this[$key] = $value;
}
Expand Down Expand Up @@ -192,8 +190,9 @@ public function offsetSet($attribute, $value)
*/
public function offsetUnset($attribute)
{
if ($this->offsetExists($attribute))
if ($this->offsetExists($attribute)) {
unset($this->attributeList[$attribute]);
}
}

/**
Expand All @@ -214,7 +213,7 @@ public function text($value)
*/
public function getTop()
{
return $this->_top===null ? $this : $this->_top;
return $this->top===null ? $this : $this->top;
}

/**
Expand All @@ -223,28 +222,28 @@ public function getTop()
*/
public function getParent()
{
return $this->_parent;
return $this->parent;
}

/**
* Return first child of parent of current object
*/
public function getFirst()
{
return is_null($this->_parent) ? null : $this->_parent->content[0];
return is_null($this->parent) ? null : $this->parent->content[0];
}

/**
* Return previous element or itself
*
*
* @return Markup instance
*/
public function getPrevious()
{
$prev = $this;
$find = false;
if (!is_null($this->_parent)) {
foreach ($this->_parent->content as $c) {
if (!is_null($this->parent)) {
foreach ($this->parent->content as $c) {
if ($c === $this) {
$find=true;
break;
Expand All @@ -264,8 +263,8 @@ public function getNext()
{
$next = null;
$find = false;
if (!is_null($this->_parent)) {
foreach ($this->_parent->content as $c) {
if (!is_null($this->parent)) {
foreach ($this->parent->content as $c) {
if ($find) {
$next = &$c;
break;
Expand All @@ -283,15 +282,15 @@ public function getNext()
*/
public function getLast()
{
return is_null($this->_parent) ? null : $this->_parent->content[count($this->_parent->content) - 1];
return is_null($this->parent) ? null : $this->parent->content[count($this->parent->content) - 1];
}

/**
* @return Markup return parent or null
*/
public function remove()
{
$parent = $this->_parent;
$parent = $this->parent;
if (!is_null($parent)) {
foreach ($parent->content as $key => $value) {
if ($parent->content[$key] == $this) {
Expand Down Expand Up @@ -346,7 +345,7 @@ protected function attributesToString()
foreach ($this->attributeList as $key => $value) {
if ($value!==null && ($value!==false || $XMLConvention)) {
$string.= ' ' . $key;
if($value===true) {
if ($value===true) {
if ($XMLConvention) {
$value = $key;
} else {
Expand Down Expand Up @@ -389,15 +388,12 @@ protected function contentToString()
*/
public static function unXSS($input)
{
$return = '';
if (version_compare(phpversion(), '5.4', '<'))
{
$return = htmlspecialchars($input);
}
else
{
$return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
}
$return = '';
if (version_compare(phpversion(), '5.4', '<')) {
$return = htmlspecialchars($input);
} else {
$return = htmlentities($input, ENT_QUOTES | ENT_DISALLOWED | static::$outputLanguage);
}

return $return;
}
Expand Down
25 changes: 13 additions & 12 deletions tests/autoloader.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
function loader($class)
{
$class = explode('\\', $class);
$class = array_pop($class);


$file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $class . '.php';
if (file_exists($file)) {
require $file;
}
}
<?php
function loader($class)
{
$class = explode('\\', $class);
$class = array_pop($class);

$file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $class . '.php';

if (file_exists($file)) {
require $file;
}
}

spl_autoload_register('loader');

0 comments on commit 627a2ce

Please sign in to comment.