Skip to content

Commit

Permalink
Merge pull request #1 from jimmy4fingers/stage
Browse files Browse the repository at this point in the history
Build pipeline improvements
  • Loading branch information
jimmy4fingers committed Aug 22, 2018
2 parents a5bb930 + 5ad246e commit 94c2654
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ cache:

# Run script
script:
- ./vendor/bin/phpspec -v
- ./vendor/bin/phpspec run --config phpspec.travis.yml -vvv
# BDD tests
- ./vendor/bin/phpspec run --config phpspec.travis.yml -vvv
# coding standards and analysis
- ./vendor/bin/phpcs --standard=PSR2 src
- ./vendor/bin/phpmd src text mess-dector-rules.xml
- ./vendor/bin/phpstan analyse src --level=7
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"description": "HTML elements as PHP objects with decorators",
"require": {
"php": ">=7",
"phpspec/phpspec": "^4.3"
"phpspec/phpspec": "^4.3",
"squizlabs/php_codesniffer": "3.*",
"phpmd/phpmd" : "@stable",
"phpstan/phpstan": "^0.9.2"
},
"minimum-stability": "stable",
"autoload":{
Expand Down
20 changes: 20 additions & 0 deletions mess-dector-rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset name="all phpmd rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
All PHPMD rules applied.
</description>

<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/controversial.xml" />

</ruleset>
2 changes: 1 addition & 1 deletion spec/HTML/ElementSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ function it_sets_html_elements()
function it_sets_end_tag()
{
$this->setEndTag(false);
$this->getEndTag()->shouldReturn(false);
$this->hasEndTag()->shouldReturn(false);
}
}
19 changes: 12 additions & 7 deletions src/HTML/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ class Element implements ElementInterface
{
/**
* HTML tag
*
* @var string
*/
protected $tag;
/**
* array of HTML attributes
*
* @var array
*/
protected $attributes;

/**
* HTML between tags
* @var string
*
* @var mixed
*/
protected $html;

/**
* has end HTML tag or not
*
* @var bool $endTag
*/
protected $endTag = true;
Expand All @@ -42,15 +46,15 @@ public function __construct(array $settings = [])

/**
* @param string $attribute
* @param $value mixed
* @param mixed $value
*/
public function setAttribute(string $attribute, $value)
{
$this->attributes[$attribute] = $value;
}

/**
* @param string $attribute
* @param string $attribute
* @return mixed
*/
public function getAttribute(string $attribute)
Expand Down Expand Up @@ -83,7 +87,7 @@ public function getTag():string
}

/**
* @param string|ElementInterface $html
* @param mixed $html
*/
public function setHTML($html)
{
Expand All @@ -109,7 +113,7 @@ public function setEndTag(bool $endTag)
/**
* @return bool
*/
public function getEndTag()
public function hasEndTag()
{
return $this->endTag;
}
Expand All @@ -124,8 +128,9 @@ protected function set(array $settings)
}

if (array_key_exists('attributes', $settings) && is_array($settings['attributes'])) {
foreach ($settings['attributes'] as $attr=>$value)
foreach ($settings['attributes'] as $attr => $value) {
$this->setAttribute($attr, $value);
}
}

if (array_key_exists('html', $settings)) {
Expand All @@ -136,4 +141,4 @@ protected function set(array $settings)
$this->setEndTag($settings['endTag']);
}
}
}
}
9 changes: 6 additions & 3 deletions src/HTML/ElementDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ElementDecorator implements ElementDecoratorInterface

/**
* ElementDecorator constructor.
*
* @param ElementInterface $element
*/
public function __construct(ElementInterface $element)
Expand Down Expand Up @@ -44,12 +45,13 @@ public function getEndTag()
private function getDecoratedTag()
{
$attr = $this->element->getAttributes();
$htmlTagParts[] = $this->element->getTag();;
$htmlTagParts[] = $this->element->getTag();

$str = '<';
if (is_array($attr) && !empty($attr)) {
foreach ($attr as $key => $value)
foreach ($attr as $key => $value) {
$htmlTagParts[] = $key . '="'. $value .'"';
}
}
$str .= implode(' ', $htmlTagParts);
$str .= '>';
Expand All @@ -59,8 +61,9 @@ private function getDecoratedTag()

private function getDecoratedEndTag()
{
if ($this->element->getEndTag() === false)
if ($this->element->hasEndTag() === false) {
return '';
}

return '</'.$this->element->getTag().'>';
}
Expand Down
2 changes: 1 addition & 1 deletion src/HTML/ElementDecoratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function __construct(ElementInterface $element);
public function __toString();
public function getTag();
public function getEndTag();
}
}
4 changes: 2 additions & 2 deletions src/HTML/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function getAttribute(string $attribute);
public function getAttributes();
public function setTag(string $tag);
public function getTag();
public function getEndTag();
public function hasEndTag();
public function setEndTag(bool $endTag);
public function setHTML($html);
public function getHTML();
}
}
4 changes: 2 additions & 2 deletions src/HTML/HTMLDecoratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface HTMLDecoratorInterface
{
public function element(ElementInterface $element);
public function beforeElement(ElementInterface $element);
public function AfterElement(ElementInterface $element);
public function afterElement(ElementInterface $element);
public function parentElement(ElementInterface $element);
public function __toString();
}
}

0 comments on commit 94c2654

Please sign in to comment.