Skip to content

Commit

Permalink
Testing a style-check, with style fixed (#2)
Browse files Browse the repository at this point in the history
* Testing a style-check, with style fixed

* adding grumphp, removing phpcs
  • Loading branch information
jaydiablo committed Apr 23, 2018
1 parent e25c966 commit 5e9552d
Show file tree
Hide file tree
Showing 40 changed files with 297 additions and 202 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
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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"
},
"archive": {
"exclude": ["/tests"]
Expand All @@ -49,8 +52,9 @@
],
"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-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"
},
"suggest": {
"diablomedia/zendframework1-log-writer-db": "Writer that uses Zend_Db",
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: 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/*
bootstrap: %rootDir%/../../../phpstan-bootstrap.php
ignoreErrors:
- '#Casting to string something that.s already string\.#'
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
9 changes: 9 additions & 0 deletions require-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"symbol-whitelist" : [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"DOMDocument", "DOMElement",
"zend_monitor_custom_event", "monitor_custom_event"
]
}
65 changes: 34 additions & 31 deletions src/Zend/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
*/
class Zend_Log
{
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages

/**
* @var array of priorities where the keys are the
Expand Down Expand Up @@ -91,7 +91,7 @@ class Zend_Log
*
* @var callable
*/
protected $_origErrorHandler = null;
protected $_origErrorHandler = null;

/**
*
Expand All @@ -103,13 +103,13 @@ class Zend_Log
*
* @var array|boolean
*/
protected $_errorHandlerMap = false;
protected $_errorHandlerMap = false;

/**
*
* @var string
*/
protected $_timestampFormat = 'c';
protected $_timestampFormat = 'c';

/**
* Class constructor. Create a new logger
Expand All @@ -118,7 +118,7 @@ class Zend_Log
*/
public function __construct(Zend_Log_Writer_Abstract $writer = null)
{
$r = new ReflectionClass($this);
$r = new ReflectionClass($this);
$this->_priorities = array_flip($r->getConstants());

if ($writer !== null) {
Expand All @@ -134,7 +134,7 @@ public function __construct(Zend_Log_Writer_Abstract $writer = null)
* @return Zend_Log
* @throws Zend_Log_Exception
*/
static public function factory($config = array())
public static function factory($config = array())
{
if ($config instanceof Zend_Config) {
$config = $config->toArray();
Expand Down Expand Up @@ -167,7 +167,7 @@ static public function factory($config = array())
if (!is_array(current($config))) {
$log->addWriter(current($config));
} else {
foreach($config as $writer) {
foreach ($config as $writer) {
$log->addWriter($writer);
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ protected function _constructFilterFromConfig($config)
$filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);

if (!$filter instanceof Zend_Log_Filter_Interface) {
$filterName = is_object($filter)
$filterName = is_object($filter)
? get_class($filter)
: 'The specified filter';
throw new Zend_Log_Exception("{$filterName} does not implement Zend_Log_Filter_Interface");
Expand All @@ -228,19 +228,19 @@ protected function _constructFilterFromConfig($config)
return $filter;
}

/**
* Construct formatter object from configuration array or Zend_Config object
*
* @param array|Zend_Config $config Zend_Config or Array
* @return Zend_Log_Formatter_Interface
* @throws Zend_Log_Exception
*/
/**
* Construct formatter object from configuration array or Zend_Config object
*
* @param array|Zend_Config $config Zend_Config or Array
* @return Zend_Log_Formatter_Interface
* @throws Zend_Log_Exception
*/
protected function _constructFormatterFromConfig($config)
{
$formatter = $this->_constructFromConfig('formatter', $config, $this->_defaultFormatterNamespace);

if (!$formatter instanceof Zend_Log_Formatter_Interface) {
$formatterName = is_object($formatter)
$formatterName = is_object($formatter)
? get_class($formatter)
: 'The specified formatter';
throw new Zend_Log_Exception($formatterName . ' does not implement Zend_Log_Formatter_Interface');
Expand Down Expand Up @@ -270,7 +270,7 @@ protected function _constructFromConfig($type, $config, $namespace)
);
}

$params = isset($config[ $type .'Params' ]) ? $config[ $type .'Params' ] : array();
$params = isset($config[ $type . 'Params' ]) ? $config[ $type . 'Params' ] : array();
$className = $this->getClassName($config, $type, $namespace);
if (!class_exists($className)) {
Zend_Loader::loadClass($className);
Expand Down Expand Up @@ -330,7 +330,8 @@ protected function getClassName($config, $type, $defaultNamespace)
*/
protected function _packEvent($message, $priority)
{
return array_merge(array(
return array_merge(
array(
'timestamp' => date($this->_timestampFormat),
'message' => $message,
'priority' => $priority,
Expand All @@ -348,7 +349,7 @@ protected function _packEvent($message, $priority)
public function __destruct()
{
/** @var Zend_Log_Writer_Abstract $writer */
foreach($this->_writers as $writer) {
foreach ($this->_writers as $writer) {
$writer->shutdown();
}
}
Expand All @@ -373,7 +374,7 @@ public function __call($method, $params)
throw new Zend_Log_Exception('Missing log message');
case 1:
$message = array_shift($params);
$extras = null;
$extras = null;
break;
default:
$message = array_shift($params);
Expand Down Expand Up @@ -479,11 +480,9 @@ public function addFilter($filter)
if (is_int($filter)) {
/** @see Zend_Log_Filter_Priority */
$filter = new Zend_Log_Filter_Priority($filter);

} elseif ($filter instanceof Zend_Config || is_array($filter)) {
$filter = $this->_constructFilterFromConfig($filter);

} elseif(! $filter instanceof Zend_Log_Filter_Interface) {
} elseif (! $filter instanceof Zend_Log_Filter_Interface) {
throw new Zend_Log_Exception('Invalid filter provided');
}

Expand Down Expand Up @@ -600,7 +599,11 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
} else {
$priority = Zend_Log::INFO;
}
$this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
$this->log(
$errstr,
$priority,
array('errno'=> $errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext)
);
}

if ($this->_origErrorHandler !== null) {
Expand Down
3 changes: 2 additions & 1 deletion src/Zend/Log/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
* @version $Id$
*/
class Zend_Log_Exception extends Zend_Exception
{}
{
}
2 changes: 1 addition & 1 deletion src/Zend/Log/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ interface Zend_Log_FactoryInterface
* @param array|Zend_Config $config
* @return Zend_Log_FactoryInterface
*/
static public function factory($config);
public static function factory($config);
}
5 changes: 2 additions & 3 deletions src/Zend/Log/Filter/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
abstract class Zend_Log_Filter_Abstract
implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface
abstract class Zend_Log_Filter_Abstract implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface
{
/**
* Validate and optionally convert the config to array
Expand All @@ -38,7 +37,7 @@ abstract class Zend_Log_Filter_Abstract
* @return array
* @throws Zend_Log_Exception
*/
static protected function _parseConfig($config)
protected static function _parseConfig($config)
{
if ($config instanceof Zend_Config) {
$config = $config->toArray();
Expand Down
9 changes: 6 additions & 3 deletions src/Zend/Log/Filter/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ public function __construct($regexp)
* @param array|Zend_Config $config
* @return Zend_Log_Filter_Message
*/
static public function factory($config)
public static function factory($config)
{
$config = self::_parseConfig($config);
$config = array_merge(array(
$config = array_merge(
array(
'regexp' => null
), $config);
),
$config
);

return new self(
$config['regexp']
Expand Down
9 changes: 6 additions & 3 deletions src/Zend/Log/Filter/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ public function __construct($priority, $operator = null)
* @param array|Zend_Config $config
* @return Zend_Log_Filter_Priority
*/
static public function factory($config)
public static function factory($config)
{
$config = self::_parseConfig($config);
$config = array_merge(array(
$config = array_merge(
array(
'priority' => null,
'operator' => null,
), $config);
),
$config
);

// Add support for constants
if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Zend/Log/Filter/Suppress.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function accept($event)
* @return Zend_Log_Filter_Suppress
* @throws Zend_Log_Exception
*/
static public function factory($config)
public static function factory($config)
{
return new self();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Zend/Log/Formatter/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
abstract class Zend_Log_Formatter_Abstract
implements Zend_Log_Formatter_Interface, Zend_Log_FactoryInterface
abstract class Zend_Log_Formatter_Abstract implements Zend_Log_Formatter_Interface, Zend_Log_FactoryInterface
{
}
Loading

0 comments on commit 5e9552d

Please sign in to comment.