Skip to content

Commit

Permalink
adding grumphp, php-cs-fixer, fixing style
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Apr 18, 2018
1 parent b39b37d commit f783cf6
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/composer.lock
/clover.xml
/clover.xml
.php_cs.cache
22 changes: 22 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->files()
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PHPUnit60Migration:risky' => true,
'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true],
'single_quote' => true,
'array_syntax' => ['syntax' => 'long'],
'concat_space' => ['spacing' => 'one'],
'psr0' => true
])
->setUsingCache(true)
->setFinder($finder);
;
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ install:

stages:
- test
- style check
- phpstan analysis
- test with coverage

Expand All @@ -37,6 +38,11 @@ jobs:
allow_failures:
- php: nightly
include:
- stage: style check
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=false
script:
- composer style-check
- stage: phpstan analysis
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=false
Expand Down
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"prefer-stable": true,
"require": {
"php": ">=7.0.0",
"ext-dom": "*",
"ext-libxml": "*",
"ext-SimpleXML": "*",
"diablomedia/zendframework1-exception": "^1.0.0"
},
"autoload": {
Expand All @@ -26,14 +29,18 @@
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.9.2",
"friendsofphp/php-cs-fixer": "^2.11",
"maglnet/composer-require-checker": "^0.1.6 | ^0.2.1",
"phpro/grumphp": "^0.14.0"
},
"archive": {
"exclude": ["/tests"]
},
"scripts": {
"test": "phpunit ./tests",
"test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
"phpstan": "phpstan analyze -l7 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l7 -c phpstan.neon --no-progress ./ --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
}
}
16 changes: 16 additions & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# grumphp.yml
parameters:
tasks:
composer:
strict: true
composer_require_checker: ~
phpcsfixer2:
allow_risky: true
config: .php_cs
phpstan:
level: 7
configuration: phpstan.neon
phpunit:
metadata:
priority: 100
always_execute: true
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
parameters:
excludes_analyse:
- %rootDir%/../../../tests/*
- %rootDir%/../../../vendor/*
ignoreErrors:
- '#Variable \$loadEntities might not be defined\.#'
- '#Variable \$useInternalXmlErrors might not be defined\.#'
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
backupGlobals="true"
stderr="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
Expand Down
3 changes: 2 additions & 1 deletion src/Zend/Xml/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Xml_Exception extends Zend_Exception
{}
{
}
8 changes: 4 additions & 4 deletions src/Zend/Xml/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public static function scan($xml, DOMDocument $dom = null)

if (null === $dom) {
$simpleXml = true;
$dom = new DOMDocument();
$dom = new DOMDocument();
}

if (!self::isPhpFpm()) {
$loadEntities = libxml_disable_entity_loader(true);
$loadEntities = libxml_disable_entity_loader(true);
$useInternalXmlErrors = libxml_use_internal_errors(true);
}

Expand Down Expand Up @@ -270,7 +270,7 @@ protected static function detectXmlEncoding($xml, $fileEncoding)
$quote = call_user_func($generator, '"');
$close = call_user_func($generator, '>');

$closePos = strpos($xml, $close);
$closePos = strpos($xml, $close);
if (false === $closePos) {
return array($fileEncoding);
}
Expand All @@ -282,7 +282,7 @@ protected static function detectXmlEncoding($xml, $fileEncoding)
return array($fileEncoding);
}

$encPos += strlen($encAttr);
$encPos += strlen($encAttr);
$quotePos = strpos($xml, $quote, $encPos);
if (false === $quotePos) {
return array($fileEncoding);
Expand Down
7 changes: 3 additions & 4 deletions tests/Zend/Xml/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testScanSimpleXmlResult()

public function testScanDom()
{
$dom = new DOMDocument('1.0');
$dom = new DOMDocument('1.0');
$result = Zend_Xml_Security::scan($this->_getXml(), $dom);
$this->assertTrue($result instanceof DOMDocument);
$node = $result->getElementsByTagName('result')->item(0);
Expand All @@ -97,7 +97,7 @@ public function testScanInvalidXmlDom()
<foo>test</bar>
XML;

$dom = new DOMDocument('1.0');
$dom = new DOMDocument('1.0');
$result = Zend_Xml_Security::scan($xml, $dom);
$this->assertFalse($result);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public function testScanXmlWithDTD()
</results>
XML;

$dom = new DOMDocument('1.0');
$dom = new DOMDocument('1.0');
$result = Zend_Xml_Security::scan($xml, $dom);
$this->assertTrue($result instanceof DOMDocument);
$this->assertTrue($result->validate());
Expand All @@ -140,6 +140,5 @@ protected function _getXml()
<result>test</result>
</results>
XML;

}
}

0 comments on commit f783cf6

Please sign in to comment.