Skip to content

Commit

Permalink
adding grumphp, php-cs-fixer, fixing style, narrowing namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydiablo committed Jun 3, 2018
1 parent c3f096e commit a2f69b3
Show file tree
Hide file tree
Showing 34 changed files with 441 additions and 323 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/composer.lock
/clover.xml
/tests/Zend/_files/zend_cache*
/tests/Zend/Translate/Adapter/_files/zend_cache*
/tests/Zend/Translate/Adapter/_files/zend_cache*
.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);
;
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,26 @@ 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
script:
- composer phpstan
- stage: test with coverage
php: 7.1
env: TMPDIR=/tmp USE_XDEBUG=true
env: TMPDIR=/tmp USE_XDEBUG=true CC_TEST_REPORTER_ID=9e6fb3c2f914008fe81124e4454a3d68f4af30a68bd783a356e50c157afd8559
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- composer test-with-coverage
after_success:
- bash <(curl -s https://codecov.io/bash) -f ./clover.xml
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
},
"autoload": {
"psr-0": {
"Zend_": "src/"
}
"Zend_Translate_": "src/"
},
"classmap": [
"src/Zend/Translate.php"
]
},
"autoload-dev": {
"psr-0": {
Expand All @@ -32,7 +35,10 @@
},
"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"
},
"include-path": [
"src/"
Expand All @@ -41,9 +47,10 @@
"exclude": ["/tests"]
},
"scripts": {
"test": "phpunit ./tests",
"test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
"phpstan": "phpstan analyze -l4 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l4 -c phpstan.neon --no-progress ./ --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
},
"suggest": {
"ext-xml": "Many of the translation adapters require this extension"
Expand Down
17 changes: 17 additions & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# grumphp.yml
parameters:
tasks:
composer:
strict: true
composer_require_checker:
config_file: require-checker-config.json
phpcsfixer2:
allow_risky: true
config: .php_cs
phpstan:
level: 4
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%/../../../vendor/*
- %rootDir%/../../../tests/*
ignoreErrors:
- '#Variable \$number might not be defined\.#'
- '#Variable \$plocale might not be defined\.#'
Expand Down
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
10 changes: 10 additions & 0 deletions require-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"xml_parser_create", "xml_set_object", "xml_parser_set_option", "XML_OPTION_CASE_FOLDING",
"xml_set_element_handler", "xml_set_character_data_handler", "xml_parse", "xml_error_string", "xml_get_error_code",
"xml_get_current_line_number", "xml_parser_free"
]
}
15 changes: 8 additions & 7 deletions src/Zend/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate {
class Zend_Translate
{
/**
* Adapter names constants
*/
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
} elseif (func_num_args() > 1) {
$args = func_get_args();
$options = array();
$options['adapter'] = array_shift($args);
Expand All @@ -77,7 +78,7 @@ public function __construct($options = array())
$opt = array_shift($args);
$options = array_merge($opt, $options);
}
} else if (!is_array($options)) {
} elseif (!is_array($options)) {
$options = array('adapter' => $options);
}

Expand All @@ -96,7 +97,7 @@ public function setAdapter($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
} elseif (func_num_args() > 1) {
$args = func_get_args();
$options = array();
$options['adapter'] = array_shift($args);
Expand All @@ -112,11 +113,11 @@ public function setAdapter($options = array())
$opt = array_shift($args);
$options = array_merge($opt, $options);
}
} else if (!is_array($options)) {
} elseif (!is_array($options)) {
$options = array('adapter' => $options);
}

if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($options['adapter']). '.php')) {
if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($options['adapter']) . '.php')) {
$options['adapter'] = 'Zend_Translate_Adapter_' . ucfirst($options['adapter']);
}

Expand All @@ -132,7 +133,7 @@ public function setAdapter($options = array())
unset($options['adapter']);
$this->_adapter = new $adapter($options);
if (!$this->_adapter instanceof Zend_Translate_Adapter) {
throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter");
throw new Zend_Translate_Exception('Adapter ' . $adapter . ' does not extend Zend_Translate_Adapter');
}
}

Expand Down
Loading

0 comments on commit a2f69b3

Please sign in to comment.