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 Apr 26, 2018
1 parent 3e9a718 commit 5c4a417
Show file tree
Hide file tree
Showing 76 changed files with 602 additions and 486 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
/composer.lock
/clover.xml
/tests/Zend/Filter/_files/Users
/tests/Zend/Filter/_files/Users
.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);
;
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ install:

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

Expand All @@ -34,15 +35,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=8f28da13e0ea0172cf806fdf90c46437edc8b2bda156e9849e9b2d2215df8cd1
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
30 changes: 24 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
},
"autoload": {
"psr-0": {
"Zend_": "src/"
}
"Zend_Filter_": "src/"
},
"classmap": [
"src/Zend/Filter.php"
]
},
"autoload-dev": {
"psr-0": {
Expand All @@ -40,7 +43,10 @@
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.9.2",
"jetbrains/phpstorm-stubs": "dev-phpstan",
"pear/archive_tar": "^1.4"
"pear/archive_tar": "^1.4",
"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 @@ -49,11 +55,23 @@
"exclude": ["/tests"]
},
"scripts": {
"test": "phpunit ./tests",
"test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
"phpstan": "phpstan analyze -l6 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l6 -c phpstan.neon --no-progress ./ --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
},
"suggest": {
"ext-iconv": "Optionally used in the Zend_Filter_HtmlEntities filter",
"ext-ctype": "Used in the Zend_Filter_Encrypt_Openssl filter",
"ext-mbstring": "Optionally used in the Zend_Filter_StringToLower/Upper filters",
"ext-mcrypt": "Used in the Zend_Filter_Encrypt_Mcrypt filter",
"ext-zlib": "Used in the Zend_Filter_Compress_Gz filter",
"ext-openssl": "Used in the Zend_Filter_Encrypt_Openssl filter",
"ext-bz2": "Used in the Zend_Filter_Compress_Bz2 and (optionally) in the Zend_Filter_Compress_Tar filters",
"ext-zip": "Used in the Zend_Filter_Compress_Zip filter",
"ext-rar": "Used in the Zend_Filter_Compress_Rar filter",
"ext-lzf": "Used in the Zend_Filter_Compress_Lzf filter",
"pear/archive_tar": "For the Zend_Filter_Compress_Tar filter",
"diablomedia/zendframework1-filter-input": "Provides the separate Zend_Filter_Input component"
}
}
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: 6
configuration: phpstan.neon
phpunit:
metadata:
priority: 100
always_execute: true
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
parameters:
excludes_analyse:
- %rootDir%/../../../tests/*
- %rootDir%/../../../vendor/*
bootstrap: %rootDir%/../../../phpstan-bootstrap.php
ignoreErrors:
- '#Casting to .+ something that.s already .+\.#'
Expand All @@ -10,4 +13,4 @@ parameters:
- '#Zend_Filter_.+::__construct\(\) does not call parent constructor from Zend_Filter_.+\.#'
- '#Variable \$file might not be defined\.#'
- '#Parameter \#1 \$p_filelist of method Archive_Tar::create\(\) expects array, array\|string given\.#'
- '#Parameter \#3 \$locale of static method Zend_Locale::getTranslation\(\) expects string\|Zend_Locale\|null, array given\.#'
- '#Parameter \#3 \$locale of static method Zend_Locale::getTranslation\(\) expects string\|Zend_Locale\|null, array given\.#'
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
20 changes: 20 additions & 0 deletions require-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"iconv",
"ctype_print",
"mb_internal_encoding", "mb_list_encodings", "mb_strtolower", "mb_strtoupper",
"Archive_Tar",
"mcrypt_list_algorithms", "mcrypt_list_modes", "mcrypt_module_self_test", "mcrypt_enc_get_iv_size", "MCRYPT_RAND",
"MCRYPT_DEV_URANDOM", "MCRYPT_DEV_RANDOM", "mcrypt_create_iv", "mcrypt_generic", "mcrypt_generic_deinit",
"mdecrypt_generic", "mcrypt_module_open", "mcrypt_module_close", "mcrypt_enc_get_supported_key_sizes", "mcrypt_enc_get_key_size", "mcrypt_generic_init",
"gzopen", "gzwrite", "gzclose", "gzdeflate", "gzcompress", "gzread", "gzinflate", "gzuncompress",
"openssl_pkey_get_public", "openssl_free_key", "openssl_pkey_get_private", "openssl_pkey_get_details", "openssl_seal", "openssl_open",
"bzopen", "bzwrite", "bzclose", "bzcompress", "bzread", "bzdecompress",
"ZipArchive",
"rar_open", "rar_list", "rar_close",
"lzf_compress", "lzf_decompress"
]
}
1 change: 0 additions & 1 deletion src/Zend/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
class Zend_Filter implements Zend_Filter_Interface
{

const CHAIN_APPEND = 'append';
const CHAIN_PREPEND = 'prepend';

Expand Down
16 changes: 8 additions & 8 deletions src/Zend/Filter/Alnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct($allowWhiteSpace = false)
{
if ($allowWhiteSpace instanceof Zend_Config) {
$allowWhiteSpace = $allowWhiteSpace->toArray();
} else if (is_array($allowWhiteSpace)) {
} elseif (is_array($allowWhiteSpace)) {
if (array_key_exists('allowwhitespace', $allowWhiteSpace)) {
$allowWhiteSpace = $allowWhiteSpace['allowwhitespace'];
} else {
Expand All @@ -80,12 +80,12 @@ public function __construct($allowWhiteSpace = false)
}

if (null === self::$_meansEnglishAlphabet) {
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array(
$this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
}

}

/**
Expand Down Expand Up @@ -124,9 +124,9 @@ public function filter($value)
if (!self::$_unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z0-9 match
$pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/';
} else if (self::$_meansEnglishAlphabet) {
} elseif (self::$_meansEnglishAlphabet) {
//The Alphabet means english alphabet.
$pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u';
$pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/u';
} else {
//The Alphabet means each language's alphabet.
$pattern = '/[^\p{L}\p{N}' . $whiteSpace . ']/u';
Expand Down
16 changes: 8 additions & 8 deletions src/Zend/Filter/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct($allowWhiteSpace = false)
{
if ($allowWhiteSpace instanceof Zend_Config) {
$allowWhiteSpace = $allowWhiteSpace->toArray();
} else if (is_array($allowWhiteSpace)) {
} elseif (is_array($allowWhiteSpace)) {
if (array_key_exists('allowwhitespace', $allowWhiteSpace)) {
$allowWhiteSpace = $allowWhiteSpace['allowwhitespace'];
} else {
Expand All @@ -80,12 +80,12 @@ public function __construct($allowWhiteSpace = false)
}

if (null === self::$_meansEnglishAlphabet) {
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
$this->_locale = new Zend_Locale('auto');
self::$_meansEnglishAlphabet = in_array(
$this->_locale->getLanguage(),
array('ja', 'ko', 'zh')
);
}

}

/**
Expand Down Expand Up @@ -124,9 +124,9 @@ public function filter($value)
if (!self::$_unicodeEnabled) {
// POSIX named classes are not supported, use alternative a-zA-Z match
$pattern = '/[^a-zA-Z' . $whiteSpace . ']/';
} else if (self::$_meansEnglishAlphabet) {
} elseif (self::$_meansEnglishAlphabet) {
//The Alphabet means english alphabet.
$pattern = '/[^a-zA-Z' . $whiteSpace . ']/u';
$pattern = '/[^a-zA-Z' . $whiteSpace . ']/u';
} else {
//The Alphabet means each language's alphabet.
$pattern = '/[^\p{L}' . $whiteSpace . ']/u';
Expand Down
4 changes: 2 additions & 2 deletions src/Zend/Filter/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function setType($type = null)
{
if (is_array($type)) {
$detected = 0;
foreach($type as $value) {
foreach ($type as $value) {
if (is_int($value)) {
$detected += $value;
} elseif (in_array($value, $this->_constants)) {
Expand Down Expand Up @@ -355,7 +355,7 @@ protected function _getLocalizedQuestion($value, $yes, $locale)
$str = Zend_Locale::getTranslation($question, 'question', $locale);
$str = explode(':', $str);
if (!empty($str)) {
foreach($str as $no) {
foreach ($str as $no) {
if (($no == $value) || (strtolower($no) == strtolower($value))) {
return $return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Zend/Filter/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($options)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (!is_array($options) || !array_key_exists('callback', $options)) {
} elseif (!is_array($options) || !array_key_exists('callback', $options)) {
$options = func_get_args();
$temp['callback'] = array_shift($options);
if (!empty($options)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Zend/Filter/Compress/Gz.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function compress($content)
gzwrite($file, $content);
gzclose($file);
$compressed = true;
} else if ($this->_options['mode'] == 'deflate') {
} elseif ($this->_options['mode'] == 'deflate') {
$compressed = gzdeflate($content, $this->getLevel());
} else {
$compressed = gzcompress($content, $this->getLevel());
Expand Down Expand Up @@ -177,21 +177,21 @@ public function decompress($content)
}

if (@file_exists($archive)) {
$handler = fopen($archive, "rb");
$handler = fopen($archive, 'rb');
if (!$handler) {
throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
}

fseek($handler, -4, SEEK_END);
$packet = fread($handler, 4);
$bytes = unpack("V", $packet);
$bytes = unpack('V', $packet);
$size = end($bytes);
fclose($handler);

$file = gzopen($archive, 'r');
$compressed = gzread($file, $size);
gzclose($file);
} else if ($mode == 'deflate') {
} elseif ($mode == 'deflate') {
$compressed = gzinflate($content);
} else {
$compressed = gzuncompress($content);
Expand Down
10 changes: 5 additions & 5 deletions src/Zend/Filter/Compress/Rar.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getArchive()
*/
public function setArchive($archive)
{
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
$archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
$this->_options['archive'] = (string) $archive;

return $this;
Expand Down Expand Up @@ -154,7 +154,7 @@ public function setTarget($target)
throw new Zend_Filter_Exception("The directory '$target' does not exist");
}

$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
$this->_options['target'] = (string) $target;
return $this;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public function decompress($content)
}

if (!$archive) {
throw new Zend_Filter_Exception("Error opening the RAR Archive");
throw new Zend_Filter_Exception('Error opening the RAR Archive');
}

$target = $this->getTarget();
Expand All @@ -216,10 +216,10 @@ public function decompress($content)

$filelist = rar_list($archive);
if (!$filelist) {
throw new Zend_Filter_Exception("Error reading the RAR Archive");
throw new Zend_Filter_Exception('Error reading the RAR Archive');
}

foreach($filelist as $file) {
foreach ($filelist as $file) {
$file->extract($target);
}

Expand Down
Loading

0 comments on commit 5c4a417

Please sign in to comment.