Skip to content

Commit

Permalink
Testing code climate's code sniffer plugin (#1)
Browse files Browse the repository at this point in the history
* Testing code climate's code sniffer plugin

* try force install?

* fixing style

* removing codeclimate config, adding grumphp
  • Loading branch information
jaydiablo committed Apr 21, 2018
1 parent d8d58d2 commit e7c967c
Show file tree
Hide file tree
Showing 57 changed files with 1,112 additions and 761 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);
;
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ branches:
master

install:
- echo "yes\nno\n" | pecl install apcu && sed -i 's/extension="apcu.so"//' ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- pecl install apcu_bc && sed -i 's/extension="apc.so"//' ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "yes\nno\n" | pecl install -f apcu && sed -i 's/extension="apcu.so"//' ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- pecl install -f apcu_bc && sed -i 's/extension="apc.so"//' ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- phpenv config-add travis-config.ini
- phpenv rehash
- travis_retry composer install --no-interaction --prefer-source
Expand All @@ -26,6 +26,7 @@ services:

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

Expand All @@ -40,15 +41,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=70a4fee74600bfc663f4738b3abcb5242031b596bf813ca7676cfc3d9d668bfc
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 @@ -19,8 +19,11 @@
},
"autoload": {
"psr-0": {
"Zend_": "src/"
}
"Zend_Cache_": "src/"
},
"classmap": [
"src/Zend/Cache.php"
]
},
"autoload-dev": {
"psr-0": {
Expand All @@ -37,7 +40,10 @@
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.9.2",
"jetbrains/phpstorm-stubs": "dev-phpstan"
"jetbrains/phpstorm-stubs": "dev-phpstan",
"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 @@ -46,9 +52,10 @@
"exclude": ["/tests"]
},
"scripts": {
"test": "phpunit ./tests",
"test-with-coverage": "phpunit --coverage-clover=clover.xml ./tests",
"phpstan": "phpstan analyze -l5 -c phpstan.neon --no-progress ./src --ansi"
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -l5 -c phpstan.neon --no-progress ./ --ansi",
"style-check": "php-cs-fixer fix --dry-run -vv"
},
"suggest": {
"ext-apc": "Used in the APC Backend",
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: 5
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:
- '#Zend_Cache_.+::__construct\(\) does not call parent constructor from Zend_Cache_Core\.#'
Expand All @@ -15,4 +18,4 @@ parameters:
- '#Strict comparison using === between string and null will always evaluate to false\.#'
- '#Strict comparison using !== between string and null will always evaluate to true\.#'
- '#Casting to .+ something that.s already .+\.#'
- '#Parameter \#1 \$data of method Zend_Cache_Backend_File::_hash\(\) expects string, false\|string given\.#'
- '#Parameter \#1 \$data of method Zend_Cache_Backend_File::_hash\(\) expects string, false\|string given\.#'
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
stderr="true"
colors="true"
bootstrap="./phpunit-bootstrap.php">
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
Expand Down
16 changes: 16 additions & 0 deletions require-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"accelerator_get_configuration", "accelerator_license_info",
"apc_clear_cache", "apc_delete", "apc_fetch", "APC_ITER_KEY", "apc_sma_info", "apc_store", "APCIterator",
"hash",
"Memcache", "MEMCACHE_COMPRESSED",
"Memcached",
"output_cache_get", "output_cache_put", "output_cache_remove_key",
"wincache_ucache_clear", "wincache_ucache_delete", "wincache_ucache_get", "wincache_ucache_info", "wincache_ucache_meminfo", "wincache_ucache_set",
"XC_TYPE_VAR", "xcache_clear_cache", "xcache_count", "xcache_get", "xcache_isset", "xcache_set", "xcache_unset",
"zend_disk_cache_clear", "zend_disk_cache_delete", "zend_disk_cache_fetch", "zend_disk_cache_store", "zend_shm_cache_clear", "zend_shm_cache_delete", "zend_shm_cache_fetch", "zend_shm_cache_store"
]
}
61 changes: 47 additions & 14 deletions src/Zend/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ abstract class Zend_Cache
*
* @var array
*/
public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'WinCache');
public static $standardExtendedBackends = array(
'File',
'Apc',
'TwoLevels',
'Memcached',
'Libmemcached',
'WinCache'
);

/**
* Only for backward compatibility (may be removed in next major release)
Expand All @@ -64,7 +71,16 @@ abstract class Zend_Cache
* @var array
* @deprecated
*/
public static $availableBackends = array('File', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'WinCache', 'TwoLevels');
public static $availableBackends = array(
'File',
'Memcached',
'Libmemcached',
'Apc',
'ZendPlatform',
'Xcache',
'WinCache',
'TwoLevels'
);

/**
* Consts for clean() method
Expand All @@ -82,21 +98,35 @@ abstract class Zend_Cache
* @param string|Zend_Cache_Backend $backend backend name (string) or Zend_Cache_Backend_ object
* @param array $frontendOptions associative array of options for the corresponding frontend constructor
* @param array $backendOptions associative array of options for the corresponding backend constructor
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
* @param boolean $autoload if true, there will no require_once for backend and frontend (useful only for custom backends/frontends)
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ;
* if false, the frontend argument is used as the end of
* "Zend_Cache_Frontend_[...]" class name
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ;
* if false, the backend argument is used as the end of
* "Zend_Cache_Backend_[...]" class name
* @param boolean $autoload if true, there will no require_once for backend and frontend
* (useful only for custom backends/frontends)
* @throws Zend_Cache_Exception
* @return Zend_Cache_Core
*/
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
{
public static function factory(
$frontend,
$backend,
$frontendOptions = array(),
$backendOptions = array(),
$customFrontendNaming = false,
$customBackendNaming = false,
$autoload = false
) {
if (is_string($backend)) {
$backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
} else {
if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
$backendObject = $backend;
} else {
self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
self::throwException(
'backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface'
);
// this return will never be hit
return;
}
Expand Down Expand Up @@ -128,12 +158,12 @@ public static function factory($frontend, $backend, $frontendOptions = array(),
public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
{
if (!$customBackendNaming) {
$backend = self::_normalizeName($backend);
$backend = self::_normalizeName($backend);
}
if (in_array($backend, Zend_Cache::$standardBackends)) {
// we use a standard backend
$backendClass = 'Zend_Cache_Backend_' . $backend;
// security controls are explicit
// security controls are explicit
} else {
// we use a custom backend
if (!preg_match('~^[\w\\\\]+$~D', $backend)) {
Expand Down Expand Up @@ -165,16 +195,20 @@ public static function _makeBackend($backend, $backendOptions, $customBackendNam
* @param boolean $autoload
* @return Zend_Cache_Core
*/
public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
{
public static function _makeFrontend(
$frontend,
$frontendOptions = array(),
$customFrontendNaming = false,
$autoload = false
) {
if (!$customFrontendNaming) {
$frontend = self::_normalizeName($frontend);
}
if (in_array($frontend, self::$standardFrontends)) {
// we use a standard frontend
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
$frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
// security controls are explicit
// security controls are explicit
} else {
// we use a custom frontend
if (!preg_match('~^[\w\\\\]+$~D', $frontend)) {
Expand Down Expand Up @@ -247,5 +281,4 @@ private static function _isReadable($filename)
@fclose($fh);
return true;
}

}
7 changes: 4 additions & 3 deletions src/Zend/Cache/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function __construct(array $options = array())
*/
public function setDirectives($directives)
{
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
if (!is_array($directives)) {
Zend_Cache::throwException('Directives parameter must be an array');
}
foreach ($directives as $name => $value) {
if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name");
Expand All @@ -84,7 +86,6 @@ public function setDirectives($directives)
if (array_key_exists($name, $this->_directives)) {
$this->_directives[$name] = $value;
}

}

$this->_loggerSanity();
Expand Down Expand Up @@ -200,7 +201,7 @@ public function getTmpDir()
}
}
// Attemp to detect by creating a temporary file
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
$tempFile = tempnam(md5(uniqid(rand(), true)), '');
if ($tempFile) {
$dir = realpath(dirname($tempFile));
unlink($tempFile);
Expand Down
Loading

0 comments on commit e7c967c

Please sign in to comment.