Skip to content

Commit

Permalink
Add PHPCS checks
Browse files Browse the repository at this point in the history
  • Loading branch information
thiemowmde authored and bekh6ex committed Jul 5, 2017
1 parent 89e15f7 commit c0c472d
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -14,6 +14,7 @@
"hamcrest/hamcrest-php": "^1.1.1||^2.0"
},
"require-dev": {
"wikibase/wikibase-codesniffer": "^0.1.0",
"phpunit/phpunit": "^4.8"
},
"autoload": {
Expand All @@ -31,6 +32,7 @@
},
"scripts": {
"ci": [
"phpcs -p -s",
"phpunit"
]
},
Expand Down
21 changes: 21 additions & 0 deletions phpcs.xml
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="HamcrestHtmlMatchers">
<rule ref="vendor/wikibase/wikibase-codesniffer/Wikibase">
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
<exclude name="Generic.PHP.NoSilencedErrors" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<exclude name="MediaWiki.WhiteSpace.SpaceyParenthesis" />
</rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="128" />
</properties>
</rule>

<rule ref="Squiz.WhiteSpace.FunctionSpacing">
<exclude-pattern>functions\.php</exclude-pattern>
</rule>

<file>.</file>
</ruleset>
2 changes: 2 additions & 0 deletions src/AttributeMatcher.php
Expand Up @@ -8,6 +8,7 @@

class AttributeMatcher extends TagMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -82,4 +83,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi

return false;
}

}
2 changes: 2 additions & 0 deletions src/ChildElementMatcher.php
Expand Up @@ -8,6 +8,7 @@

class ChildElementMatcher extends TypeSafeDiagnosingMatcher
{

/**
* @var Matcher|null
*/
Expand Down Expand Up @@ -66,4 +67,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi
$mismatchDescription->appendText('having no children ')->appendDescriptionOf($this->matcher);
return false;
}

}
2 changes: 2 additions & 0 deletions src/ClassMatcher.php
Expand Up @@ -8,6 +8,7 @@

class ClassMatcher extends TagMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -47,4 +48,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi

return false;
}

}
2 changes: 2 additions & 0 deletions src/ComplexTagMatcher.php
Expand Up @@ -10,6 +10,7 @@

class ComplexTagMatcher extends TagMatcher
{

/**
* @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
* @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
Expand Down Expand Up @@ -205,4 +206,5 @@ private function elementToString(\DOMElement $element)
$newDocument->appendChild($newDocument->importNode($cloned, true));
return trim($newDocument->saveHTML());
}

}
3 changes: 2 additions & 1 deletion src/DirectChildElementMatcher.php
Expand Up @@ -2,13 +2,13 @@

namespace WMDE\HamcrestHtml;


use Hamcrest\Description;
use Hamcrest\Matcher;
use Hamcrest\TypeSafeDiagnosingMatcher;

class DirectChildElementMatcher extends TypeSafeDiagnosingMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -72,4 +72,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi

return false;
}

}
2 changes: 2 additions & 0 deletions src/HtmlMatcher.php
Expand Up @@ -8,6 +8,7 @@

class HtmlMatcher extends DiagnosingMatcher
{

/**
* @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
* @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
Expand Down Expand Up @@ -108,4 +109,5 @@ private function stripScriptsContents($html)
}
return $html;
}

}
2 changes: 2 additions & 0 deletions src/RootElementMatcher.php
Expand Up @@ -8,6 +8,7 @@

class RootElementMatcher extends TypeSafeDiagnosingMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -68,4 +69,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi

return (bool)$target;
}

}
2 changes: 2 additions & 0 deletions src/TagMatcher.php
Expand Up @@ -6,8 +6,10 @@

abstract class TagMatcher extends TypeSafeDiagnosingMatcher
{

public function __construct()
{
parent::__construct(self::TYPE_OBJECT, \DOMElement::class);
}

}
2 changes: 2 additions & 0 deletions src/TagNameMatcher.php
Expand Up @@ -8,6 +8,7 @@

class TagNameMatcher extends TagMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -41,4 +42,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi
$this->tagNameMatcher->describeMismatch($item->tagName, $mismatchDescription);
return $this->tagNameMatcher->matches($item->tagName);
}

}
3 changes: 3 additions & 0 deletions src/TextContentsMatcher.php
@@ -1,12 +1,14 @@
<?php

namespace WMDE\HamcrestHtml;

use Hamcrest\Description;
use Hamcrest\Matcher;
use Hamcrest\Util;

class TextContentsMatcher extends TagMatcher
{

/**
* @var Matcher
*/
Expand Down Expand Up @@ -37,4 +39,5 @@ protected function matchesSafelyWithDiagnosticDescription($item, Description $mi
{
return $this->matcher->matches($item->textContent);
}

}
3 changes: 2 additions & 1 deletion src/XmlNodeRecursiveIterator.php
Expand Up @@ -2,9 +2,9 @@

namespace WMDE\HamcrestHtml;


class XmlNodeRecursiveIterator extends \ArrayIterator
{

public function __construct(\DOMNodeList $nodeList)
{
$queue = $this->addElementsToQueue([], $nodeList);
Expand All @@ -29,4 +29,5 @@ private function addElementsToQueue(array $queue, \DOMNodeList $nodeList)

return $queue;
}

}
1 change: 1 addition & 0 deletions src/functions.php
@@ -1,4 +1,5 @@
<?php

use Hamcrest\Matcher;

if (!function_exists('htmlPiece')) {
Expand Down
2 changes: 2 additions & 0 deletions tests/ComplexTagMatcherTest.php
Expand Up @@ -10,6 +10,7 @@
*/
class ComplexTagMatcherTest extends \PHPUnit_Framework_TestCase
{

/**
* @test
*/
Expand Down Expand Up @@ -136,4 +137,5 @@ public function toleratesExtraSpacesInClassDescription() {
assertThat($html, is(htmlPiece(havingChild(
ComplexTagMatcher::tagMatchingOutline('<input class=" class1 "/>')))));
}

}
2 changes: 2 additions & 0 deletions tests/FunctionsTest.php
Expand Up @@ -7,6 +7,7 @@

class FunctionsTest extends \PHPUnit_Framework_TestCase
{

/**
* @test
*/
Expand Down Expand Up @@ -197,4 +198,5 @@ public function dataProvider_ElementDoesNotExist()
],
];
}

}
1 change: 1 addition & 0 deletions tests/HtmlMatcherTest.php
Expand Up @@ -9,6 +9,7 @@
*/
class HtmlMatcherTest extends \PHPUnit_Framework_TestCase
{

/**
* @test
* @dataProvider dataProvider_HtmlTagNamesIntroducedInHtml5
Expand Down
2 changes: 2 additions & 0 deletions tests/XmlNodeRecursiveIteratorTest.php
Expand Up @@ -9,6 +9,7 @@
*/
class XmlNodeRecursiveIteratorTest extends \PHPUnit_Framework_TestCase
{

public function testIteratesAllElements_WhenFlatStructureGiven()
{
$DOMNodeList = $this->createDomNodeListFromHtml('<p></p>');
Expand Down Expand Up @@ -58,4 +59,5 @@ protected function collectTagNames($recursiveIterator)
}, $array);
return $tagNames;
}

}

0 comments on commit c0c472d

Please sign in to comment.