From 888e1de2307461fc54356700bae6fceab29c7da6 Mon Sep 17 00:00:00 2001 From: Brad Kent Date: Tue, 25 Apr 2023 09:48:10 -0500 Subject: [PATCH] coding standards (primarily Arrays.AlphabeticallySortedByKeys) --- phpcs.slevomat.xml | 7 +- phpcs.xml.dist | 4 - src/Backtrace/Normalizer.php | 6 +- src/Backtrace/SkipInternal.php | 2 +- src/Debug/AbstractDebug.php | 5 +- src/Debug/Abstraction/AbstractObject.php | 77 +++++---- .../Abstraction/AbstractObjectHelper.php | 3 +- .../AbstractObjectMethodParams.php | 2 +- .../Abstraction/AbstractObjectMethods.php | 7 +- .../Abstraction/AbstractObjectProperties.php | 27 ++- src/Debug/Abstraction/AbstractString.php | 2 +- src/Debug/Abstraction/Abstracter.php | 2 +- src/Debug/Abstraction/Abstraction.php | 8 + src/Debug/Collector/GuzzleMiddleware.php | 2 +- src/Debug/Collector/MySqli.php | 2 + src/Debug/Collector/OAuth.php | 6 +- src/Debug/Collector/Pdo.php | 2 +- src/Debug/Collector/SimpleCache.php | 2 +- src/Debug/Collector/SimpleCache/CallInfo.php | 2 +- src/Debug/Collector/SoapClient.php | 11 +- src/Debug/Collector/StatementInfo.php | 6 +- src/Debug/Config.php | 8 +- src/Debug/ConfigEvents.php | 6 +- src/Debug/Debug.php | 66 ++++---- src/Debug/Dump/Base.php | 6 +- src/Debug/Dump/BaseValue.php | 6 +- src/Debug/Dump/Html.php | 2 +- src/Debug/Dump/Html/HtmlObject.php | 2 +- src/Debug/Dump/Html/HtmlString.php | 4 +- src/Debug/Dump/Html/HtmlStringEncoded.php | 15 +- src/Debug/Dump/Html/ObjectMethods.php | 3 +- src/Debug/Dump/Html/ObjectProperties.php | 2 +- src/Debug/Dump/Html/Table.php | 2 +- src/Debug/Dump/Html/Value.php | 4 +- src/Debug/Dump/Text.php | 10 +- src/Debug/Dump/TextAnsi.php | 8 +- src/Debug/Dump/TextAnsiValue.php | 11 +- src/Debug/Dump/TextValue.php | 3 +- src/Debug/Framework/Cake4.php | 4 +- .../Framework/Laravel/EventsSubscriber.php | 2 +- src/Debug/Framework/Laravel/Middleware.php | 2 +- .../Framework/Laravel/ServiceProvider.php | 10 +- src/Debug/Framework/Slim2.php | 1 + .../DependencyInjection/BdkDebugExtension.php | 2 +- src/Debug/Framework/Yii1_1/Component.php | 4 +- src/Debug/Framework/Yii1_1/LogRoute.php | 20 +-- src/Debug/Framework/Yii2/LogTarget.php | 6 +- src/Debug/Framework/Yii2/Module.php | 9 +- src/Debug/InternalEvents.php | 4 +- src/Debug/LogEntry.php | 5 +- src/Debug/Method/Clear.php | 11 +- src/Debug/Method/Count.php | 2 +- src/Debug/Method/Group.php | 8 +- src/Debug/Method/GroupStack.php | 4 +- src/Debug/Method/Helper.php | 4 +- src/Debug/Method/Profile.php | 13 +- src/Debug/Method/Table.php | 4 +- src/Debug/Method/Time.php | 6 +- src/Debug/Plugin/AssertSettingTrait.php | 2 +- src/Debug/Plugin/CustomMethod/General.php | 10 +- src/Debug/Plugin/Highlight.php | 2 +- src/Debug/Plugin/LogEnv.php | 10 +- src/Debug/Plugin/LogPhp.php | 8 +- src/Debug/Plugin/LogReqRes.php | 2 +- src/Debug/Psr3/Logger.php | 5 +- src/Debug/Route/ChromeLogger.php | 5 +- src/Debug/Route/Firephp.php | 4 +- src/Debug/Route/Html.php | 4 +- src/Debug/Route/Html/ErrorSummary.php | 8 +- src/Debug/Route/Html/Tabs.php | 6 +- src/Debug/Route/Script.php | 2 +- src/Debug/Route/Wamp.php | 7 +- src/Debug/ServiceProvider.php | 2 +- src/Debug/Utility/ErrorLevel.php | 5 +- src/Debug/Utility/FileTree.php | 8 +- src/Debug/Utility/Html.php | 6 +- src/Debug/Utility/Php.php | 2 +- src/Debug/Utility/PhpDoc.php | 49 +++--- src/Debug/Utility/PhpDocBase.php | 5 +- src/Debug/Utility/SerializeLog.php | 44 +++-- src/Debug/Utility/StopWatch.php | 2 +- src/Debug/Utility/StringUtil.php | 2 +- src/Debug/Utility/UseStatements.php | 4 +- src/Debug/Utility/Utf8Buffer.php | 10 +- src/Debug/Utility/Utf8Dump.php | 1 + src/Debug/Utility/Utility.php | 12 +- src/ErrorHandler/Error.php | 32 ++-- src/ErrorHandler/ErrorHandler.php | 6 +- src/ErrorHandler/Plugin/Emailer.php | 2 +- src/ErrorHandler/Plugin/Stats.php | 4 +- src/ErrorHandler/Plugin/StatsStoreFile.php | 12 +- src/HttpMessage/AbstractServerRequest.php | 14 +- src/HttpMessage/AssertionTrait.php | 2 +- src/HttpMessage/UploadedFile.php | 1 + src/HttpMessage/UriUtils.php | 4 +- tests/Debug/Abstraction/AbstractionTest.php | 10 +- tests/Debug/ChannelTest.php | 6 +- tests/Debug/Collector/SimpleCacheTest.php | 2 +- tests/Debug/DebugTest.php | 1 + tests/Debug/DebugTestFramework.php | 16 +- tests/Debug/Fixture/TestBase.php | 13 ++ tests/Debug/Helper.php | 42 +++-- tests/Debug/InternalEventsTest.php | 1 + tests/Debug/Method/ClearTest.php | 16 +- tests/Debug/Method/GroupTest.php | 19 ++- tests/Debug/Method/MethodTest.php | 2 +- .../Debug/Method/PluginMethodGeneralTest.php | 16 +- tests/Debug/Plugin/LogFilesTest.php | 4 +- tests/Debug/Plugin/RedactionTest.php | 6 +- tests/Debug/Route/EmailTest.php | 2 +- tests/Debug/SubstitutionTest.php | 15 +- tests/Debug/Type/ArrayTest.php | 1 + tests/Debug/Type/BasicTest.php | 2 +- tests/Debug/Type/EnumTest.php | 5 +- tests/Debug/Type/ObjectTest.php | 39 ++--- tests/Debug/Type/StringTest.php | 37 +++-- tests/Debug/Utility/FileTreeTest.php | 14 +- tests/Debug/Utility/PhpDocTest.php | 154 +++++++++--------- tests/Debug/Utility/SerializeLogTest.php | 28 ++-- tests/Debug/Utility/Utf8Test.php | 4 +- tests/HttpMessage/UriUtilsTest.php | 2 +- 121 files changed, 642 insertions(+), 583 deletions(-) diff --git a/phpcs.slevomat.xml b/phpcs.slevomat.xml index 268fde1d..9b0603fd 100644 --- a/phpcs.slevomat.xml +++ b/phpcs.slevomat.xml @@ -42,7 +42,12 @@ - + + + + + + diff --git a/phpcs.xml.dist b/phpcs.xml.dist index f3c96b60..ff3dc378 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,10 +14,6 @@ --> - - diff --git a/src/Backtrace/Normalizer.php b/src/Backtrace/Normalizer.php index 6b47e81a..313d148b 100644 --- a/src/Backtrace/Normalizer.php +++ b/src/Backtrace/Normalizer.php @@ -32,13 +32,13 @@ class Normalizer * @var array */ private static $internalFuncs = array( - '{closure}' => false, 'include' => false, 'include_once' => false, 'require' => false, 'require_once' => false, 'trigger_error' => false, 'user_error' => false, + '{closure}' => false, ); /** @@ -123,7 +123,7 @@ private static function normalizeFrameA(array $frame) self::$backtraceTemp[$count - 1]['line'] = $frame['line']; return false; } - if ($frame['class'] === 'ReflectionMethod' && \in_array($frame['function'], array('invoke','invokeArgs'), true)) { + if ($frame['class'] === 'ReflectionMethod' && \in_array($frame['function'], array('invoke', 'invokeArgs'), true)) { return false; } if ($frame['include_filename']) { @@ -151,7 +151,7 @@ private static function normalizeFrameFile(array $frame, array $frameNext) // use file/line from next frame $frame = \array_merge( $frame, - \array_intersect_key($frameNext, \array_flip(array('file','line'))) + \array_intersect_key($frameNext, \array_flip(array('file', 'line'))) ); } elseif (\preg_match($regex, $frame['file'], $matches)) { // reported line = line within eval diff --git a/src/Backtrace/SkipInternal.php b/src/Backtrace/SkipInternal.php index 9fa44489..3d4ee367 100644 --- a/src/Backtrace/SkipInternal.php +++ b/src/Backtrace/SkipInternal.php @@ -193,7 +193,7 @@ private static function isSkippable($frame, $levelMax) if (\in_array($frame['function'], array('__call', '__callStatic'), true)) { return true; } - if ($class === 'ReflectionMethod' && \in_array($frame['function'], array('invoke','invokeArgs'), true)) { + if ($class === 'ReflectionMethod' && \in_array($frame['function'], array('invoke', 'invokeArgs'), true)) { return true; } return static::isSubclassOfInternal($frame, $levelMax); diff --git a/src/Debug/AbstractDebug.php b/src/Debug/AbstractDebug.php index 063b7557..db737f64 100644 --- a/src/Debug/AbstractDebug.php +++ b/src/Debug/AbstractDebug.php @@ -280,9 +280,10 @@ protected function appendLog(LogEntry $logEntry) if (!$this->cfg['collect'] && !$logEntry['forcePublish']) { return false; } + $cfg = $logEntry->getMeta('cfg'); $cfgRestore = array(); - if (isset($logEntry['meta']['cfg'])) { - $cfgRestore = $this->setCfg($logEntry['meta']['cfg']); + if ($cfg) { + $cfgRestore = $this->setCfg($cfg); $logEntry->setMeta('cfg', null); } $logEntry->crate(); diff --git a/src/Debug/Abstraction/AbstractObject.php b/src/Debug/Abstraction/AbstractObject.php index ef6dd288..1d9ee471 100644 --- a/src/Debug/Abstraction/AbstractObject.php +++ b/src/Debug/Abstraction/AbstractObject.php @@ -63,39 +63,39 @@ class AbstractObject extends AbstractComponent const PARAM_ATTRIBUTE_COLLECT = 1048576; const PARAM_ATTRIBUTE_OUTPUT = 2097152; // 2^21 - public static $cfgFlags = array( + public static $cfgFlags = array( // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder // GENERAL - 'phpDocCollect' => self::PHPDOC_COLLECT, - 'phpDocOutput' => self::PHPDOC_OUTPUT, + 'brief' => self::BRIEF, 'objAttributeCollect' => self::OBJ_ATTRIBUTE_COLLECT, 'objAttributeOutput' => self::OBJ_ATTRIBUTE_OUTPUT, + 'phpDocCollect' => self::PHPDOC_COLLECT, + 'phpDocOutput' => self::PHPDOC_OUTPUT, 'toStringOutput' => self::TO_STRING_OUTPUT, - 'brief' => self::BRIEF, - - // CONSTANTS - 'constCollect' => self::CONST_COLLECT, - 'constOutput' => self::CONST_OUTPUT, - 'constAttributeCollect' => self::CONST_ATTRIBUTE_COLLECT, - 'constAttributeOutput' => self::CONST_ATTRIBUTE_OUTPUT, // CASE - 'caseCollect' => self::CASE_COLLECT, - 'caseOutput' => self::CASE_OUTPUT, 'caseAttributeCollect' => self::CASE_ATTRIBUTE_COLLECT, 'caseAttributeOutput' => self::CASE_ATTRIBUTE_OUTPUT, + 'caseCollect' => self::CASE_COLLECT, + 'caseOutput' => self::CASE_OUTPUT, - // PROPERTIES - 'propAttributeCollect' => self::PROP_ATTRIBUTE_COLLECT, - 'propAttributeOutput' => self::PROP_ATTRIBUTE_OUTPUT, + // CONSTANTS + 'constAttributeCollect' => self::CONST_ATTRIBUTE_COLLECT, + 'constAttributeOutput' => self::CONST_ATTRIBUTE_OUTPUT, + 'constCollect' => self::CONST_COLLECT, + 'constOutput' => self::CONST_OUTPUT, // METHODS - 'methodCollect' => self::METHOD_COLLECT, - 'methodOutput' => self::METHOD_OUTPUT, 'methodAttributeCollect' => self::METHOD_ATTRIBUTE_COLLECT, 'methodAttributeOutput' => self::METHOD_ATTRIBUTE_OUTPUT, + 'methodCollect' => self::METHOD_COLLECT, 'methodDescOutput' => self::METHOD_DESC_OUTPUT, + 'methodOutput' => self::METHOD_OUTPUT, 'paramAttributeCollect' => self::PARAM_ATTRIBUTE_COLLECT, 'paramAttributeOutput' => self::PARAM_ATTRIBUTE_OUTPUT, + + // PROPERTIES + 'propAttributeCollect' => self::PROP_ATTRIBUTE_COLLECT, + 'propAttributeOutput' => self::PROP_ATTRIBUTE_OUTPUT, ); public $helper; @@ -111,7 +111,7 @@ class AbstractObject extends AbstractComponent * * @var array Array of key/values */ - protected static $values = array( + protected static $values = array( // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder 'type' => Abstracter::TYPE_OBJECT, 'attributes' => array(), 'cfgFlags' => 0, @@ -176,24 +176,29 @@ public function __construct(Abstracter $abstracter) public function getAbstraction($obj, $method = null, $hist = array()) { $reflector = $this->debug->php->getReflector($obj); - $abs = new Abstraction(Abstracter::TYPE_OBJECT, \array_merge(self::$values, array( - 'cfgFlags' => $this->getCfgFlags(), - 'className' => $reflector->getName(), - 'debugMethod' => $method, - 'isAnonymous' => PHP_VERSION_ID >= 70000 && $reflector->isAnonymous(), - 'isExcluded' => $hist && $this->isExcluded($obj), // don't exclude if we're debugging directly - 'isFinal' => $reflector->isFinal(), - 'isRecursion' => \in_array($obj, $hist, true), - 'scopeClass' => $this->getScopeClass($hist), - 'viaDebugInfo' => $this->cfg['useDebugInfo'] && $reflector->hasMethod('__debugInfo'), - // these are temporary values available during abstraction - 'collectPropertyValues' => true, - 'fullyQualifyPhpDocType' => $this->cfg['fullyQualifyPhpDocType'], - 'hist' => $hist, - 'isTraverseOnly' => false, - 'propertyOverrideValues' => array(), - 'reflector' => $reflector, - ))); + $abs = new Abstraction(Abstracter::TYPE_OBJECT, \array_merge( + self::$values, + array( + 'cfgFlags' => $this->getCfgFlags(), + 'className' => $reflector->getName(), + 'debugMethod' => $method, + 'isAnonymous' => PHP_VERSION_ID >= 70000 && $reflector->isAnonymous(), + 'isExcluded' => $hist && $this->isExcluded($obj), // don't exclude if we're debugging directly + 'isFinal' => $reflector->isFinal(), + 'isRecursion' => \in_array($obj, $hist, true), + 'scopeClass' => $this->getScopeClass($hist), + 'viaDebugInfo' => $this->cfg['useDebugInfo'] && $reflector->hasMethod('__debugInfo'), + ), + array( + // these are temporary values available during abstraction + 'collectPropertyValues' => true, + 'fullyQualifyPhpDocType' => $this->cfg['fullyQualifyPhpDocType'], + 'hist' => $hist, + 'isTraverseOnly' => false, + 'propertyOverrideValues' => array(), + 'reflector' => $reflector, + ) + )); $abs['hist'][] = $obj; $abs->setSubject($obj); $this->doAbstraction($abs); diff --git a/src/Debug/Abstraction/AbstractObjectHelper.php b/src/Debug/Abstraction/AbstractObjectHelper.php index e14eb347..fb3e810d 100644 --- a/src/Debug/Abstraction/AbstractObjectHelper.php +++ b/src/Debug/Abstraction/AbstractObjectHelper.php @@ -49,6 +49,7 @@ public function getAttributes(Reflector $reflector) return array(); } return \array_map(static function (ReflectionAttribute $attribute) { + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return array( 'name' => $attribute->getName(), 'arguments' => $attribute->getArguments(), @@ -81,8 +82,8 @@ public function getPhpDocVar(Reflector $reflector) $name = $reflector->name; $phpDoc = $this->phpDoc->getParsed($reflector); $info = array( - 'type' => null, 'desc' => $phpDoc['summary'], + 'type' => null, ); if (!isset($phpDoc['var'])) { return $info; diff --git a/src/Debug/Abstraction/AbstractObjectMethodParams.php b/src/Debug/Abstraction/AbstractObjectMethodParams.php index ebafc19f..71c34c2e 100644 --- a/src/Debug/Abstraction/AbstractObjectMethodParams.php +++ b/src/Debug/Abstraction/AbstractObjectMethodParams.php @@ -295,7 +295,7 @@ private function phpDocParamValue($param, $className = null) return Abstracter::UNDEFINED; } $defaultValue = $param['defaultValue']; - if (\in_array($defaultValue, array('true','false','null'), true)) { + if (\in_array($defaultValue, array('true', 'false', 'null'), true)) { return \json_decode($defaultValue); } if (\is_numeric($defaultValue)) { diff --git a/src/Debug/Abstraction/AbstractObjectMethods.php b/src/Debug/Abstraction/AbstractObjectMethods.php index b61437f1..01c034ca 100644 --- a/src/Debug/Abstraction/AbstractObjectMethods.php +++ b/src/Debug/Abstraction/AbstractObjectMethods.php @@ -43,8 +43,8 @@ class AbstractObjectMethods 'summary' => null, ), 'return' => array( - 'type' => null, 'desc' => null, + 'type' => null, ), 'visibility' => 'public', // public | private | protected | magic ); @@ -265,7 +265,6 @@ private function addViaReflection(Abstraction $abs) } unset($info['phpDoc']['param']); unset($info['phpDoc']['return']); - \ksort($info['phpDoc']); $methodName = $refMethod->getName(); $methods[$methodName] = $info; } @@ -277,7 +276,7 @@ private function addViaReflection(Abstraction $abs) * * @param Abstraction $abs Object Abstraction instance * @param array $phpDocMethod parsed phpdoc method info - * @param string $inheritedFrom classname or null + * @param string $inheritedFrom class-name or null * * @return array */ @@ -313,7 +312,7 @@ private function buildMethodPhpDoc(Abstraction $abs, $phpDocMethod, $inheritedFr private function buildMethodRef(Abstraction $abs, ReflectionMethod $refMethod) { $obj = $abs->getSubject(); - // get_class() returns "raw" classname + // get_class() returns "raw" class-name // could be stdClass@anonymous/filepath.php:6$2e // $abs['className'] is a "friendly" name ... just stdClass@anonymous $className = \is_object($obj) diff --git a/src/Debug/Abstraction/AbstractObjectProperties.php b/src/Debug/Abstraction/AbstractObjectProperties.php index bcab4c40..717722c0 100644 --- a/src/Debug/Abstraction/AbstractObjectProperties.php +++ b/src/Debug/Abstraction/AbstractObjectProperties.php @@ -35,6 +35,8 @@ class AbstractObjectProperties 'attributes' => array(), 'debugInfoExcluded' => false, // true if not included in __debugInfo 'desc' => null, // from phpDoc + 'forceShow' => false, // initially show the property/value (even if protected or private) + // if value is an array, expand it 'inheritedFrom' => null, // populated only if inherited // not populated if extended/redefined 'isPromoted' => false, @@ -43,8 +45,6 @@ class AbstractObjectProperties 'originallyDeclared' => null, // populated only if originally declared in ancestor 'overrides' => null, // previous ancestor where property is defined // populated only if we're overriding - 'forceShow' => false, // initially show the property/value (even if protected or private) - // if value is an array, expand it 'type' => null, 'value' => Abstracter::UNDEFINED, 'valueFrom' => 'value', // 'value' | 'debugInfo' | 'debug' @@ -117,7 +117,7 @@ public function __construct(Abstracter $abstracter, AbstractObjectHelper $helper } /** - * Add property info/values to abstraction + * Add property instance info/values to abstraction * * @param Abstraction $abs Object Abstraction instance * @@ -166,9 +166,9 @@ private function addClosure(Abstraction $abs) $obj = $abs->getSubject(); $ref = new ReflectionFunction($obj); $abs['definition'] = array( + 'extensionName' => $ref->getExtensionName(), 'fileName' => $ref->getFileName(), 'startLine' => $ref->getStartLine(), - 'extensionName' => $ref->getExtensionName(), ); $abs['properties']['debug.file'] = static::buildPropValues(array( 'type' => Abstracter::TYPE_STRING, @@ -337,10 +337,9 @@ private function addViaPhpDoc(Abstraction $abs) $inheritedFrom = $this->addViaPhpDocInherit($abs); $haveMagic = $inheritedFrom !== null; } - if (!$haveMagic) { - return; + if ($haveMagic) { + $this->addViaPhpDocIter($abs, $inheritedFrom); } - $this->addViaPhpDocIter($abs, $inheritedFrom); } /** @@ -360,7 +359,6 @@ private function addViaPhpDocInherit(Abstraction $abs) if (!$tagIntersect) { continue; } - // $haveMagic = true; $inheritedFrom = $reflector->getName(); $abs['phpDoc'] = \array_merge( $abs['phpDoc'], @@ -448,8 +446,8 @@ private function buildPropViaPhpDoc(Abstraction $abs, $phpDocProp, $inheritedFro $existing ?: self::$basePropInfo, array( 'desc' => $phpDocProp['desc'], - 'type' => $this->helper->resolvePhpDocType($phpDocProp['type'], $abs), 'inheritedFrom' => $inheritedFrom, + 'type' => $this->helper->resolvePhpDocType($phpDocProp['type'], $abs), 'visibility' => $existing ? array($existing['visibility'], $vis) : $vis, @@ -488,7 +486,7 @@ private function buildPropViaRef(Abstraction $abs, ReflectionProperty $refProper ? $refProperty->isReadOnly() : false, 'isStatic' => $refProperty->isStatic(), - 'type' => $this->getPropType($phpDoc['type'], $refProperty), + 'type' => $this->getPropType($phpDoc['type'], $refProperty, $abs), 'visibility' => $this->helper->getVisibility($refProperty), )); if ($abs['collectPropertyValues']) { @@ -506,7 +504,7 @@ private function buildPropViaRef(Abstraction $abs, ReflectionProperty $refProper */ private function crate(Abstraction $abs) { - $properties = $this->abs['properties']; + $properties = $abs['properties']; $phpDocCollect = $abs['cfgFlags'] & AbstractObject::PHPDOC_COLLECT; foreach ($properties as $name => $info) { $info['value'] = $this->abstracter->crate($info['value'], $abs['debugMethod'], $abs['hist']); @@ -524,12 +522,13 @@ private function crate(Abstraction $abs) * * @param string $phpDocType Type specified in phpDoc block * @param ReflectionProperty $refProperty ReflectionProperty instance + * @param Abstraction $abs Object Abstraction instance * * @return string|null */ - private function getPropType($phpDocType, ReflectionProperty $refProperty) + private function getPropType($phpDocType, ReflectionProperty $refProperty, Abstraction $abs) { - $type = $this->helper->resolvePhpDocType($phpDocType, $this->abs); + $type = $this->helper->resolvePhpDocType($phpDocType, $abs); if ($type !== null) { return $type; } @@ -585,7 +584,7 @@ private function isDomObj($obj) /** * Determine propInfo['overrides'] value * - * This is the classname of previous ancestor where property is defined + * This is the class-name of previous ancestor where property is defined * * @param ReflectionProperty $refProperty Reflection Property * @param array $propInfo Property Info diff --git a/src/Debug/Abstraction/AbstractString.php b/src/Debug/Abstraction/AbstractString.php index 0d35074f..a9005c5a 100644 --- a/src/Debug/Abstraction/AbstractString.php +++ b/src/Debug/Abstraction/AbstractString.php @@ -146,12 +146,12 @@ protected function absValuesInit($string, $typeMore) $maxlen = $this->getMaxLen($maxLenCat, $strlen); return array( 'brief' => $this->cfg['brief'], + 'maxlen' => $maxlen, // temporary 'strlen' => $strlen, 'typeMore' => $typeMore, 'value' => $maxlen > -1 ? \substr($string, 0, $maxlen) : $string, - 'maxlen' => $maxlen, // temporary 'valueRaw' => $string, // temporary ); } diff --git a/src/Debug/Abstraction/Abstracter.php b/src/Debug/Abstraction/Abstracter.php index 49707b63..db4d4cdd 100644 --- a/src/Debug/Abstraction/Abstracter.php +++ b/src/Debug/Abstraction/Abstracter.php @@ -39,9 +39,9 @@ class Abstracter extends AbstractComponent const TYPE_RESOURCE = 'resource'; const TYPE_STRING = 'string'; const TYPE_CONST = 'const'; // non-native type (Abstraction: we store name and value) - const TYPE_UNDEFINED = 'undefined'; // non-native type const TYPE_NOT_INSPECTED = 'notInspected'; // non-native type const TYPE_RECURSION = 'recursion'; // non-native type + const TYPE_UNDEFINED = 'undefined'; // non-native type const TYPE_UNKNOWN = 'unknown'; // non-native type /* diff --git a/src/Debug/Abstraction/Abstraction.php b/src/Debug/Abstraction/Abstraction.php index 320ae415..7ef47359 100644 --- a/src/Debug/Abstraction/Abstraction.php +++ b/src/Debug/Abstraction/Abstraction.php @@ -37,6 +37,13 @@ class Abstraction extends Event implements JsonSerializable, Serializable public function __construct($type, $values = array()) { $values['type'] = $type; + if (\array_key_exists('value', $values) === false && $type !== Abstracter::TYPE_OBJECT) { + // make sure non-object gets value + $values['value'] = $type === Abstracter::TYPE_ARRAY + ? array() + : null; + } + \ksort($values); $this->setValues($values); } @@ -144,6 +151,7 @@ protected function onSet($values = array()) } if (!isset($values['attribs']['class'])) { $this->values['attribs']['class'] = array(); + \ksort($this->values['attribs']); } elseif (\is_string($values['attribs']['class'])) { $this->values['attribs']['class'] = \explode(' ', $values['attribs']['class']); } diff --git a/src/Debug/Collector/GuzzleMiddleware.php b/src/Debug/Collector/GuzzleMiddleware.php index 646aa894..1f430a0e 100644 --- a/src/Debug/Collector/GuzzleMiddleware.php +++ b/src/Debug/Collector/GuzzleMiddleware.php @@ -132,8 +132,8 @@ public function onRequest(RequestInterface $request, array $options) { $requestInfo = array( 'isAsyncronous' => empty($options[RequestOptions::SYNCHRONOUS]), - 'requestId' => \spl_object_hash($request), 'request' => $request, + 'requestId' => \spl_object_hash($request), ); if ($options['allow_redirects'] === true) { $options['allow_redirects'] = GuzzleHttp\RedirectMiddleware::$defaultSettings; diff --git a/src/Debug/Collector/MySqli.php b/src/Debug/Collector/MySqli.php index 24660a5c..5a300487 100644 --- a/src/Debug/Collector/MySqli.php +++ b/src/Debug/Collector/MySqli.php @@ -57,6 +57,7 @@ class MySqli extends mysqliBase public function __construct($host = null, $username = null, $passwd = null, $dbname = null, $port = null, $socket = null, Debug $debug = null) { $params = \func_num_args() + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder ? array( 'host' => $host, 'username' => $username, @@ -358,6 +359,7 @@ private function doConstruct($params) parent::__construct(); return; } + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $paramsDefault = array( 'host' => \ini_get('mysqli.default_host'), 'username' => \ini_get('mysqli.default_user'), diff --git a/src/Debug/Collector/OAuth.php b/src/Debug/Collector/OAuth.php index 8fff487f..6726c31a 100644 --- a/src/Debug/Collector/OAuth.php +++ b/src/Debug/Collector/OAuth.php @@ -124,10 +124,10 @@ private function getHttpMethod() private function getDebugInfo() { return \array_merge(array( - 'headers_sent' => '', - 'headers_recv' => '', 'body_recv' => null, 'body_sent' => null, + 'headers_recv' => '', + 'headers_sent' => '', 'sbs' => '', ), $this->debugInfo ?: array()); } @@ -162,8 +162,8 @@ private function additionalInfo($url) // "sbs" may be only key remaining ))); $lastResponseInfo = \array_merge(array( - 'size_download' => 0, 'download_content_length' => 0, + 'size_download' => 0, 'url' => $url, ), $this->getLastResponseInfo() ?: array()); $lastResponseInfo = \array_diff_key($lastResponseInfo, \array_filter(array( diff --git a/src/Debug/Collector/Pdo.php b/src/Debug/Collector/Pdo.php index 3131fc8a..d3857a8e 100644 --- a/src/Debug/Collector/Pdo.php +++ b/src/Debug/Collector/Pdo.php @@ -263,7 +263,7 @@ public function onDebugOutput(Event $event) 'argsAsParams' => false, 'icon' => $this->icon, 'level' => 'info', - )) + )), )); \call_user_func_array(array($debug, 'groupCollapsed'), $groupParams); $this->logRuntime($debug); diff --git a/src/Debug/Collector/SimpleCache.php b/src/Debug/Collector/SimpleCache.php index 7861964c..5ee2f246 100644 --- a/src/Debug/Collector/SimpleCache.php +++ b/src/Debug/Collector/SimpleCache.php @@ -164,8 +164,8 @@ public function onDebugOutput(Event $event) $debug->groupCollapsed( 'SimpleCache info', $debug->meta(array( - 'level' => 'info', 'icon' => $this->icon, + 'level' => 'info', )) ); $debug->log('logged operations: ', \count($this->loggedActions)); diff --git a/src/Debug/Collector/SimpleCache/CallInfo.php b/src/Debug/Collector/SimpleCache/CallInfo.php index 00fdf2b7..2ff1d5ce 100644 --- a/src/Debug/Collector/SimpleCache/CallInfo.php +++ b/src/Debug/Collector/SimpleCache/CallInfo.php @@ -75,9 +75,9 @@ public function __debugInfo() return array( 'duration' => $this->duration, 'exception' => $this->exception, + 'keyOrKeys' => $this->keyOrKeys, 'memoryUsage' => $this->memoryUsage, 'method' => $this->method, - 'keyOrKeys' => $this->keyOrKeys, ); } diff --git a/src/Debug/Collector/SoapClient.php b/src/Debug/Collector/SoapClient.php index daa1032d..aa3df320 100644 --- a/src/Debug/Collector/SoapClient.php +++ b/src/Debug/Collector/SoapClient.php @@ -50,7 +50,6 @@ class SoapClient extends SoapClientBase * @throws Exception * * @SuppressWarnings(PHPMD.StaticAccess) - * @phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch */ public function __construct($wsdl, $options = array(), Debug $debug = null) { @@ -79,8 +78,6 @@ public function __construct($wsdl, $options = array(), Debug $debug = null) /** * {@inheritDoc} - * - * @phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch */ #[\ReturnTypeWillChange] public function __call($name, $args) @@ -89,7 +86,7 @@ public function __call($name, $args) try { $return = parent::__call($name, $args); } catch (SoapFault $exception) { - // we'll rethrow bellow + // we'll rethrow below } $this->logReqRes($name, $exception); if ($exception) { @@ -244,8 +241,8 @@ private function isViaCall() $backtrace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10); foreach ($backtrace as $frame) { $frame = \array_merge(array( - 'function' => null, 'class' => null, + 'function' => null, 'type' => null, ), $frame); $func = $frame['class'] . $frame['type'] . $frame['function']; @@ -338,11 +335,11 @@ private function logXml($label, $xml) $this->debug->log( $label, new Abstraction(Abstracter::TYPE_STRING, array( - 'value' => $xml, + 'addQuotes' => false, 'attribs' => array( 'class' => 'highlight language-xml', ), - 'addQuotes' => false, + 'value' => $xml, 'visualWhiteSpace' => false, )), $this->debug->meta(array( diff --git a/src/Debug/Collector/StatementInfo.php b/src/Debug/Collector/StatementInfo.php index e5b203b0..c56d70b8 100644 --- a/src/Debug/Collector/StatementInfo.php +++ b/src/Debug/Collector/StatementInfo.php @@ -120,8 +120,8 @@ public function appendLog(Debug $debug) $this->debug = $debug; $label = $this->getGroupLabel(); $debug->groupCollapsed($label, $debug->meta(array( - 'icon' => $debug->getCfg('channelIcon', Debug::CONFIG_DEBUG), 'boldLabel' => false, + 'icon' => $debug->getCfg('channelIcon', Debug::CONFIG_DEBUG), ))); $this->logQuery($label); $this->logParams(); @@ -238,9 +238,9 @@ protected function getSqlWithParams($quotationChars = '<>') } $sql = $this->sql; $cleanBackRefCharMap = array( - '%' => '%%', '$' => '$%', - '\\' => '\\%' + '%' => '%%', + '\\' => '\\%', ); foreach ($this->params as $k => $v) { $backRefSafeV = \strtr($v, $cleanBackRefCharMap); diff --git a/src/Debug/Config.php b/src/Debug/Config.php index b148527e..e4ad3835 100644 --- a/src/Debug/Config.php +++ b/src/Debug/Config.php @@ -25,9 +25,6 @@ class Config protected $valuesPending = array(); protected $invokedServices = array(); protected $configKeys = array( - 'debug' => array( - // any key not found falls under 'debug'... - ), 'abstracter' => array( 'brief', 'caseAttributeCollect', @@ -61,6 +58,9 @@ class Config 'toStringOutput', 'useDebugInfo', ), + 'debug' => array( + // any key not found falls under 'debug'... + ), 'errorHandler' => array( 'continueToPrevHandler', 'errorFactory', @@ -102,7 +102,7 @@ class Config 'routeStream' => array( 'ansi', 'stream', - ) + ), ); /** diff --git a/src/Debug/ConfigEvents.php b/src/Debug/ConfigEvents.php index 5757a761..9b111cac 100644 --- a/src/Debug/ConfigEvents.php +++ b/src/Debug/ConfigEvents.php @@ -43,8 +43,8 @@ public function __construct(Debug $debug) public function getSubscriptions() { return array( - Debug::EVENT_CONFIG => array('onConfig', PHP_INT_MAX), Debug::EVENT_BOOTSTRAP => array('onBootstrap', PHP_INT_MAX * -1), + Debug::EVENT_CONFIG => array('onConfig', PHP_INT_MAX), ); } @@ -344,8 +344,8 @@ private function onCfgReplaceSubscriber($val, $name) { $events = array( 'onLog' => Debug::EVENT_LOG, - 'onOutput' => Debug::EVENT_OUTPUT, 'onMiddleware' => Debug::EVENT_MIDDLEWARE, + 'onOutput' => Debug::EVENT_OUTPUT, ); $event = $events[$name]; $prev = $this->debug->getCfg($name, Debug::CONFIG_DEBUG); @@ -431,7 +431,7 @@ private function onConfigInit($configs) // remove current collect & output values, // so don't trigger updates for existing values $this->debug->getCfg(null, Debug::CONFIG_DEBUG), - \array_flip(array('collect','output')) + \array_flip(array('collect', 'output')) ), $cfgDebug ); diff --git a/src/Debug/Debug.php b/src/Debug/Debug.php index bea702d6..0f3fd238 100644 --- a/src/Debug/Debug.php +++ b/src/Debug/Debug.php @@ -90,9 +90,8 @@ class Debug extends AbstractDebug const VERSION = '3.0.4'; protected $cfg = array( - 'collect' => false, - 'key' => null, - 'output' => false, // output the log? + 'channelIcon' => 'fa fa-list-ul', + 'channelName' => 'general', // channel or tab name 'channels' => array( /* channelName => array( @@ -103,17 +102,11 @@ class Debug extends AbstractDebug ) */ ), - 'channelIcon' => 'fa fa-list-ul', - 'channelName' => 'general', // channel or tab name - 'channelShow' => true, // wheter initially filtered or not + 'channelShow' => true, // whether initially filtered or not 'channelSort' => 0, // if non-nested channel (tab), sort order - // higher = first - // tabs with same sort will be sorted alphabetically - 'enableProfiling' => false, - 'errorLogNormal' => false, // whether php shoyld also log the error when debugging is active - 'errorMask' => 0, // which error types appear as "error" in debug console... - // all other errors are "warn" - // (default set in constructor) + // higher = first + // tabs with same sort will be sorted alphabetically + 'collect' => false, 'emailFrom' => null, // null = use php's default (php.ini: sendmail_from) 'emailFunc' => 'mail', // callable 'emailLog' => false, // Whether to email a debug log. (requires 'collect' to also be true) @@ -121,11 +114,17 @@ class Debug extends AbstractDebug // true or 'always': email sent (if log is not output) // 'onError': email sent if error occured (unless output) 'emailTo' => 'default', // will default to $_SERVER['SERVER_ADMIN'] if non-empty, null otherwise + 'enableProfiling' => false, + 'errorLogNormal' => false, // whether php shoyld also log the error when debugging is active + 'errorMask' => 0, // which error types appear as "error" in debug console... + // all other errors are "warn" + // (default set in constructor) 'exitCheck' => true, 'extensionsCheck' => array('curl', 'mbString'), 'headerMaxAll' => 250000, 'headerMaxPer' => null, - 'logEnvInfo' => array( // may be set by passing a list + 'key' => null, + 'logEnvInfo' => array( // may be set by passing a list 'errorReporting' => true, 'files' => true, 'gitInfo' => true, @@ -143,17 +142,18 @@ class Debug extends AbstractDebug 'logResponseMaxLen' => '1 MB', 'logRuntime' => true, 'logServerKeys' => array('REMOTE_ADDR','REQUEST_TIME','REQUEST_URI','SERVER_ADDR','SERVER_NAME'), - 'onBootstrap' => null, // callable - 'onLog' => null, // callable - 'onOutput' => null, // callable - 'outputHeaders' => true, // ie, ChromeLogger and/or firePHP headers - 'redactKeys' => array( // case-insensitive + 'onBootstrap' => null, // callable + 'onLog' => null, // callable + 'onOutput' => null, // callable + 'output' => false, // output the log? + 'outputHeaders' => true, // ie, ChromeLogger and/or firePHP headers + 'redactKeys' => array( // case-insensitive 'password', ), - // 'redactReplace' // closure (default defined in PLugin/Redaction) - 'route' => 'auto', // 'auto', 'chromeLogger', 'firephp', 'html', 'serverLog', 'script', 'steam', 'text', or RouteInterface, - // if 'auto', will be determined automatically - // if null, no output (unless output plugin added manually) + // 'redactReplace' // closure (default defined in Plugin/Redaction) + 'route' => 'auto', // 'auto', 'chromeLogger', 'firephp', 'html', 'serverLog', 'script', 'steam', 'text', or RouteInterface, + // if 'auto', will be determined automatically + // if null, no output (unless output plugin added manually) 'routeNonHtml' => 'serverLog', 'serviceProvider' => array(), // ServiceProviderInterface, array, or callable that receives Container as param 'sessionName' => null, // if logging session data (see logEnvInfo), optionally specify session name @@ -161,7 +161,7 @@ class Debug extends AbstractDebug // wampPuglisher // required if using Wamp route // must be installed separately - 'realm' => 'debug' + 'realm' => 'debug', ), ); @@ -193,8 +193,6 @@ public function __construct($cfg = array()) * @param bool $dismissible (false) Whether to display a close icon/button * * @return $this - * - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function alert($message, $level = 'error', $dismissible = false) { @@ -205,13 +203,13 @@ public function alert($message, $level = 'error', $dismissible = false) __FUNCTION__, $args, array( - 'level' => 'error', 'dismissible' => false, + 'level' => 'error', ), $hasSubstitutions ? array() : $this->getMethodDefaultArgs(__FUNCTION__), - array('level','dismissible') + array('level', 'dismissible') ); $logEntry['args'] = \array_values($logEntry['args']); $this->methodHelper->alertLevel($logEntry); @@ -231,8 +229,6 @@ public function alert($message, $level = 'error', $dismissible = false) * if none provided, will use calling file & line num * * @return $this - * - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function assert($assertion, $msg = null) { @@ -275,8 +271,6 @@ public function assert($assertion, $msg = null) * `self::CLEAR_SILENT` : Don't add log entry * * @return $this - * - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function clear($bitmask = self::CLEAR_LOG) { @@ -441,8 +435,6 @@ public function groupEnd($value = Abstracter::UNDEFINED) * @param int $priority (0) The higher the priority, the earlier the group will appear in output * * @return $this - * - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function groupSummary($priority = 0) { @@ -657,7 +649,7 @@ public function time($label = null, $duration = null) * 'auto' : !$log * * @return $this|float|false The duration (in sec). - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter + * * @psalm-return ($return is true ? float|false : $this) */ public function timeEnd($label = null, $log = true, $return = 'auto') @@ -686,7 +678,7 @@ public function timeEnd($label = null, $log = true, $return = 'auto') * 'auto' : !$log * * @return $this|float|false The duration (in sec). `false` if specified label does not exist - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter + * * @psalm-return ($return is true ? float|false : $this) */ public function timeGet($label = null, $log = true, $return = 'auto') @@ -733,8 +725,6 @@ public function timeLog($label = null, $args = null) * @param string $caption (optional) Specify caption for the trace table * * @return $this - * - * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function trace($inclContext = false, $caption = 'trace') { diff --git a/src/Debug/Dump/Base.php b/src/Debug/Dump/Base.php index 09d712fb..a308db55 100644 --- a/src/Debug/Dump/Base.php +++ b/src/Debug/Dump/Base.php @@ -80,7 +80,7 @@ public function processLogEntry(LogEntry $logEntry) if (\in_array($method, array('group', 'groupCollapsed', 'groupEnd', 'groupSummary'), true)) { return $this->methodGroup($logEntry); } - if (\in_array($method, array('profileEnd','table','trace'), true)) { + if (\in_array($method, array('profileEnd', 'table', 'trace'), true)) { return $this->methodTabular($logEntry); } return $this->methodDefault($logEntry); @@ -137,7 +137,7 @@ protected function methodAlert(LogEntry $logEntry) { $method = $logEntry->getMeta('level'); if ($logEntry->containsSubstitutions()) { - $logEntry['method'] = \in_array($method, array('info','success'), true) + $logEntry['method'] = \in_array($method, array('info', 'success'), true) ? 'info' : 'log'; $args = $this->substitution->process($logEntry['args']); @@ -172,7 +172,7 @@ protected function methodDefault(LogEntry $logEntry) { $method = $logEntry['method']; $args = $logEntry['args']; - if (\in_array($method, array('assert','clear','error','info','log','warn'), true)) { + if (\in_array($method, array('assert', 'clear', 'error', 'info', 'log', 'warn'), true)) { if ($logEntry->containsSubstitutions()) { $args = $this->substitution->process($args); } diff --git a/src/Debug/Dump/BaseValue.php b/src/Debug/Dump/BaseValue.php index 8575f6a7..a73f4497 100644 --- a/src/Debug/Dump/BaseValue.php +++ b/src/Debug/Dump/BaseValue.php @@ -179,8 +179,8 @@ protected function dumpAbstraction(Abstraction $abs) $event = $this->debug->publishBubbleEvent(Debug::EVENT_DUMP_CUSTOM, new Event( $abs, array( - 'valDumper' => $this, 'return' => '', + 'valDumper' => $this, ) )); $this->setDumpOpt('typeMore', $abs['typeMore']); @@ -344,7 +344,7 @@ protected function dumpPropVis($info) { $vis = (array) $info['visibility']; foreach ($vis as $i => $v) { - if (\in_array($v, array('magic','magic-read','magic-write'), true)) { + if (\in_array($v, array('magic', 'magic-read', 'magic-write'), true)) { $vis[$i] = '✨ ' . $v; // "sparkles": there is no magic-wand unicode char } elseif ($v === 'private' && $info['inheritedFrom']) { $vis[$i] = '🔒 ' . $v; @@ -439,8 +439,8 @@ protected function parseIdentifier($val, $asFunction = false) } $parts = array( 'classname' => $val, - 'operator' => '::', 'identifier' => '', + 'operator' => '::', ); $matches = array(); if (\is_array($val)) { diff --git a/src/Debug/Dump/Html.php b/src/Debug/Dump/Html.php index 52f3d148..8dbf92f6 100644 --- a/src/Debug/Dump/Html.php +++ b/src/Debug/Dump/Html.php @@ -365,8 +365,8 @@ protected function methodTabular(LogEntry $logEntry) $meta = $this->debug->arrayUtil->mergeDeep(array( 'attribs' => array( 'class' => \array_keys(\array_filter(array( - 'table-bordered' => true, 'sortable' => $logEntry->getMeta('sortable'), + 'table-bordered' => true, 'trace-context' => $logEntry->getMeta('inclContext'), ))), ), diff --git a/src/Debug/Dump/Html/HtmlObject.php b/src/Debug/Dump/Html/HtmlObject.php index 0bc2097c..45541a17 100644 --- a/src/Debug/Dump/Html/HtmlObject.php +++ b/src/Debug/Dump/Html/HtmlObject.php @@ -357,7 +357,7 @@ protected function dumpToString(Abstraction $abs) !$abs['stringified'] ? '__toString()' : null, // ie a timestamp will have a human readable date in title isset($parsed['attribs']['title']) ? $parsed['attribs']['title'] : null, - ))) + ))), ), $parsed['innerhtml'] . $valAppend ) . "\n"; diff --git a/src/Debug/Dump/Html/HtmlString.php b/src/Debug/Dump/Html/HtmlString.php index 0cd21ad7..56f2d6c8 100644 --- a/src/Debug/Dump/Html/HtmlString.php +++ b/src/Debug/Dump/Html/HtmlString.php @@ -150,8 +150,8 @@ public function visualWhiteSpace($str) { // display \r, \n, & \t $str = \preg_replace_callback('/(\r\n|\r|\n)/', static function ($matches) { - $search = array("\r","\n"); - $replace = array('','' . "\n"); + $search = array("\r", "\n"); + $replace = array('', '' . "\n"); return \str_replace($search, $replace, $matches[1]); }, $str); $str = \str_replace("\t", '' . "\t" . '', $str); diff --git a/src/Debug/Dump/Html/HtmlStringEncoded.php b/src/Debug/Dump/Html/HtmlStringEncoded.php index a2eab0ce..38b3d7fd 100644 --- a/src/Debug/Dump/Html/HtmlStringEncoded.php +++ b/src/Debug/Dump/Html/HtmlStringEncoded.php @@ -15,7 +15,6 @@ use bdk\Debug\Abstraction\Abstracter; use bdk\Debug\Abstraction\Abstraction; use bdk\Debug\Dump\Html\HtmlString; -use bdk\Debug\Dump\Html\Value as ValDumper; /** * Output "encoded" string (ie base64, json, or serialized) @@ -70,7 +69,7 @@ public function dump($val, Abstraction $abs) } /** - * [dumpEncodedGetTabs description] + * Build tabs and panes * * @param Abstraction $abs full value abstraction * @@ -79,8 +78,8 @@ public function dump($val, Abstraction $abs) private function buildTabsAndPanes(Abstraction $abs) { $tabs = array( - 'tabs' => array(), 'panes' => array(), + 'tabs' => array(), ); $index = 1; do { @@ -96,7 +95,7 @@ private function buildTabsAndPanes(Abstraction $abs) } /** - * [buildTab description] + * Built tab link * * @param string $tab Tab label * @param int $index Tab index @@ -111,7 +110,7 @@ private function buildTab($tab, $index, $isActive = false) array( 'class' => array( 'active' => $isActive, - 'nav-link', + 'nav-link' => true, ), 'data-target' => '.tab-' . $index, 'data-toggle' => 'tab', @@ -122,7 +121,7 @@ private function buildTab($tab, $index, $isActive = false) } /** - * [buildTabPane description] + * Build tab pane * * @param string $tabBody Tab body * @param int $index Tab index @@ -137,8 +136,8 @@ private function buildTabPane($tabBody, $index, $isActive = false) array( 'class' => array( 'active' => $isActive, - 'tab-' . $index, - 'tab-pane', + 'tab-' . $index => true, + 'tab-pane' => true, ), 'role' => 'tabpanel', ), diff --git a/src/Debug/Dump/Html/ObjectMethods.php b/src/Debug/Dump/Html/ObjectMethods.php index 7eff14c3..22dbce70 100644 --- a/src/Debug/Dump/Html/ObjectMethods.php +++ b/src/Debug/Dump/Html/ObjectMethods.php @@ -69,7 +69,7 @@ public function dump(Abstraction $abs) 'phpDocOutput' => $abs['cfgFlags'] & AbstractObject::PHPDOC_OUTPUT, ); $methods = $abs['methods']; - $magicMethods = \array_intersect(array('__call','__callStatic'), \array_keys($methods)); + $magicMethods = \array_intersect(array('__call', '__callStatic'), \array_keys($methods)); $str .= $this->dumpObject->magicMethodInfo($magicMethods); foreach ($methods as $methodName => $info) { $str .= $this->dumpMethod($methodName, $info); @@ -132,6 +132,7 @@ protected function dumpMethod($methodName, $info) */ protected function dumpModifiers($info) { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $modifiers = \array_keys(\array_filter(array( 'final' => $info['isFinal'], $info['visibility'] => true, diff --git a/src/Debug/Dump/Html/ObjectProperties.php b/src/Debug/Dump/Html/ObjectProperties.php index 822bfb52..b749dbc1 100644 --- a/src/Debug/Dump/Html/ObjectProperties.php +++ b/src/Debug/Dump/Html/ObjectProperties.php @@ -57,7 +57,7 @@ public function dump(Abstraction $abs) 'attributeOutput' => $abs['cfgFlags'] & AbstractObject::PROP_ATTRIBUTE_OUTPUT, 'phpDocOutput' => $abs['cfgFlags'] & AbstractObject::PHPDOC_OUTPUT, ); - $magicMethods = \array_intersect(array('__get','__set'), \array_keys($abs['methods'])); + $magicMethods = \array_intersect(array('__get', '__set'), \array_keys($abs['methods'])); $str = $this->dumpPropertiesLabel($abs); $str .= $this->dumpObject->magicMethodInfo($magicMethods); foreach ($abs['properties'] as $name => $info) { diff --git a/src/Debug/Dump/Html/Table.php b/src/Debug/Dump/Html/Table.php index d1449379..677dc650 100644 --- a/src/Debug/Dump/Html/Table.php +++ b/src/Debug/Dump/Html/Table.php @@ -76,7 +76,7 @@ protected function buildBody($rows) { $tBody = ''; $this->options['onBuildRow'] = \is_callable($this->options['onBuildRow']) - ? array( $this->options['onBuildRow'] ) + ? array($this->options['onBuildRow']) : (array) $this->options['onBuildRow']; foreach ($rows as $k => $row) { $rowInfo = \array_merge( diff --git a/src/Debug/Dump/Html/Value.php b/src/Debug/Dump/Html/Value.php index ae740707..fd13a054 100644 --- a/src/Debug/Dump/Html/Value.php +++ b/src/Debug/Dump/Html/Value.php @@ -244,8 +244,8 @@ private function dumpArrayValue($key, $val, $withKey) 'span', array( 'class' => array( - 't_key', 't_int' => \is_int($key), + 't_key' => true, ), ), $this->dump($key, array('tagName' => null)) // don't wrap it @@ -426,9 +426,9 @@ private function setDumpOptDefaults($val, $opts) ); } $opts = \array_merge(array( - 'tagName' => '__default__', 'attribs' => $attribs, 'postDump' => null, + 'tagName' => '__default__', ), $opts); return $opts; } diff --git a/src/Debug/Dump/Text.php b/src/Debug/Dump/Text.php index b090d8f3..a0af5f49 100644 --- a/src/Debug/Dump/Text.php +++ b/src/Debug/Dump/Text.php @@ -23,6 +23,10 @@ class Text extends Base { protected $depth = 0; // for keeping track of indentation protected $cfg = array( + 'glue' => array( + 'equal' => ' = ', + 'multiple' => ', ', + ), 'prefixes' => array( 'assert' => '≠ ', 'clear' => 'âŒĻ ', @@ -37,10 +41,6 @@ class Text extends Base 'timeLog' => '⏱ ', 'warn' => '⚠ ', ), - 'glue' => array( - 'equal' => ' = ', - 'multiple' => ', ', - ), ); /** @@ -172,7 +172,7 @@ protected function methodAlert(LogEntry $logEntry) ); $prefix = $this->cfg['prefixes'][$levelToMethod[$level]]; $prefix = '[Alert ' . $prefix . $level . '] '; - $wrap = array('》','《'); + $wrap = array('》', '《'); $args = $logEntry['args']; if ($logEntry->containsSubstitutions()) { $args = $this->substitution->process($args, array( diff --git a/src/Debug/Dump/TextAnsi.php b/src/Debug/Dump/TextAnsi.php index 1f64ab42..f6c82fdb 100644 --- a/src/Debug/Dump/TextAnsi.php +++ b/src/Debug/Dump/TextAnsi.php @@ -25,19 +25,19 @@ class TextAnsi extends Text protected $ansiCfg = array( 'ansi' => 'default', // default | true | false (STDOUT & STDERR streams will default to true) 'escapeCodes' => array( + 'arrayKey' => "\e[38;5;83m", // yellow 'excluded' => "\e[38;5;9m", // red 'false' => "\e[91m", // red 'keyword' => "\e[38;5;45m", // blue - 'arrayKey' => "\e[38;5;83m", // yellow 'maxlen' => "\e[30;48;5;41m", // light green background 'muted' => "\e[38;5;250m", // dark grey 'numeric' => "\e[96m", // blue 'operator' => "\e[38;5;130m", // green - 'punct' => "\e[38;5;245m", // grey (brackets) 'property' => "\e[38;5;83m", // yellow + 'punct' => "\e[38;5;245m", // grey (brackets) 'quote' => "\e[38;5;250m", // grey - 'true' => "\e[32m", // green 'recursion' => "\e[38;5;196m", // red + 'true' => "\e[32m", // green ), 'escapeCodesLevels' => array( 'error' => "\e[38;5;88;48;5;203;1;4m", @@ -51,8 +51,8 @@ class TextAnsi extends Text 'warn' => "\e[38;5;148m", ), 'glue' => array( - 'multiple' => "\e[38;5;245m, \x00escapeReset\x00", 'equal' => " \e[38;5;245m=\x00escapeReset\x00 ", + 'multiple' => "\e[38;5;245m, \x00escapeReset\x00", ), 'stream' => 'php://stderr', // filepath/uri/resource ); diff --git a/src/Debug/Dump/TextAnsiValue.php b/src/Debug/Dump/TextAnsiValue.php index e43b9dac..db3e977d 100644 --- a/src/Debug/Dump/TextAnsiValue.php +++ b/src/Debug/Dump/TextAnsiValue.php @@ -72,8 +72,7 @@ protected function dumpArray($array) $str .= ' ' . $escapeCodes['punct'] . '[' . $escapeKey . $k . $escapeCodes['punct'] . ']' . $escapeCodes['operator'] . ' => ' . $this->escapeReset - . $this->dump($v) - . "\n"; + . $this->dump($v) . "\n"; } $str .= $this->cfg['escapeCodes']['punct'] . ')' . $this->escapeReset; if (!$array) { @@ -139,16 +138,17 @@ protected function dumpNull() */ protected function dumpObject(Abstraction $abs) { + $className = $this->markupIdentifier($abs['className']); $escapeCodes = $this->cfg['escapeCodes']; if ($abs['isRecursion']) { - return $escapeCodes['excluded'] . '*RECURSION*' . $this->escapeReset; + return $className . ' ' . $escapeCodes['recursion'] . '*RECURSION*' . $this->escapeReset; } if ($abs['isExcluded']) { - return $escapeCodes['excluded'] . 'NOT INSPECTED' . $this->escapeReset; + return $className . ' ' . $escapeCodes['excluded'] . 'NOT INSPECTED' . $this->escapeReset; } $isNested = $this->valDepth > 0; $this->valDepth++; - $str = $this->markupIdentifier($abs['className']) . "\n" + $str = $className . "\n" . $this->dumpObjectProperties($abs) . $this->dumpObjectMethods($abs); $str = \trim($str); @@ -172,6 +172,7 @@ protected function dumpObjectMethods(Abstraction $abs) if (!$methodCollect || !$methodOutput) { return ''; } + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $counts = array( 'public' => 0, 'protected' => 0, diff --git a/src/Debug/Dump/TextValue.php b/src/Debug/Dump/TextValue.php index e97fdc57..d6d0d808 100644 --- a/src/Debug/Dump/TextValue.php +++ b/src/Debug/Dump/TextValue.php @@ -145,6 +145,7 @@ protected function dumpObjectMethods(Abstraction $abs) return ''; } $str = ''; + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $counts = array( 'public' => 0, 'protected' => 0, @@ -183,7 +184,7 @@ protected function dumpObjectProperties(Abstraction $abs) $name = \str_replace('debug.', '', $name); $vis = (array) $info['visibility']; foreach ($vis as $i => $v) { - if (\in_array($v, array('magic','magic-read','magic-write'), true)) { + if (\in_array($v, array('magic', 'magic-read', 'magic-write'), true)) { $vis[$i] = '✨ ' . $v; // "sparkles" there is no magic-wand unicode char } elseif ($v === 'private' && $info['inheritedFrom']) { $vis[$i] = '🔒 ' . $v; diff --git a/src/Debug/Framework/Cake4.php b/src/Debug/Framework/Cake4.php index 97d1bcff..964d44ea 100644 --- a/src/Debug/Framework/Cake4.php +++ b/src/Debug/Framework/Cake4.php @@ -107,7 +107,7 @@ public function middleware(MiddlewareQueue $middleware): MiddlewareQueue 'catchException' => true, // we'll catch it, pass to PHPDebugConsole's errorHandler and pass it on to Cake's handler 'onCaughtException' => function (Exception $e, ServerRequestInterface $request) { return $this->errorHandlerMiddleW->handleException($e, $request); - } + }, ))); $mwRef = new \ReflectionObject($middleware); $queueRef = $mwRef->getProperty('queue'); @@ -174,6 +174,7 @@ protected function logEvents() $name = $event->getName(); if (!isset($events[$name])) { $events[$name] = array( + 'count' => 0, 'name' => $name, 'subject' => $debug->abstracter->crateWithVals( \get_class($event->getSubject()), @@ -181,7 +182,6 @@ protected function logEvents() 'typeMore' => Abstracter::TYPE_STRING_CLASSNAME, ) ), - 'count' => 0 ); } $events[$name]['count'] ++; diff --git a/src/Debug/Framework/Laravel/EventsSubscriber.php b/src/Debug/Framework/Laravel/EventsSubscriber.php index 2e3968b9..2ce46126 100644 --- a/src/Debug/Framework/Laravel/EventsSubscriber.php +++ b/src/Debug/Framework/Laravel/EventsSubscriber.php @@ -67,8 +67,8 @@ public function onWildcardEvent($name = null, $payload = array()) $groupParams = array($matches[1], $matches[2]); } $groupParams[] = $this->debug->meta(array( - 'icon' => $this->icon, 'argsAsParams' => false, + 'icon' => $this->icon, )); $this->debug->groupCollapsed(...$groupParams); // php 5.6+ $this->logPayload($payload); diff --git a/src/Debug/Framework/Laravel/Middleware.php b/src/Debug/Framework/Laravel/Middleware.php index 19325ff9..f8a15439 100644 --- a/src/Debug/Framework/Laravel/Middleware.php +++ b/src/Debug/Framework/Laravel/Middleware.php @@ -247,8 +247,8 @@ protected function logRoute() $uri = \reset($methods) . ' ' . $route->uri(); $info = \array_merge(array( - 'uri' => $uri ?: null, 'middleware' => $route->middleware(), + 'uri' => $uri ?: null, ), $route->getAction()); $info['middleware'] = $this->debug->abstracter->crateWithVals($info['middleware'], array( 'options' => array( diff --git a/src/Debug/Framework/Laravel/ServiceProvider.php b/src/Debug/Framework/Laravel/ServiceProvider.php index 8a9eb84b..57bc9d9a 100644 --- a/src/Debug/Framework/Laravel/ServiceProvider.php +++ b/src/Debug/Framework/Laravel/ServiceProvider.php @@ -48,10 +48,10 @@ public function register() $this->mergeConfigFrom(__DIR__ . '/config.php', 'phpDebugConsole'); $config = ArrayUtil::mergeDeep($this->app['config']->get('phpDebugConsole'), array( + 'filepathScript' => './js/Debug.jquery.js', 'logEnvInfo' => array( 'session' => false, ), - 'filepathScript' => './js/Debug.jquery.js', 'onError' => static function (Error $error) { $error['continueToPrevHandler'] = false; // forward error to Laravel Handler? }, @@ -115,7 +115,7 @@ public function onOutput() 'sortable' => true, 'tableInfo' => array( 'indexLabel' => 'model', - 'rows' => $tableInfoRows + 'rows' => $tableInfoRows, ), 'totalCols' => array(TableRow::SCALAR), ))); @@ -160,10 +160,10 @@ private function buildModelCountTable(&$tableInfoRows) $modelCounts[] = $count; $tableInfoRows[] = array( 'key' => $this->debug->abstracter->crateWithVals($class, array( - 'typeMore' => Abstracter::TYPE_STRING_CLASSNAME, 'attribs' => array( 'data-file' => $ref->getFileName(), - ) + ), + 'typeMore' => Abstracter::TYPE_STRING_CLASSNAME, )), ); } @@ -408,6 +408,7 @@ protected function logView(View $view) $info = \array_filter(array( 'name' => $name, + 'params' => \call_user_func(array($this, 'logViewParams'), $view), 'path' => $pathStr ? $this->debug->abstracter->crateWithVals( \ltrim(\str_replace(\base_path(), '', $pathStr), '/'), @@ -418,7 +419,6 @@ protected function logView(View $view) ) ) : null, - 'params' => \call_user_func(array($this, 'logViewParams'), $view), 'type' => \is_object($path) ? \get_class($view) : (\substr($path, -10) === '.blade.php' diff --git a/src/Debug/Framework/Slim2.php b/src/Debug/Framework/Slim2.php index 2342ab8b..7b6463f5 100644 --- a/src/Debug/Framework/Slim2.php +++ b/src/Debug/Framework/Slim2.php @@ -76,6 +76,7 @@ public function write($message, $level) */ protected function levelToMethod($level) { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $map = array( Log::EMERGENCY => 'error', Log::ALERT => 'alert', diff --git a/src/Debug/Framework/Symfony/DebugBundle/DependencyInjection/BdkDebugExtension.php b/src/Debug/Framework/Symfony/DebugBundle/DependencyInjection/BdkDebugExtension.php index b845a6aa..f43702f0 100644 --- a/src/Debug/Framework/Symfony/DebugBundle/DependencyInjection/BdkDebugExtension.php +++ b/src/Debug/Framework/Symfony/DebugBundle/DependencyInjection/BdkDebugExtension.php @@ -61,8 +61,8 @@ public function prepend(ContainerBuilder $container) $container->prependExtensionConfig('monolog', array( 'handlers' => array( 'phpDebugConsole' => array( - 'type' => 'service', 'id' => 'monologHandler', + 'type' => 'service', ), ), )); diff --git a/src/Debug/Framework/Yii1_1/Component.php b/src/Debug/Framework/Yii1_1/Component.php index 7f7721e1..29955f48 100644 --- a/src/Debug/Framework/Yii1_1/Component.php +++ b/src/Debug/Framework/Yii1_1/Component.php @@ -107,12 +107,12 @@ public function __set($name, $value) public function getSubscriptions() { return array( + 'yii.componentInit' => 'onComponentInit', Debug::EVENT_CUSTOM_METHOD => 'onCustomMethod', - Debug::EVENT_OBJ_ABSTRACT_START => 'onDebugObjAbstractStart', Debug::EVENT_OBJ_ABSTRACT_END => 'onDebugObjAbstractEnd', + Debug::EVENT_OBJ_ABSTRACT_START => 'onDebugObjAbstractStart', Debug::EVENT_OUTPUT => array('onDebugOutput', 1), Debug::EVENT_OUTPUT_LOG_ENTRY => 'onDebugOutputLogEntry', - 'yii.componentInit' => 'onComponentInit', ); } diff --git a/src/Debug/Framework/Yii1_1/LogRoute.php b/src/Debug/Framework/Yii1_1/LogRoute.php index f6770352..0fb21613 100644 --- a/src/Debug/Framework/Yii1_1/LogRoute.php +++ b/src/Debug/Framework/Yii1_1/LogRoute.php @@ -28,11 +28,11 @@ class LogRoute extends CLogRoute private $debug; private $levelMap = array( - CLogger::LEVEL_INFO => 'log', - CLogger::LEVEL_WARNING => 'warn', CLogger::LEVEL_ERROR => 'error', - CLogger::LEVEL_TRACE => 'trace', + CLogger::LEVEL_INFO => 'log', CLogger::LEVEL_PROFILE => 'time', + CLogger::LEVEL_TRACE => 'trace', + CLogger::LEVEL_WARNING => 'warn', ); /** @@ -46,7 +46,7 @@ class LogRoute extends CLogRoute * We exclude system.db categories... handled via pdo wrapper */ protected $except = array( - '/^system\.db\./' + '/^system\.db\./', ); /** @@ -144,7 +144,7 @@ private function getCallerInfo() } $callerInfo = $frame; // check if log called by some other wrapper method - if (\in_array($backtrace[$i + 1]['function'], array('log','error','warn','warning'), true)) { + if (\in_array($backtrace[$i + 1]['function'], array('log', 'error', 'warn', 'warning'), true)) { $callerInfo = $backtrace[$i + 1]; } break; @@ -188,7 +188,7 @@ protected function isExcluded(array $logEntry) protected function normalizeMessage(array $logEntry) { $logEntry = \array_combine( - array('message','level','category','time'), + array('message', 'level', 'category', 'time'), $logEntry ); $logEntry = \array_merge($logEntry, array( @@ -215,10 +215,10 @@ protected function messageMeta(array $logEntry) $logEntry = $this->messageMetaTrace($logEntry); $logEntry = $this->messageMetaCaller($logEntry); $categoryFuncs = array( + '/^system\\./' => 'messageMetaSystem', + '/^system\\.caching/' => 'messageMetaSystemCaching', 'application' => 'messageMetaApplication', 'system.CModule' => 'messageMetaSystemCmodule', - '/^system\\.caching/' => 'messageMetaSystemCaching', - '/^system\\./' => 'messageMetaSystem', ); foreach ($categoryFuncs as $match => $method) { $isMatch = $match[0] === '/' @@ -243,7 +243,7 @@ private function messageMetaCaller(array $logEntry) if (\in_array($logEntry['level'], array(CLogger::LEVEL_ERROR, CLogger::LEVEL_WARNING), true) === false) { return $logEntry; } - if (\array_intersect_key($logEntry['meta'], \array_flip(array('file','line')))) { + if (\array_intersect_key($logEntry['meta'], \array_flip(array('file', 'line')))) { return $logEntry; } $callerInfo = $this->getCallerInfo(); @@ -486,7 +486,7 @@ private function processLogEntryTrace(array $logEntry) $caption = $logEntry['category'] ? $logEntry['category'] . ': ' . $logEntry['message'] : $logEntry['message']; - $logEntry['meta']['columns'] = array('file','line'); + $logEntry['meta']['columns'] = array('file', 'line'); $logEntry['meta']['trace'] = $logEntry['trace']; $debug = $logEntry['channel']; $method = $this->levelMap[$logEntry['level']]; diff --git a/src/Debug/Framework/Yii2/LogTarget.php b/src/Debug/Framework/Yii2/LogTarget.php index 420b8d09..d7343438 100644 --- a/src/Debug/Framework/Yii2/LogTarget.php +++ b/src/Debug/Framework/Yii2/LogTarget.php @@ -31,12 +31,12 @@ class LogTarget extends Target private $levelMap = array( Logger::LEVEL_ERROR => 'error', - Logger::LEVEL_WARNING => 'warn', Logger::LEVEL_INFO => 'log', - Logger::LEVEL_TRACE => 'trace', Logger::LEVEL_PROFILE => 'log', Logger::LEVEL_PROFILE_BEGIN => 'log', Logger::LEVEL_PROFILE_END => 'time', + Logger::LEVEL_TRACE => 'trace', + Logger::LEVEL_WARNING => 'warn', ); private $profileStack = array(); @@ -289,7 +289,7 @@ private function normalizeMessage($message) 'category', 'timestamp', 'trace', - 'memory' + 'memory', ), $message); if ($message['level'] === Logger::LEVEL_TRACE && empty($message['trace'])) { $message['level'] = Logger::LEVEL_INFO; diff --git a/src/Debug/Framework/Yii2/Module.php b/src/Debug/Framework/Yii2/Module.php index 0bbf1f1a..2a401f71 100644 --- a/src/Debug/Framework/Yii2/Module.php +++ b/src/Debug/Framework/Yii2/Module.php @@ -264,14 +264,13 @@ protected function collectEvent() } YiiEvent::on('*', '*', function (YiiEvent $event) { $this->collectedEvents[] = array( + 'eventClass' => \get_class($event), 'index' => \count($this->collectedEvents), - // 'time' => \microtime(true), + 'isStatic' => \is_object($event->sender) === false, + 'name' => $event->name, 'senderClass' => \is_object($event->sender) ? \get_class($event->sender) : $event->sender, - 'name' => $event->name, - 'eventClass' => \get_class($event), - 'isStatic' => \is_object($event->sender) === false, ); }); } @@ -495,7 +494,7 @@ private function logUserRolesPermissions(Debug $debug) 'ruleName', 'data', 'createdAt', - 'updatedAt' + 'updatedAt', ); $debug->table('roles', $authManager->getRolesByUser($user->id), $cols); $debug->table('permissions', $authManager->getPermissionsByUser($user->id), $cols); diff --git a/src/Debug/InternalEvents.php b/src/Debug/InternalEvents.php index 9b9a5236..a5333be7 100644 --- a/src/Debug/InternalEvents.php +++ b/src/Debug/InternalEvents.php @@ -74,7 +74,7 @@ public function getSubscriptions() EventManager::EVENT_PHP_SHUTDOWN => array( array('onShutdownHigh', PHP_INT_MAX), array('onShutdownHigh2', PHP_INT_MAX - 10), - array('onShutdownLow', PHP_INT_MAX * -1) + array('onShutdownLow', PHP_INT_MAX * -1), ), ); } @@ -230,10 +230,10 @@ public function onPrettify(Event $event) } $this->onPrettifyDo($event, $matches[1]); $event['value'] = $this->debug->abstracter->crateWithVals($event['value'], array( + 'addQuotes' => false, 'attribs' => array( 'class' => 'highlight language-' . $event['highlightLang'], ), - 'addQuotes' => false, 'contentType' => $event['contentType'], 'prettified' => $event['isPrettified'], 'prettifiedTag' => $event['isPrettified'], diff --git a/src/Debug/LogEntry.php b/src/Debug/LogEntry.php index ee074bfc..de5869f4 100644 --- a/src/Debug/LogEntry.php +++ b/src/Debug/LogEntry.php @@ -57,11 +57,11 @@ public function __construct(Debug $subject, $method, $args = array(), $meta = ar { $this->subject = $subject; $this->values = array( - 'method' => $method, + 'appendLog' => true, 'args' => $args, 'meta' => $meta, + 'method' => $method, 'numArgs' => 0, // number of initial non-meta aargs passed (does not include added default values) - 'appendLog' => true, 'return' => null, ); $metaExtracted = $this->metaExtract($this->values['args']); @@ -113,6 +113,7 @@ public function crate() */ public function export() { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $return = array( 'method' => $this->values['method'], 'args' => $this->values['args'], diff --git a/src/Debug/Method/Clear.php b/src/Debug/Method/Clear.php index ac58bdde..74cfa631 100644 --- a/src/Debug/Method/Clear.php +++ b/src/Debug/Method/Clear.php @@ -149,7 +149,7 @@ private function clearErrorsHelper(&$log, $clear = true) { $errorsNotCleared = array(); foreach ($log as $k => $logEntry) { - if (\in_array($logEntry['method'], array('error','warn'), true) === false) { + if (\in_array($logEntry['method'], array('error', 'warn'), true) === false) { continue; } $clear2 = $clear; @@ -201,7 +201,7 @@ private function clearLogHelper(&$log, $clearErrors = false, $entriesKeep = arra { $keep = $clearErrors ? array() - : array('error','warn'); + : array('error', 'warn'); if ($keep || $this->channelName) { // we need to go through and filter based on method and/or channel foreach ($log as $k => $logEntry) { @@ -288,21 +288,22 @@ private function updateLogEntry(LogEntry $logEntry, $args) { $bitmask = $logEntry['meta']['bitmask']; $callerInfo = $this->debug->backtrace->getCallerInfo(); + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $logEntry->setValues(array( 'method' => 'clear', 'args' => $args, 'meta' => \array_merge(array( - 'file' => $callerInfo['file'], - 'line' => $callerInfo['line'], 'bitmask' => $bitmask, + 'file' => $callerInfo['file'], 'flags' => array( 'alerts' => (bool) ($bitmask & Debug::CLEAR_ALERTS), 'log' => (bool) ($bitmask & Debug::CLEAR_LOG), 'logErrors' => (bool) ($bitmask & Debug::CLEAR_LOG_ERRORS), + 'silent' => (bool) ($bitmask & Debug::CLEAR_SILENT), 'summary' => (bool) ($bitmask & Debug::CLEAR_SUMMARY), 'summaryErrors' => (bool) ($bitmask & Debug::CLEAR_SUMMARY_ERRORS), - 'silent' => (bool) ($bitmask & Debug::CLEAR_SILENT), ), + 'line' => $callerInfo['line'], ), $logEntry['meta']), 'appendLog' => $args && !($bitmask & Debug::CLEAR_SILENT), 'forcePublish' => (bool) $args, // publish event even if collect = false diff --git a/src/Debug/Method/Count.php b/src/Debug/Method/Count.php index 04615bb9..b7bf5089 100644 --- a/src/Debug/Method/Count.php +++ b/src/Debug/Method/Count.php @@ -106,8 +106,8 @@ private function args(LogEntry $logEntry) $flags = $args[0]; } return array( - 'label' => $label, 'flags' => $flags, + 'label' => $label, ); } diff --git a/src/Debug/Method/Group.php b/src/Debug/Method/Group.php index c525f8c5..528a4e2d 100644 --- a/src/Debug/Method/Group.php +++ b/src/Debug/Method/Group.php @@ -97,7 +97,7 @@ public function methodGroup(LogEntry $logEntry) } if ($logEntry['args'] === array()) { // give a default label - $logEntry['args'] = array( 'group' ); + $logEntry['args'] = array('group'); $caller = $this->debug->backtrace->getCallerInfo(0, Backtrace::INCL_ARGS); $args = $this->autoArgs($caller); if ($args) { @@ -420,9 +420,9 @@ private function onOutputCleanup() // dummy / root group // eliminates need to test if entry has parent group 'childCount' => 0, - 'groupCount' => 0, 'depth' => 0, - ) + 'groupCount' => 0, + ), ), 'stackCount' => 1, ); @@ -485,11 +485,11 @@ private function outputCleanupPLE($index) if (\in_array($method, array('group', 'groupCollapsed'), true)) { $this->cleanupInfo['stack'][] = array( 'childCount' => 0, // includes any child groups + 'depth' => $stackCount, 'groupCount' => 0, 'index' => $index, 'indexEnd' => null, 'meta' => $logEntry['meta'], - 'depth' => $stackCount, ); $this->cleanupInfo['stack'][$stackCount - 1]['childCount']++; $this->cleanupInfo['stack'][$stackCount - 1]['groupCount']++; diff --git a/src/Debug/Method/GroupStack.php b/src/Debug/Method/GroupStack.php index e3e07222..ca375707 100644 --- a/src/Debug/Method/GroupStack.php +++ b/src/Debug/Method/GroupStack.php @@ -22,8 +22,8 @@ class GroupStack { private $currentInfo = array( 'curDepth' => 0, - 'minDepth' => 0, 'logEntries' => array(), + 'minDepth' => 0, ); private $debug; @@ -264,8 +264,8 @@ private function getCurrentGroupsInit($where) } $this->currentInfo = array( 'curDepth' => $curDepth, - 'minDepth' => $curDepth, 'logEntries' => array(), + 'minDepth' => $curDepth, ); } diff --git a/src/Debug/Method/Helper.php b/src/Debug/Method/Helper.php index 4bb0f6b4..605886e3 100644 --- a/src/Debug/Method/Helper.php +++ b/src/Debug/Method/Helper.php @@ -50,7 +50,7 @@ public function alertHasSubstitutions(array $args) __FUNCTION__, $args ); - $levelsAllowed = array('danger','error','info','success','warn','warning'); + $levelsAllowed = array('danger', 'error', 'info', 'success', 'warn', 'warning'); return $logEntry->containsSubstitutions() && \array_key_exists(1, $args) && \in_array($args[1], $levelsAllowed, true) === false; @@ -66,7 +66,7 @@ public function alertHasSubstitutions(array $args) public function alertLevel(LogEntry $logEntry) { $level = $logEntry->getMeta('level'); - $levelsAllowed = array('danger','error','info','success','warn','warning'); + $levelsAllowed = array('danger', 'error', 'info', 'success', 'warn', 'warning'); // Continue to allow bootstrap "levels" $levelTrans = array( 'danger' => 'error', diff --git a/src/Debug/Method/Profile.php b/src/Debug/Method/Profile.php index 21f3b390..a38ed9c7 100644 --- a/src/Debug/Method/Profile.php +++ b/src/Debug/Method/Profile.php @@ -123,7 +123,7 @@ public function profileEnd(LogEntry $logEntry) $name = $logEntry['meta']['name']; $args = array( $name !== null ? 'profileEnd: No such Profile: ' . $name - : 'profileEnd: Not currently profiling' + : 'profileEnd: Not currently profiling', ); if (isset($this->instances[$name])) { $instance = $this->instances[$name]; @@ -140,19 +140,19 @@ public function profileEnd(LogEntry $logEntry) $tableInfo['rows'][$k]['key'] = new Abstraction( Abstracter::TYPE_CALLABLE, array( - 'value' => $k, 'hideType' => true, // don't output 'callable' + 'value' => $k, ) ); } $caption = 'Profile \'' . $name . '\' Results'; $args = array($caption, 'no data'); if ($data) { - $args = array( $data ); + $args = array($data); $logEntry->setMeta(array( 'caption' => $caption, - 'totalCols' => array('ownTime'), 'tableInfo' => $tableInfo, + 'totalCols' => array('ownTime'), )); } unset($this->instances[$name]); @@ -235,7 +235,7 @@ public function tickFunction() $conditionsMet = \array_filter(array( $stackCount < 1, $stackCount === $stackCountInternal, // no change in stack - \preg_match($this->nsIgnoreRegex, $class) + \preg_match($this->nsIgnoreRegex, $class), )); if ($conditionsMet) { $this->timeLastTick = \microtime(true); @@ -298,10 +298,11 @@ protected function pushStack($funcName) { $this->funcStack[] = array( 'function' => $funcName, - 'tsStart' => $this->timeLastTick, 'subTime' => 0, // how much time spent in nested functions + 'tsStart' => $this->timeLastTick, ); if (!isset($this->data[$funcName])) { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $this->data[$funcName] = array( 'calls' => 0, 'totalTime' => 0, // time spent in function and nested func diff --git a/src/Debug/Method/Table.php b/src/Debug/Method/Table.php index 49e0a6ca..06493170 100644 --- a/src/Debug/Method/Table.php +++ b/src/Debug/Method/Table.php @@ -163,10 +163,10 @@ private function initMeta() */ $this->meta = $this->debug->arrayUtil->mergeDeep(array( 'caption' => null, - 'columns' => array(), 'columnNames' => array( TableRow::SCALAR => 'value', ), + 'columns' => array(), 'inclContext' => false, // for trace tables 'sortable' => true, 'tableInfo' => array( @@ -214,7 +214,7 @@ private function initTableInfoColumns() $columns[$key] = array( 'key' => isset($columnNames[$key]) ? $columnNames[$key] - : $key + : $key, ); } foreach ($this->meta['totalCols'] as $i => $key) { diff --git a/src/Debug/Method/Time.php b/src/Debug/Method/Time.php index a8a1f694..c2d19e7a 100644 --- a/src/Debug/Method/Time.php +++ b/src/Debug/Method/Time.php @@ -125,7 +125,7 @@ public function timeLog(LogEntry $logEntry) $debug, __FUNCTION__, array('Timer \'' . $label . '\' does not exist'), - \array_diff_key($meta, \array_flip(array('precision','unit'))) + \array_diff_key($meta, \array_flip(array('precision', 'unit'))) )); return; } @@ -137,7 +137,7 @@ public function timeLog(LogEntry $logEntry) $args[0] = $label . ': '; \array_splice($args, 1, 0, $elapsed); $logEntry['args'] = $args; - $logEntry['meta'] = \array_diff_key($meta, \array_flip(array('precision','unit'))); + $logEntry['meta'] = \array_diff_key($meta, \array_flip(array('precision', 'unit'))); $debug->log($logEntry); } @@ -210,7 +210,7 @@ protected function appendLogEntry($elapsed, LogEntry $logEntry) $debug, 'time', array($str), - \array_diff_key($meta, \array_flip(array('precision','silent','template','unit'))) + \array_diff_key($meta, \array_flip(array('precision', 'silent', 'template', 'unit'))) )); } } diff --git a/src/Debug/Plugin/AssertSettingTrait.php b/src/Debug/Plugin/AssertSettingTrait.php index 53e10df1..81d08ad7 100644 --- a/src/Debug/Plugin/AssertSettingTrait.php +++ b/src/Debug/Plugin/AssertSettingTrait.php @@ -27,13 +27,13 @@ trait AssertSettingTrait protected function assertSetting($setting) { $setting = $this->assertSettingPrep(\array_merge(array( + 'addParams' => array(), 'filter' => FILTER_VALIDATE_BOOLEAN, 'msg' => '', // (optional) message displayed if assertion fails 'name' => '', // ini name 'operator' => '==', 'valActual' => '__use_ini_val__', 'valCompare' => true, - 'addParams' => array(), ), $setting)); $assert = \is_array($setting['valCompare']) ? \in_array($setting['valActual'], $setting['valCompare'], true) diff --git a/src/Debug/Plugin/CustomMethod/General.php b/src/Debug/Plugin/CustomMethod/General.php index 12ab6cf8..0ea6cfd3 100644 --- a/src/Debug/Plugin/CustomMethod/General.php +++ b/src/Debug/Plugin/CustomMethod/General.php @@ -81,13 +81,13 @@ public function email($toAddr, $subject, $body) public function errorStats() { $stats = array( + 'counts' => \array_fill_keys( + array('deprecated','error','fatal','notice','strict','warning'), + array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0) + ), 'inConsole' => 0, 'inConsoleCategories' => array(), 'notInConsole' => 0, - 'counts' => \array_fill_keys( - array('fatal','error','warning','deprecated','notice','strict'), - array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0) - ) ); foreach ($this->debug->errorHandler->get('errors') as $error) { $category = $error['category']; @@ -202,8 +202,8 @@ public function prettify($string, $contentType) Debug::EVENT_PRETTIFY, $this->debug, array( - 'value' => $string, 'contentType' => $contentType, + 'value' => $string, ) ); return $event['value']; diff --git a/src/Debug/Plugin/Highlight.php b/src/Debug/Plugin/Highlight.php index 0f4dcceb..8c7eeea3 100644 --- a/src/Debug/Plugin/Highlight.php +++ b/src/Debug/Plugin/Highlight.php @@ -53,7 +53,7 @@ public function getAssets() } .debug pre[class*="language-"].line-numbers { padding-left: 3.8em; - }' + }', ), 'script' => array( './js/prism.js', diff --git a/src/Debug/Plugin/LogEnv.php b/src/Debug/Plugin/LogEnv.php index 48048d81..32c330f8 100644 --- a/src/Debug/Plugin/LogEnv.php +++ b/src/Debug/Plugin/LogEnv.php @@ -150,22 +150,22 @@ private function logSessionSettings($namePassed) $settings = array( array('name' => 'session.cookie_httponly'), array( - 'name' => 'session.cookie_lifetime', 'filter' => FILTER_VALIDATE_INT, + 'name' => 'session.cookie_lifetime', 'valCompare' => 0, ), array( - 'name' => 'session.name', 'filter' => FILTER_DEFAULT, + 'msg' => 'should not be PHPSESSID (just as %cexpose_php%c should be disabled)', + 'name' => 'session.name', + 'operator' => '!=', 'valActual' => $namePassed ?: \ini_get('session.name'), 'valCompare' => 'PHPSESSID', - 'operator' => '!=', - 'msg' => 'should not be PHPSESSID (just as %cexpose_php%c should be disabled)', ), array('name' => 'session.use_only_cookies'), array('name' => 'session.use_strict_mode'), array('name' => 'session.use_trans_sid', - 'valCompare' => false + 'valCompare' => false, ), ); \array_walk($settings, array($this, 'assertSetting')); diff --git a/src/Debug/Plugin/LogPhp.php b/src/Debug/Plugin/LogPhp.php index f734f1cd..926dabb1 100644 --- a/src/Debug/Plugin/LogPhp.php +++ b/src/Debug/Plugin/LogPhp.php @@ -153,10 +153,10 @@ private function assertExtensions() ); } $this->assertSetting(array( - 'name' => 'mbstring.func_overload', 'filter' => FILTER_VALIDATE_INT, - 'valCompare' => array(0, false), 'msg' => 'Multibyte string function overloading is enabled (is evil)', + 'name' => 'mbstring.func_overload', + 'valCompare' => array(0, false), )); } @@ -251,11 +251,11 @@ private function logPhpMemoryLimit() $memoryLimit === '-1' // overkill, but lets use assertSetting, which applies some styling ? $this->assertSetting(array( + 'msg' => 'should not be -1 (no limit)', 'name' => 'memory_limit', + 'operator' => '!=', 'valActual' => '-1', 'valCompare' => '-1', - 'operator' => '!=', - 'msg' => 'should not be -1 (no limit)', )) : $this->debug->log('memory_limit', $this->debug->utility->getBytes($memoryLimit)); } diff --git a/src/Debug/Plugin/LogReqRes.php b/src/Debug/Plugin/LogReqRes.php index 46c73d3f..75bbafd7 100644 --- a/src/Debug/Plugin/LogReqRes.php +++ b/src/Debug/Plugin/LogReqRes.php @@ -35,8 +35,8 @@ class LogReqRes implements SubscriberInterface public function getSubscriptions() { return array( - Debug::EVENT_PLUGIN_INIT => 'onPluginInit', Debug::EVENT_OUTPUT => array('logResponse', PHP_INT_MAX), + Debug::EVENT_PLUGIN_INIT => 'onPluginInit', ); } diff --git a/src/Debug/Psr3/Logger.php b/src/Debug/Psr3/Logger.php index 9c20c040..2bbba620 100644 --- a/src/Debug/Psr3/Logger.php +++ b/src/Debug/Psr3/Logger.php @@ -30,6 +30,7 @@ class Logger extends AbstractLogger public $debug; protected $cfg = array( + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder 'levelMap' => array( LogLevel::EMERGENCY => 'error', LogLevel::ALERT => 'alert', @@ -95,7 +96,7 @@ protected function assertValidLevel($level) private function checkTableContext(LogEntry $logEntry, $context) { if ( - \in_array($logEntry['method'], array('info','log'), true) + \in_array($logEntry['method'], array('info', 'log'), true) && isset($context['table']) && \is_array($context['table']) ) { @@ -250,7 +251,7 @@ private function setArgs(LogEntry $logEntry) private function setMeta(LogEntry $logEntry) { list($message, $context) = $logEntry['args']; - $meta = \array_intersect_key($context, \array_flip(array('channel','file','line'))); + $meta = \array_intersect_key($context, \array_flip(array('channel', 'file', 'line'))); // remove meta from context $context = \array_diff_key($context, $meta); $logEntry->setMeta($meta); diff --git a/src/Debug/Route/ChromeLogger.php b/src/Debug/Route/ChromeLogger.php index 75f6ed60..cbe634ed 100644 --- a/src/Debug/Route/ChromeLogger.php +++ b/src/Debug/Route/ChromeLogger.php @@ -59,6 +59,7 @@ class ChromeLogger extends AbstractRoute /** * @var array header data */ + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder protected $jsonData = array( 'version' => Debug::VERSION, 'columns' => array('log', 'backtrace', 'type'), @@ -235,7 +236,7 @@ protected function reduceData($max) */ $logBack = array(); foreach ($this->data['log'] as $i => $logEntry) { - if (\in_array($logEntry['method'], array('assert','error','warn'), true) === false) { + if (\in_array($logEntry['method'], array('assert', 'error', 'warn'), true) === false) { unset($this->data['log'][$i]); $logBack[$i] = $logEntry; } @@ -308,8 +309,8 @@ protected function reduceDataFill($max, $logBack = array()) $method = $logEntry['method']; if ($method === 'groupEnd') { $depth++; - // @phpcs:disable SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified // https://bugs.xdebug.org/view.php?id=2095 + // phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified } elseif (in_array($method, array('group', 'groupCollapsed'), true)) { $depth--; } elseif ($groupOnly) { diff --git a/src/Debug/Route/Firephp.php b/src/Debug/Route/Firephp.php index 1cf51f48..f4ff6ac5 100644 --- a/src/Debug/Route/Firephp.php +++ b/src/Debug/Route/Firephp.php @@ -109,13 +109,13 @@ public function processLogEntry(LogEntry $logEntry) $value = null; if ($method === 'alert') { $value = $this->methodAlert($logEntry); - } elseif (\in_array($method, array('group','groupCollapsed'), true)) { + } elseif (\in_array($method, array('group', 'groupCollapsed'), true)) { $logEntry['firephpMeta']['Label'] = $args[0]; $logEntry['firephpMeta']['Collapsed'] = $method === 'groupCollapsed' // yes, strings ? 'true' : 'false'; - } elseif (\in_array($method, array('profileEnd','table','trace'), true)) { + } elseif (\in_array($method, array('profileEnd', 'table', 'trace'), true)) { $value = $this->methodTabular($logEntry); } elseif (\count($args)) { $this->dumper->processLogEntry($logEntry); diff --git a/src/Debug/Route/Html.php b/src/Debug/Route/Html.php index 883b1a1a..65971194 100644 --- a/src/Debug/Route/Html.php +++ b/src/Debug/Route/Html.php @@ -228,8 +228,8 @@ private function buildOutput() $str = 'debug->html->buildAttribString(array( 'class' => 'debug', // channel list gets built as log processed... we'll str_replace this... - 'data-channels' => '{{channels}}', 'data-channel-name-root' => $this->channelNameRoot, + 'data-channels' => '{{channels}}', 'data-options' => array( 'drawer' => $this->cfg['drawer'], 'linkFilesTemplateDefault' => $lftDefault ?: null, @@ -274,11 +274,11 @@ protected function buildChannelTree() ? $channels[$pathFq] : $channelRoot->getChannel($pathFq); $ref[$k] = array( + 'channels' => array(), 'options' => array( 'icon' => $channel->getCfg('channelIcon', Debug::CONFIG_DEBUG), 'show' => $channel->getCfg('channelShow', Debug::CONFIG_DEBUG), ), - 'channels' => array(), ); } $ref = &$ref[$k]['channels']; diff --git a/src/Debug/Route/Html/ErrorSummary.php b/src/Debug/Route/Html/ErrorSummary.php index e34ea851..37d0f4a1 100644 --- a/src/Debug/Route/Html/ErrorSummary.php +++ b/src/Debug/Route/Html/ErrorSummary.php @@ -32,10 +32,6 @@ class ErrorSummary 'header' => 'Deprecated', 'msg' => 'There were %d deprecated notices', ), - 'strict' => array( - 'header' => 'Strict', - 'msg' => 'There were %d strict errors', - ), 'error' => array( 'header' => 'Errors', 'msg' => 'There were %d errors', @@ -44,6 +40,10 @@ class ErrorSummary 'header' => 'Notices', 'msg' => 'There were %d notices', ), + 'strict' => array( + 'header' => 'Strict', + 'msg' => 'There were %d strict errors', + ), 'warning' => array( 'header' => 'Warnings', 'msg' => 'There were %d warnings', diff --git a/src/Debug/Route/Html/Tabs.php b/src/Debug/Route/Html/Tabs.php index 8e4c48de..6ee7677c 100644 --- a/src/Debug/Route/Html/Tabs.php +++ b/src/Debug/Route/Html/Tabs.php @@ -122,8 +122,8 @@ private function buildTab(Debug $debug) 'a', array( 'class' => array( - 'nav-link' => true, 'active' => $isActive, + 'nav-link' => true, ), 'data-target' => '.' . $this->nameToClassname($name), 'data-toggle' => 'tab', @@ -147,10 +147,10 @@ private function buildTabPane(Debug $debug) $this->route->setChannelRegex('#^' . \preg_quote($name, '#') . '(\.|$)#'); $str = 'debug->html->buildAttribString(array( 'class' => array( + $this->nameToClassname($name) => true, 'active' => $isActive, - 'tab-pane', + 'tab-pane' => true, 'tab-primary' => $isActive, - $this->nameToClassname($name), ), 'data-options' => array( 'sidebar' => $this->route->getCfg('sidebar'), diff --git a/src/Debug/Route/Script.php b/src/Debug/Route/Script.php index 0998017a..f134f8b4 100644 --- a/src/Debug/Route/Script.php +++ b/src/Debug/Route/Script.php @@ -126,7 +126,7 @@ public function processLogEntry(LogEntry $logEntry) $meta = $logEntry['meta']; if ($method === 'assert') { \array_unshift($args, false); - } elseif (\in_array($method, array('error','warn'), true)) { + } elseif (\in_array($method, array('error', 'warn'), true)) { if (isset($meta['file'])) { $args[] = \sprintf('%s: line %s', $meta['file'], $meta['line']); } diff --git a/src/Debug/Route/Wamp.php b/src/Debug/Route/Wamp.php index 4bcab7be..8d5b02bc 100644 --- a/src/Debug/Route/Wamp.php +++ b/src/Debug/Route/Wamp.php @@ -176,7 +176,7 @@ public function onError(Error $error) 'class' => $error['type'] & $this->debug->getCfg('errorMask', Debug::CONFIG_DEBUG) ? 'error' : 'warn', - ) + ), ) )); } @@ -228,7 +228,6 @@ public function onShutdown() * * @return void * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter */ public function processLogEntries(Event $event = null) @@ -360,9 +359,9 @@ private function publishMeta() private function publishMetaGet() { $metaVals = array( - 'processId' => \getmypid(), - 'HTTP_HOST' => null, 'HTTPS' => null, + 'HTTP_HOST' => null, + 'processId' => \getmypid(), 'REMOTE_ADDR' => null, 'REQUEST_METHOD' => $this->debug->serverRequest->getMethod(), 'REQUEST_TIME' => null, diff --git a/src/Debug/ServiceProvider.php b/src/Debug/ServiceProvider.php index def79032..51abb742 100644 --- a/src/Debug/ServiceProvider.php +++ b/src/Debug/ServiceProvider.php @@ -100,12 +100,12 @@ public function register(Container $container) $debug = $container['debug']; $existingInstance = \bdk\ErrorHandler::getInstance(); $cfg = \array_merge(array( - 'onEUserError' => null, // don't halt script / log E_USER_ERROR to system_log when 'continueToNormal' 'emailer' => array( 'emailBacktraceDumper' => static function ($backtrace) use ($debug) { return $debug->getDump('text')->valDumper->dump($backtrace); }, ), + 'onEUserError' => null, // don't halt script / log E_USER_ERROR to system_log when 'continueToNormal' ), $debug->getCfg('errorHandler', \bdk\Debug::CONFIG_INIT)); if ($existingInstance) { $existingInstance->setCfg($cfg); diff --git a/src/Debug/Utility/ErrorLevel.php b/src/Debug/Utility/ErrorLevel.php index e71bef42..5e60f79e 100644 --- a/src/Debug/Utility/ErrorLevel.php +++ b/src/Debug/Utility/ErrorLevel.php @@ -31,6 +31,7 @@ public static function getConstants($phpVer = null) { $phpVer = $phpVer ?: PHP_VERSION; $phpVer = self::normalizePhpVer($phpVer); + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $constants = array( 'E_ERROR' => 1, 'E_WARNING' => 2, @@ -70,8 +71,8 @@ public static function toConstantString($errorReportingLevel = null, $phpVer = n : $errorReportingLevel; $allConstants = self::getConstants($phpVer); // includes E_ALL $flags = array( - 'on' => \array_keys(self::filterConstantsByLevel($allConstants, $errorReportingLevel)), // excludes E_ALL 'off' => array(), + 'on' => \array_keys(self::filterConstantsByLevel($allConstants, $errorReportingLevel)), // excludes E_ALL ); $eAll = $allConstants['E_ALL']; unset($allConstants['E_ALL']); @@ -139,8 +140,8 @@ private static function filterConstantsByLevel($constants, $level) private static function getNegateFlags($errorReportingLevel, $allConstants, $eAll, $explicitStrict) { $flags = array( - 'on' => array('E_ALL'), 'off' => array(), + 'on' => array('E_ALL'), ); foreach ($allConstants as $constName => $constValue) { $isExplicit = $explicitStrict && $constName === 'E_STRICT'; diff --git a/src/Debug/Utility/FileTree.php b/src/Debug/Utility/FileTree.php index e033e029..afda4195 100644 --- a/src/Debug/Utility/FileTree.php +++ b/src/Debug/Utility/FileTree.php @@ -40,10 +40,10 @@ public function filesToTree($files, $excludedCounts = array(), $condense = false } $node = &$this->getTreeNode($tree, $dirs); $node[] = new Abstraction(Abstracter::TYPE_STRING, array( - 'value' => $file, 'attribs' => array( 'data-file' => $filepath, ), + 'value' => $file, )); unset($node); } @@ -74,10 +74,10 @@ private function addExcludedToTree($tree, $excludedCounts) } $node = &$this->getTreeNode($tree, $dirs); \array_unshift($node, new Abstraction(Abstracter::TYPE_STRING, array( - 'value' => $count . ' omitted', 'attribs' => array( 'class' => 'exclude-count', ), + 'value' => $count . ' omitted', ))); } return $tree; @@ -120,8 +120,8 @@ private function condenseTree($tree) $out = array(); $stack = array( array( - 'src' => &$tree, 'out' => &$out, + 'src' => &$tree, ), ); while ($stack) { @@ -152,8 +152,8 @@ private function condenseTreeFrame($cur, &$stack) // initialize output array $cur['out'][$kOut] = array(); $stack[] = array( - 'src' => &$val, 'out' => &$cur['out'][$kOut], + 'src' => &$val, ); } } diff --git a/src/Debug/Utility/Html.php b/src/Debug/Utility/Html.php index ff9de2fa..ce6a67b7 100644 --- a/src/Debug/Utility/Html.php +++ b/src/Debug/Utility/Html.php @@ -31,7 +31,7 @@ class Html * * @var array */ - public static $htmlEmptyTags = array('area','base','br','col','embed','hr','img','input','link','meta','param','source','track','wbr'); + public static $htmlEmptyTags = array('area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'); /** * Used by parseAttribString @@ -213,6 +213,7 @@ public static function parseTag($tag, $options = null) $regexTag2 = '#^<(?:\/\s*)?([^\s>]+)(.*?)\/?>$#s'; $tag = \trim($tag); if (\preg_match($regexTag, $tag, $matches)) { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return array( 'tagname' => $matches[1], 'attribs' => self::parseAttribString($matches[2], $options), @@ -220,6 +221,7 @@ public static function parseTag($tag, $options = null) ); } if (\preg_match($regexTag2, $tag, $matches)) { + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return array( 'tagname' => $matches[1], 'attribs' => self::parseAttribString($matches[2], $options), @@ -457,7 +459,7 @@ private static function parseAttribValue($name, $val, $options) private static function parseAttribBoolEnum($val) { $val = \strtolower($val); - return \in_array($val, array('true','false'), true) + return \in_array($val, array('true', 'false'), true) ? $val === 'true' : false; } diff --git a/src/Debug/Utility/Php.php b/src/Debug/Utility/Php.php index 2e7e7051..d7967250 100644 --- a/src/Debug/Utility/Php.php +++ b/src/Debug/Utility/Php.php @@ -235,7 +235,7 @@ private static function getReflectorFromString($string) . '$/'; $matches = array(); \preg_match($regex, $string, $matches); - $defaults = \array_fill_keys(array('class','constant','property','method'), null); + $defaults = \array_fill_keys(array('class', 'constant', 'property', 'method'), null); $matches = \array_merge($defaults, $matches); if ($matches['method']) { return new ReflectionMethod($matches['class'], $matches['method']); diff --git a/src/Debug/Utility/PhpDoc.php b/src/Debug/Utility/PhpDoc.php index 08c264aa..c6658cd5 100644 --- a/src/Debug/Utility/PhpDoc.php +++ b/src/Debug/Utility/PhpDoc.php @@ -84,8 +84,8 @@ protected static function extractTypeFromBody($body) } } return array( - 'type' => $type, 'desc' => \trim(\substr($body, \strlen($type))) ?: null, + 'type' => $type, ); } @@ -131,8 +131,8 @@ private function getTagParser($tag) private function parseComment($comment) { $parsed = array( - 'summary' => null, 'desc' => null, + 'summary' => null, ); $elementName = $this->reflector ? $this->reflector->getName() : null; $matches = array(); @@ -156,12 +156,14 @@ private function parseComment($comment) summary ends with empty whiteline or "." followed by \n */ $split = \preg_split('/(\.[\r\n]+|[\r\n]{2})/', $comment, 2, PREG_SPLIT_DELIM_CAPTURE); - $split = \array_replace(array('','',''), $split); + $split = \array_replace(array('', '', ''), $split); // assume that summary and desc won't be "0".. remove empty value and merge - return \array_merge($parsed, \array_filter(array( - 'summary' => \trim($split[0] . $split[1]), // split[1] is the ".\n" + $parsed = \array_merge($parsed, \array_filter(array( 'desc' => $this->trimDesc(\trim($split[2])), + 'summary' => \trim($split[0] . $split[1]), // split[1] is the ".\n" ))); + \ksort($parsed); + return $parsed; } /** @@ -183,9 +185,9 @@ private function parseComment($comment) private function parseTag($tagName, $tagStr = '', $elementName = null) { $parser = \array_merge(array( + 'callable' => array(), 'parts' => array(), 'regex' => null, - 'callable' => array(), ), $this->getTagParser($tagName)); $parsed = \array_fill_keys($parser['parts'], null); if (isset($parser['regex'])) { @@ -201,6 +203,7 @@ private function parseTag($tagName, $tagStr = '', $elementName = null) $parsed = \array_merge($parsed, \call_user_func($callable, $tagStr, $tagName, $parsed, $elementName)); } $parsed['desc'] = $this->trimDesc($parsed['desc']); + \ksort($parsed); return $parsed; } @@ -283,15 +286,20 @@ protected function setParsers() { $this->parsers = array( array( - 'tags' => array('param','property','property-read', 'property-write', 'var'), - 'parts' => array('type','name','desc'), 'callable' => array( array($this, 'extractTypeFromBody'), array($this, 'tagParam'), ), + 'parts' => array('type','name','desc'), + 'tags' => array('param','property','property-read', 'property-write', 'var'), ), array( - 'tags' => array('method'), + 'callable' => function ($tagStr, $tagName, $parsed) { + $parsed['param'] = $this->parseMethodParams($parsed['param']); + $parsed['static'] = $parsed['static'] !== null; + $parsed['type'] = $this->typeNormalize($parsed['type']); + return $parsed; + }, 'parts' => array('static', 'type', 'name', 'param', 'desc'), 'regex' => '/' . '(?:(?Pstatic)\s+)?' @@ -300,18 +308,9 @@ protected function setParsers() . '\((?P((?>[^()]+)|(?R))*)\)' // see http://php.net/manual/en/regexp.reference.recursive.php . '(?:\s+(?P.*))?' . '/s', - 'callable' => function ($tagStr, $tagName, $parsed) { - $parsed['param'] = $this->parseMethodParams($parsed['param']); - $parsed['static'] = $parsed['static'] !== null; - $parsed['type'] = $this->typeNormalize($parsed['type']); - return $parsed; - }, + 'tags' => array('method'), ), array( - 'tags' => array('return', 'throws'), - 'parts' => array('type','desc'), - 'regex' => '/^(?P.*?)' - . '(?:\s+(?P.*))?$/s', 'callable' => array( array($this, 'extractTypeFromBody'), function ($tagStr, $tagName, $parsed) { @@ -319,34 +318,38 @@ function ($tagStr, $tagName, $parsed) { return $parsed; }, ), + 'parts' => array('type','desc'), + 'regex' => '/^(?P.*?)' + . '(?:\s+(?P.*))?$/s', + 'tags' => array('return', 'throws'), ), array( - 'tags' => array('author'), 'parts' => array('name', 'email','desc'), 'regex' => '/^(?P[^<]+)' . '(?:\s+<(?P\S*)>)?' . '(?:\s+(?P.*))?' // desc isn't part of the standard . '$/s', + 'tags' => array('author'), ), array( - 'tags' => array('link'), 'parts' => array('uri', 'desc'), 'regex' => '/^(?P\S+)' . '(?:\s+(?P.*))?$/s', + 'tags' => array('link'), ), array( - 'tags' => array('see'), 'parts' => array('uri', 'fqsen', 'desc'), 'regex' => '/^(?:' . '(?Phttps?:\/\/\S+)|(?P\S+)' . ')' . '(?:\s+(?P.*))?$/s', + 'tags' => array('see'), ), array( // default - 'tags' => array(), 'parts' => array('desc'), 'regex' => '/^(?P.*?)$/s', + 'tags' => array(), ), ); } diff --git a/src/Debug/Utility/PhpDocBase.php b/src/Debug/Utility/PhpDocBase.php index 72fd7bc7..a17dd2a0 100644 --- a/src/Debug/Utility/PhpDocBase.php +++ b/src/Debug/Utility/PhpDocBase.php @@ -108,12 +108,13 @@ protected function parseMethodParams($paramStr) foreach ($params as $i => $str) { \preg_match('/^(?:([^=]*?)\s)?([^\s=]+)(?:\s*=\s*(\S+))?$/', $str, $matches); $info = array( - 'type' => $this->typeNormalize($matches[1]), 'name' => $matches[2], + 'type' => $this->typeNormalize($matches[1]), ); if (!empty($matches[3])) { $info['defaultValue'] = $matches[3]; } + \ksort($info); $params[$i] = $info; } return $params; @@ -128,7 +129,7 @@ protected function parseMethodParams($paramStr) */ protected function typeNormalize($type) { - if (\in_array($type, array('',null), true)) { + if (\in_array($type, array('', null), true)) { return null; } return \preg_replace_callback('/\b(boolean|integer|self)\b/', function ($matches) { diff --git a/src/Debug/Utility/SerializeLog.php b/src/Debug/Utility/SerializeLog.php index 2944917f..33d1baa2 100644 --- a/src/Debug/Utility/SerializeLog.php +++ b/src/Debug/Utility/SerializeLog.php @@ -49,7 +49,7 @@ public static function import($data, Debug $debug = null) } $debug->setCfg($data['config']); unset($data['config'], $data['version']); - foreach (array('alerts','log','logSummary') as $cat) { + foreach (array('alerts', 'log', 'logSummary') as $cat) { $data[$cat] = self::importGroup($cat, $data[$cat]); } foreach ($data as $k => $v) { @@ -102,10 +102,10 @@ public static function unserialize($str) return false; } $data = \array_merge(array( - 'version' => '2.3', 'config' => array( 'channels' => array(), ), + 'version' => '2.3', ), $data); if (isset($data['rootChannel'])) { $data['config']['channelName'] = $data['rootChannel']; @@ -141,7 +141,7 @@ private static function extractLog($str) * * @return LogEntry */ - private static function importLogEntry($vals) + private static function importLogEntry(array $vals) { $vals = \array_replace(array('', array(), array()), $vals); if (self::$isLegacyData) { @@ -186,7 +186,7 @@ private static function importGroup($cat, $data) * * @return array */ - private static function importLegacy($vals) + private static function importLegacy(array $vals) { foreach ($vals as $k => $v) { if (\is_array($v) === false) { @@ -211,32 +211,28 @@ private static function importLegacy($vals) /** * Convert legacy object abstraction data * - * @param array $abs Abstraction values + * @param array $absValues Abstraction values * * @return array */ - private static function importLegacyObj($abs) + private static function importLegacyObj(array $absValues) { - $abs = AbstractObject::buildObjValues($abs); - if (isset($abs['collectMethods'])) { - if ($abs['collectMethods'] === false) { - $abs['cfgFlags'] &= ~AbstractObject::METHOD_COLLECT; + $absValues = AbstractObject::buildObjValues($absValues); + if (isset($absValues['collectMethods'])) { + if ($absValues['collectMethods'] === false) { + $absValues['cfgFlags'] &= ~AbstractObject::METHOD_COLLECT; } - unset($abs['collectMethods']); + unset($absValues['collectMethods']); } - $baseMethodInfoRef = new \ReflectionProperty('bdk\Debug\Abstraction\AbstractObjectMethods', 'baseMethodInfo'); - $baseMethodInfoRef->setAccessible(true); - $baseMethodInfo = $baseMethodInfoRef->getValue(); - foreach ($abs['methods'] as $name => $meth) { - $abs['methods'][$name] = \array_merge($baseMethodInfo, $meth); + $baseMethodInfo = \bdk\Debug\Abstraction\AbstractObjectMethods::buildMethodValues(); + foreach ($absValues['methods'] as $name => $meth) { + $absValues['methods'][$name] = \array_merge($baseMethodInfo, $meth); } - $basePropInfoRef = new \ReflectionProperty('bdk\Debug\Abstraction\AbstractObjectProperties', 'basePropInfo'); - $basePropInfoRef->setAccessible(true); - $basePropInfo = $basePropInfoRef->getValue(); - foreach ($abs['properties'] as $name => $prop) { - $abs['properties'][$name] = \array_merge($basePropInfo, $prop); + $basePropInfo = \bdk\Debug\Abstraction\AbstractObjectProperties::buildPropValues(); + foreach ($absValues['properties'] as $name => $prop) { + $absValues['properties'][$name] = \array_merge($basePropInfo, $prop); } - return $abs; + return $absValues; } /** @@ -283,7 +279,7 @@ private static function serializeGetData(Debug $debug) 'requestId', 'runtime', ))); - foreach (array('alerts','log','logSummary') as $cat) { + foreach (array('alerts', 'log', 'logSummary') as $cat) { $data[$cat] = self::serializeGroup($data[$cat]); } return $data; @@ -296,7 +292,7 @@ private static function serializeGetData(Debug $debug) * * @return array */ - private static function serializeGroup($data) + private static function serializeGroup(array $data) { foreach ($data as $i => $val) { if (!($val instanceof LogEntry)) { diff --git a/src/Debug/Utility/StopWatch.php b/src/Debug/Utility/StopWatch.php index 26a6e988..e096ea23 100644 --- a/src/Debug/Utility/StopWatch.php +++ b/src/Debug/Utility/StopWatch.php @@ -35,7 +35,7 @@ public function __construct($vals = array()) 0, isset($vals['requestTime']) ? $vals['requestTime'] - : $_SERVER['REQUEST_TIME_FLOAT'] + : $_SERVER['REQUEST_TIME_FLOAT'], ); } diff --git a/src/Debug/Utility/StringUtil.php b/src/Debug/Utility/StringUtil.php index 32488509..ee47c611 100644 --- a/src/Debug/Utility/StringUtil.php +++ b/src/Debug/Utility/StringUtil.php @@ -347,9 +347,9 @@ private static function isBase64EncodedTestStats($val) } $stats = array( 'lower' => array(\preg_match_all('/[a-z]/', $val), 40.626, 8), - 'upper' => array(\preg_match_all('/[A-Z]/', $val), 40.625, 8), 'num' => array(\preg_match_all('/[0-9]/', $val), 15.625, 8), 'other' => array(\preg_match_all('/[+\/]/', $val), 3.125, 5), + 'upper' => array(\preg_match_all('/[A-Z]/', $val), 40.625, 8), ); foreach ($stats as $stat) { $per = $stat[0] * 100 / $strlen; diff --git a/src/Debug/Utility/UseStatements.php b/src/Debug/Utility/UseStatements.php index 4331b37d..9c40a9ad 100644 --- a/src/Debug/Utility/UseStatements.php +++ b/src/Debug/Utility/UseStatements.php @@ -217,8 +217,8 @@ private static function recordTokenArray($token) private static function recordTokenClass() { self::$currentUse = array( - 'class' => self::$groupNamespace ?: '', 'alias' => '', + 'class' => self::$groupNamespace ?: '', ); self::$recordPart = 'class'; } @@ -282,8 +282,8 @@ private static function setRecordInfo($token) self::$record = 'class'; self::$recordPart = 'class'; self::$currentUse = array( - 'class' => '', 'alias' => '', + 'class' => '', ); break; } diff --git a/src/Debug/Utility/Utf8Buffer.php b/src/Debug/Utility/Utf8Buffer.php index 7553af52..ca829453 100644 --- a/src/Debug/Utility/Utf8Buffer.php +++ b/src/Debug/Utility/Utf8Buffer.php @@ -22,15 +22,15 @@ class Utf8Buffer private $curI; private $stats = array(); private static $special = array( - 'regex' => array( - '#[^\S \r\n\t]#u', // with /u modifier, \s is equivalent to \p{Z} - '#[^\P{C}\r\n\t]#u', // invisible control characters and unused code points. (includes zwsp & BOM) - ), 'chars' => array( "\xef\xbf\xbd", // "Replacement Character" // "\xe2\x80\x8b", // zero-width Space (included in \p{Cf}) // "\xef\xbb\xbf", // UTF-8 BOM (included in \p{Cf}) ), + 'regex' => array( + '#[^\S \r\n\t]#u', // with /u modifier, \s is equivalent to \p{Z} + '#[^\P{C}\r\n\t]#u', // invisible control characters and unused code points. (includes zwsp & BOM) + ), ); private $str = ''; @@ -49,8 +49,8 @@ public function __construct($string) 'bytesSpecial' => 0, // special UTF-8 'bytesUtf8' => 0, // includes ASCII 'calculated' => false, // internal check if stats calculated - 'percentBinary' => 0, 'mbStrlen' => 0, + 'percentBinary' => 0, 'strlen' => Utf8::strlen($string), ); $this->str = $string; diff --git a/src/Debug/Utility/Utf8Dump.php b/src/Debug/Utility/Utf8Dump.php index ace2657a..2b4955b1 100644 --- a/src/Debug/Utility/Utf8Dump.php +++ b/src/Debug/Utility/Utf8Dump.php @@ -19,6 +19,7 @@ */ class Utf8Dump { + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder private $charDesc = array( 0x00 => 'NUL', 0x01 => 'SOH (start of heading)', diff --git a/src/Debug/Utility/Utility.php b/src/Debug/Utility/Utility.php index 67168fb8..7c8723c3 100644 --- a/src/Debug/Utility/Utility.php +++ b/src/Debug/Utility/Utility.php @@ -40,7 +40,7 @@ public static function emitHeaders($headers) } $file = ''; $line = 0; - // @phpcs:disable SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified + // phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified if (headers_sent($file, $line)) { throw new \RuntimeException('Headers already sent: ' . $file . ', line ' . $line); } @@ -106,7 +106,7 @@ public static function getBytes($size, $returnInt = false) if ($returnInt) { return (int) $size; } - $units = array('B','kB','MB','GB','TB','PB'); + $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB'); $exp = (int) \floor(\log((float) $size, 1024)); $pow = \pow(1024, $exp); $size = (int) $pow < 1 @@ -145,11 +145,11 @@ public static function getEmittedHeader($key = 'Content-Type', $delimiter = ', ' */ public static function getEmittedHeaders() { - // @phpcs:disable SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified + // phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified $list = headers_list(); $headers = array(); foreach ($list as $header) { - list($key, $value) = \array_replace(array('',''), \explode(': ', $header, 2)); + list($key, $value) = \array_replace(array('', ''), \explode(': ', $header, 2)); $headers[$key][] = $value; } return $headers; @@ -209,7 +209,7 @@ public static function gitBranch() public static function httpMethodHasBody($method) { // don't expect a request body for these methods - $noBodyMethods = array('CONNECT','DELETE','GET','HEAD','OPTIONS','TRACE'); + $noBodyMethods = array('CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'TRACE'); return \in_array($method, $noBodyMethods, true) === false; } @@ -334,7 +334,7 @@ private static function parseBytes($size) } $matches = array(); if (\preg_match('/^([\d,.]+)\s?([kmgtp])?b?$/i', $size, $matches)) { - $matches = \array_replace(array('','',''), $matches); + $matches = \array_replace(array('', '', ''), $matches); $size = (float) \str_replace(',', '', $matches[1]); switch (\strtolower($matches[2])) { case 'p': diff --git a/src/ErrorHandler/Error.php b/src/ErrorHandler/Error.php index 34821b9d..947f792d 100644 --- a/src/ErrorHandler/Error.php +++ b/src/ErrorHandler/Error.php @@ -32,28 +32,28 @@ class Error extends Event protected static $errCategories = array( self::CAT_DEPRECATED => array( E_DEPRECATED, E_USER_DEPRECATED ), self::CAT_ERROR => array( E_USER_ERROR, E_RECOVERABLE_ERROR ), + self::CAT_FATAL => array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_CORE_ERROR ), self::CAT_NOTICE => array( E_NOTICE, E_USER_NOTICE ), self::CAT_STRICT => array( E_STRICT ), self::CAT_WARNING => array( E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING ), - self::CAT_FATAL => array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_CORE_ERROR ), ); protected static $errTypes = array( - E_ERROR => 'Fatal Error', // handled via shutdown function - E_WARNING => 'Warning', - E_PARSE => 'Parsing Error', // handled via shutdown function - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core Error', // handled via shutdown function - E_CORE_WARNING => 'Core Warning', // handled? + E_ALL => 'E_ALL', // listed here for completeness E_COMPILE_ERROR => 'Compile Error', // handled via shutdown function E_COMPILE_WARNING => 'Compile Warning', // handled? - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_ALL => 'E_ALL', // listed here for completeness - E_STRICT => 'Strict', // php 5.0 : 2048 - E_RECOVERABLE_ERROR => 'Recoverable Error', // php 5.2 : 4096 + E_CORE_ERROR => 'Core Error', // handled via shutdown function + E_CORE_WARNING => 'Core Warning', // handled? E_DEPRECATED => 'Deprecated', // php 5.3 : 8192 + E_ERROR => 'Fatal Error', // handled via shutdown function + E_NOTICE => 'Notice', + E_PARSE => 'Parsing Error', // handled via shutdown function + E_RECOVERABLE_ERROR => 'Recoverable Error', // php 5.2 : 4096 + E_STRICT => 'Strict', // php 5.0 : 2048 E_USER_DEPRECATED => 'User Deprecated', // php 5.3 : 16384 + E_USER_ERROR => 'User Error', + E_USER_NOTICE => 'User Notice', + E_USER_WARNING => 'User Warning', + E_WARNING => 'Warning', ); protected static $userErrors = array( E_USER_DEPRECATED, @@ -74,7 +74,7 @@ class Error extends Event /** * @var array Array of key/values */ - protected $values = array( + protected $values = array( // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder 'type' => null, // int: The severity / level / one of the E_* constants 'message' => '', // The error message 'file' => null, // Filepath the error was raised in @@ -108,7 +108,7 @@ public function __construct(ErrorHandler $errHandler, array $values) unset($this->values['vars']['GLOBALS']); $errorCaller = $errHandler->get('errorCaller'); if ($errorCaller) { - $errorCallerVals = \array_intersect_key($errorCaller, \array_flip(array('file','line'))); + $errorCallerVals = \array_intersect_key($errorCaller, \array_flip(array('file', 'line'))); $this->values = \array_merge($this->values, $errorCallerVals); } if ($this->backtrace === null && \in_array($this->values['type'], array(E_ERROR, E_USER_ERROR), true) && $this->values['exception'] === null) { @@ -276,10 +276,10 @@ public function setValues(array $values = array()) 'isFirstOccur' => !$prevOccurance, 'isHtml' => $this->isHtml(), 'isSuppressed' => $isSuppressed, - 'typeStr' => self::$errTypes[$errType], 'message' => $this->isHtml() ? \str_replace('values['message']) : $this->values['message'], + 'typeStr' => self::$errTypes[$errType], ) ); } diff --git a/src/ErrorHandler/ErrorHandler.php b/src/ErrorHandler/ErrorHandler.php index 4b6e6992..c53956e3 100644 --- a/src/ErrorHandler/ErrorHandler.php +++ b/src/ErrorHandler/ErrorHandler.php @@ -45,6 +45,7 @@ class ErrorHandler extends AbstractErrorHandler public function __construct(EventManager $eventManager, $cfg = array()) { $this->eventManager = $eventManager; + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $this->cfg = array( 'continueToPrevHandler' => true, // whether to continue to previously defined handler (if there is/was a prev handler) // prev handler will not be called if error event propagation stopped @@ -54,7 +55,6 @@ public function __construct(EventManager $eventManager, $cfg = array()) 'errorThrow' => 0, // bitmask: error types that should converted to ErrorException and thrown 'onError' => null, // callable : shortcut for subscribing to errorHandler.error Event // will receive error Event object - 'onFirstError' => null, // callable : called on first error.. usefull for lazy-loading subscriberInterface 'onEUserError' => 'normal', // only applicable if we're not continuing to a prev error handler // (continueToPrevHandler = false, there's no previous handler, or propagation stopped) // 'continue' : sets error[continueToNormal] = false @@ -69,10 +69,11 @@ public function __construct(EventManager $eventManager, $cfg = array()) // null : use error's error[continueToNormal] value // continueToNormal true -> log // continueToNormal false -> continue + 'onFirstError' => null, // callable : called on first error.. usefull for lazy-loading subscriberInterface 'suppressNever' => E_ERROR | E_PARSE | E_RECOVERABLE_ERROR | E_USER_ERROR, // emailer options - 'enableEmailer' => false, 'emailer' => array(), + 'enableEmailer' => false, // stats options 'enableStats' => false, 'stats' => array( @@ -449,6 +450,7 @@ private function continueToPrevHandlerException(Error $error) */ protected function errorFactory(self $handler, $errType, $errMsg, $file, $line, $vars = array()) { + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return new Error($handler, array( 'type' => $errType, 'message' => $errMsg, diff --git a/src/ErrorHandler/Plugin/Emailer.php b/src/ErrorHandler/Plugin/Emailer.php index 6ad74b52..1f5b0a45 100644 --- a/src/ErrorHandler/Plugin/Emailer.php +++ b/src/ErrorHandler/Plugin/Emailer.php @@ -40,6 +40,7 @@ public function __construct($cfg = array()) { $this->serverParams = $_SERVER; $this->cfg = array( + 'dateTimeFmt' => 'Y-m-d H:i:s T', 'emailBacktraceDumper' => null, // callable that receives backtrace array & returns string 'emailFrom' => null, // null = use php's default (php.ini: sendmail_from) 'emailFunc' => 'mail', @@ -51,7 +52,6 @@ public function __construct($cfg = array()) ? $this->serverParams['SERVER_ADMIN'] : null, 'emailTraceMask' => E_ERROR | E_WARNING | E_USER_ERROR | E_USER_NOTICE, - 'dateTimeFmt' => 'Y-m-d H:i:s T', ); $this->setCfg($cfg); } diff --git a/src/ErrorHandler/Plugin/Stats.php b/src/ErrorHandler/Plugin/Stats.php index 2360ffc4..7fb33e1d 100644 --- a/src/ErrorHandler/Plugin/Stats.php +++ b/src/ErrorHandler/Plugin/Stats.php @@ -36,7 +36,7 @@ public function __construct($cfg = array()) 'dataStoreFactory' => function () { $cfgDataStore = \array_diff_key($this->cfg, array('dataStoreFactory' => null)); return new StatsStoreFile($cfgDataStore); - } + }, ); $this->setCfg(\array_merge($this->cfg, $cfg)); } @@ -100,9 +100,9 @@ public function getSummaryErrors() public function onErrorHighPri(Error $error) { $error['stats'] = array( + 'count' => 1, 'tsAdded' => \time(), 'tsLastOccur' => null, - 'count' => 1, ); $errorStats = $this->dataStore->findByError($error); if ($errorStats) { diff --git a/src/ErrorHandler/Plugin/StatsStoreFile.php b/src/ErrorHandler/Plugin/StatsStoreFile.php index e20ab065..31117b24 100644 --- a/src/ErrorHandler/Plugin/StatsStoreFile.php +++ b/src/ErrorHandler/Plugin/StatsStoreFile.php @@ -29,8 +29,8 @@ class StatsStoreFile extends AbstractComponent implements StatsStoreInterface public function __construct($cfg = array()) { $this->cfg = array( - 'ttl' => 3600, // any errors that haven't occurred in this timespan are subject to garbage collection 'errorStatsFile' => __DIR__ . '/error_stats.json', + 'ttl' => 3600, // any errors that haven't occurred in this timespan are subject to garbage collection ); $this->setCfg($cfg); $this->dataRead(); @@ -45,15 +45,15 @@ public function errorUpsert(Error $error) $tsNow = \time(); if (isset($this->data['errors'][$hash]) === false) { $this->data['errors'][$hash] = array( + 'count' => 1, 'info' => array( - 'type' => $error['type'], - 'message' => $error['message'], 'file' => $error['file'], 'line' => $error['line'], + 'message' => $error['message'], + 'type' => $error['type'], ), 'tsAdded' => $tsNow, 'tsLastOccur' => $tsNow, - 'count' => 1, ); } $this->data['errors'][$hash] = \array_merge( @@ -90,8 +90,8 @@ public function findByHash($hash) public function flush() { $this->data = array( - 'tsGarbageCollection' => \time(), 'errors' => array(), + 'tsGarbageCollection' => \time(), ); $this->dataWrite(); } @@ -120,8 +120,8 @@ protected function dataRead() $data = \json_decode($data, true); } $this->data = \array_merge(array( - 'tsGarbageCollection' => \time(), 'errors' => array(), + 'tsGarbageCollection' => \time(), ), $data ?: array()); } diff --git a/src/HttpMessage/AbstractServerRequest.php b/src/HttpMessage/AbstractServerRequest.php index 3fc3fa06..717ad119 100644 --- a/src/HttpMessage/AbstractServerRequest.php +++ b/src/HttpMessage/AbstractServerRequest.php @@ -116,9 +116,9 @@ protected function getHeadersViaServer($serverParams) { $headers = array(); $keysSansHttp = array( - 'CONTENT_TYPE' => 'Content-Type', 'CONTENT_LENGTH' => 'Content-Length', 'CONTENT_MD5' => 'Content-Md5', + 'CONTENT_TYPE' => 'Content-Type', ); $auth = $this->getAuthorizationHeader($serverParams); if ($auth) { @@ -189,11 +189,11 @@ protected static function uriFromGlobals() self::uriPathQueryFromGlobals() ); $methods = array( - 'scheme' => 'withScheme', 'host' => 'withHost', - 'port' => 'withPort', 'path' => 'withPath', + 'port' => 'withPort', 'query' => 'withQuery', + 'scheme' => 'withScheme', ); foreach ($parts as $name => $value) { if ($value) { @@ -233,14 +233,14 @@ private static function createUploadedFileArray($fileInfo) // don't use array_map... callback does not have access to self::createUploadedFile foreach ($keys as $key) { $files[$key] = self::createUploadedFile([ - 'tmp_name' => $fileInfo['tmp_name'][$key], - 'size' => $fileInfo['size'][$key], 'error' => $fileInfo['error'][$key], - 'name' => $fileInfo['name'][$key], - 'type' => $fileInfo['type'][$key], 'full_path' => isset($fileInfo['full_path'][$key]) ? $fileInfo['full_path'][$key] : null, + 'name' => $fileInfo['name'][$key], + 'size' => $fileInfo['size'][$key], + 'tmp_name' => $fileInfo['tmp_name'][$key], + 'type' => $fileInfo['type'][$key], ]); } return $files; diff --git a/src/HttpMessage/AssertionTrait.php b/src/HttpMessage/AssertionTrait.php index 4e22cbbb..e2ccc4ee 100644 --- a/src/HttpMessage/AssertionTrait.php +++ b/src/HttpMessage/AssertionTrait.php @@ -389,7 +389,7 @@ protected function assertStatusCode($code) protected function assertHost($host) { $this->assertString($host, 'host'); - if (\in_array($host, array('','localhost'), true)) { + if (\in_array($host, array('', 'localhost'), true)) { // An empty host value is equivalent to removing the host. // No validation required return; diff --git a/src/HttpMessage/UploadedFile.php b/src/HttpMessage/UploadedFile.php index 625c71d8..6e1a8e81 100644 --- a/src/HttpMessage/UploadedFile.php +++ b/src/HttpMessage/UploadedFile.php @@ -86,6 +86,7 @@ class UploadedFile implements UploadedFileInterface */ public function __construct($values = array()) { + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $defaultValues = array( 'tmp_name' => null, 'size' => null, diff --git a/src/HttpMessage/UriUtils.php b/src/HttpMessage/UriUtils.php index 9f1bec88..a2789a34 100644 --- a/src/HttpMessage/UriUtils.php +++ b/src/HttpMessage/UriUtils.php @@ -72,7 +72,6 @@ public static function resolve(UriInterface $base, UriInterface $rel) ? $relPath : \substr($base->getPath(), 0, $lastSlashPos + 1) . $relPath; if ($relPath[0] === '/') { - // \bdk\Test\Debug\Helper::stderr('rel path slash'); $targetPath = $relPath; } elseif ($base->getAuthority() !== '' && $base->getPath() === '') { $targetPath = '/' . $relPath; @@ -158,6 +157,7 @@ private static function parseUrlPatched($url) */ private static function parseUrlAddEmpty($parts, $url) { + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder $default = array( 'scheme' => null, 'host' => null, @@ -203,7 +203,7 @@ private static function pathRemoveDots($path) if ($path[0] === '/' && (!isset($pathNew[0]) || $pathNew[0] !== '/')) { // Re-add the leading slash if necessary for cases like "/.." $pathNew = '/' . $pathNew; - } elseif ($pathNew !== '' && \in_array($segment, array('.','..'), true)) { + } elseif ($pathNew !== '' && \in_array($segment, array('.', '..'), true)) { // Add the trailing slash if necessary // If pathNew is not empty, then $segment must be set and is the last segment from the foreach $pathNew .= '/'; diff --git a/tests/Debug/Abstraction/AbstractionTest.php b/tests/Debug/Abstraction/AbstractionTest.php index ce698c14..42803c04 100644 --- a/tests/Debug/Abstraction/AbstractionTest.php +++ b/tests/Debug/Abstraction/AbstractionTest.php @@ -14,11 +14,13 @@ class AbstractionTest extends TestCase public function testConstruct() { $abs = new Abstraction('myType'); - $this->assertInstanceOf('\bdk\PubSub\Event', $abs); + $this->assertInstanceOf('bdk\PubSub\Event', $abs); $this->assertSame('myType', $abs['type']); $abs = new Abstraction('myType', array('foo' => 'bar')); $this->assertSame('myType', $abs->getValue('type')); $this->assertSame('bar', $abs->getValue('foo')); + $abs = new Abstraction(Abstracter::TYPE_ARRAY); + $this->assertSame(array(), $abs->getValue('value')); } public function testToString() @@ -68,7 +70,7 @@ public function testJsonSerialize() { $abs = new Abstraction('myType', array('foo' => 'bar')); $json = \json_encode($abs); - $this->assertSame('{"foo":"bar","type":"myType","debug":"\u0000debug\u0000"}', $json); + $this->assertSame('{"foo":"bar","type":"myType","value":null,"debug":"\u0000debug\u0000"}', $json); } public function testSerialize() @@ -76,8 +78,8 @@ public function testSerialize() $abs = new Abstraction('myType', array('foo' => 'bar')); $serialized = \serialize($abs); $expect = PHP_VERSION_ID >= 70400 - ? 'O:33:"bdk\Debug\Abstraction\Abstraction":2:{s:3:"foo";s:3:"bar";s:4:"type";s:6:"myType";}' - : 'C:33:"bdk\Debug\Abstraction\Abstraction":50:{a:2:{s:3:"foo";s:3:"bar";s:4:"type";s:6:"myType";}}'; + ? 'O:33:"bdk\Debug\Abstraction\Abstraction":3:{s:3:"foo";s:3:"bar";s:4:"type";s:6:"myType";s:5:"value";N;}' + : 'C:33:"bdk\Debug\Abstraction\Abstraction":64:{a:3:{s:3:"foo";s:3:"bar";s:4:"type";s:6:"myType";s:5:"value";N;}}'; $this->assertSame($expect, $serialized); } diff --git a/tests/Debug/ChannelTest.php b/tests/Debug/ChannelTest.php index b0bebfe1..c6506e82 100644 --- a/tests/Debug/ChannelTest.php +++ b/tests/Debug/ChannelTest.php @@ -122,9 +122,9 @@ public function testData() 'alerts' => true, 'log' => true, 'logErrors' => true, + 'silent' => false, 'summary' => true, 'summaryErrors' => true, - 'silent' => false, ), 'line' => $info['lines'][2], ), @@ -162,7 +162,7 @@ public function testOutput() { $this->genLog(); $htmlFoo = << +
PHPDebugConsole
@@ -198,7 +198,7 @@ public function testOutput()
EOD; $html = << +
PHPDebugConsole
%A
diff --git a/tests/Debug/Collector/SimpleCacheTest.php b/tests/Debug/Collector/SimpleCacheTest.php index b602551a..9d8cacc8 100644 --- a/tests/Debug/Collector/SimpleCacheTest.php +++ b/tests/Debug/Collector/SimpleCacheTest.php @@ -208,9 +208,9 @@ public function testGetLoggedActions() $this->assertSame(array( 'duration', 'exception', + 'keyOrKeys', 'memoryUsage', 'method', - 'keyOrKeys', ), \array_keys(\reset($loggedActions)->__debugInfo())); } diff --git a/tests/Debug/DebugTest.php b/tests/Debug/DebugTest.php index ec0c778b..0d778e1d 100644 --- a/tests/Debug/DebugTest.php +++ b/tests/Debug/DebugTest.php @@ -115,6 +115,7 @@ public function testPublishBubbleEvent()
    \t
  • foo=><b>bar&baz</b>
  • \t
  • type=>someCustomValueType
  • +\t
  • value=>null
)'; $expect = \str_replace('\\t', "\t", $expect); $dumped = $this->debug->getDump('html')->valDumper->dump($val); diff --git a/tests/Debug/DebugTestFramework.php b/tests/Debug/DebugTestFramework.php index e32a1064..f7314298 100644 --- a/tests/Debug/DebugTestFramework.php +++ b/tests/Debug/DebugTestFramework.php @@ -674,7 +674,7 @@ private function tstMethodTest($test, LogEntry $logEntry, $outputExpect, $output if (isset($outputExpect['contains'])) { $message = "\e[1m" . $test . " doesn't contain\e[0m"; if ($test === 'streamAnsi') { - $message .= "\nactual: " . \str_replace(array("\e","\n"), array('\e','\n'), $output); + $message .= "\nactual: " . \str_replace("\e", '\e', $output); } if (\is_string($output)) { $this->assertStringContainsString($outputExpect['contains'], $output, $message); @@ -701,10 +701,16 @@ private function tstMethodTest($test, LogEntry $logEntry, $outputExpect, $output $output = \str_replace("\r", '[\\r]', $output); $outputExpect = \str_replace("\r", '[\\r]', $outputExpect); $message = "\e[1m" . $test . " not same\e[0m"; - if ($test === 'streamAnsi') { - $message .= "\nexpect: " . \str_replace(array("\e", "\n"), array('\e', '\n'), $outputExpect) . "\n"; - $message .= "\nactual: " . \str_replace(array("\e", "\n"), array('\e', '\n'), $output); + try { + $this->assertStringMatchesFormat(\trim($outputExpect), \trim($output), $message); + } catch (\Exception $e) { + echo $test . ':' . "\n"; + echo $test === 'textAnsi' + ? 'expect: ' . \str_replace("\e", '\e', $outputExpect) . "\n" + . 'actual: ' . \str_replace("\e", '\e', $output) . "\n" + : 'expect: ' . $outputExpect . "\n" + . 'actual: ' . $output . "\n"; + throw new \PHPUnit\Framework\AssertionFailedError($test . ' has failed'); } - $this->assertStringMatchesFormat(\trim($outputExpect), \trim($output), $message); } } diff --git a/tests/Debug/Fixture/TestBase.php b/tests/Debug/Fixture/TestBase.php index 19effd83..07afb656 100644 --- a/tests/Debug/Fixture/TestBase.php +++ b/tests/Debug/Fixture/TestBase.php @@ -38,6 +38,19 @@ public function __get($key) { } + /** + * set magic method + * + * @param string $key what we're setting + * @param mixed $val value + * + * @return void + */ + public function __set($key, $val) + { + $this->{$key} = $val; + } + /** * call magic method * diff --git a/tests/Debug/Helper.php b/tests/Debug/Helper.php index 18ba40e7..89706eca 100644 --- a/tests/Debug/Helper.php +++ b/tests/Debug/Helper.php @@ -58,15 +58,16 @@ public static function crate($val) /** * Convert data log log entries into simple arrays * - * @param array $data log data - * @param bool $withKeys whether log entries should be returned with keys or as a list + * @param array $data log data + * @param bool $withKeys whether log entries should be returned with keys or as a list + * @param bool $dropEmptyMeta whether to omit meta if empty * * @return array */ - public static function deObjectifyData($data, $withKeys = true) + public static function deObjectifyData($data, $withKeys = true, $dropEmptyMeta = false) { if ($data instanceof LogEntry) { - return self::logEntryToArray($data, $withKeys); + return self::logEntryToArray($data, $withKeys, $dropEmptyMeta); } if ($data instanceof Abstraction) { return self::crate($data); @@ -75,7 +76,7 @@ public static function deObjectifyData($data, $withKeys = true) return $data; } foreach ($data as $i => $v) { - $data[$i] = self::deObjectifyData($v, $withKeys); + $data[$i] = self::deObjectifyData($v, $withKeys, $dropEmptyMeta); } return $data; } @@ -153,7 +154,7 @@ public static function setProp($obj, $prop, $val) * * @return array|null */ - public static function logEntryToArray($logEntry, $withKeys = true) + public static function logEntryToArray($logEntry, $withKeys = true, $dropEmptyMeta = false) { if (\is_array($logEntry) && \array_keys($logEntry) === array('method','args','meta')) { return $logEntry; @@ -164,6 +165,9 @@ public static function logEntryToArray($logEntry, $withKeys = true) $return = $logEntry->export(); $return['args'] = self::crate($return['args']); \ksort($return['meta']); + if ($dropEmptyMeta && empty($return['meta'])) { + unset($return['meta']); + } if (!$withKeys) { return \array_values($return); } @@ -214,16 +218,17 @@ public static function stderr() { $isCli = self::isCli(); $dumper = Debug::getInstance()->getDump($isCli ? 'textAnsi' : 'text'); - $args = \array_map(function ($val) use ($dumper) { - $new = 'null'; - if ($val !== null) { - $new = $dumper->valDumper->dump($val); + $args = \array_map(static function ($val) use ($dumper, $isCli) { + $new = $dumper->valDumper->dump($val); + if ($isCli) { $dumper->valDumper->escapeReset = "\e[0m"; - $dumper->valDumper->setValDepth(0); } + $dumper->valDumper->setValDepth(0); + /* if (\json_last_error() !== JSON_ERROR_NONE) { $new = \var_export($val, true); } + */ return $new; }, \func_get_args()); $glue = \func_num_args() > 2 @@ -234,6 +239,19 @@ public static function stderr() \fwrite(STDERR, $outStr . "\n"); return; } - echo '
' . \htmlspecialchars($outStr) . '
' . "\n"; + echo '
' . \htmlspecialchars($outStr) . '
' . "\n"; + } + + private function varDump($val) + { + \ini_set('xdebug.var_display_max_depth', 8); + \ob_start(); + \var_dump($val); + $new = \ob_get_clean(); + $new = \preg_replace('/^\S+:\d+[\r\n]/', '', $new); + $new = \preg_replace('/=>\n\s+/', '=> ', $new); + $new = \preg_replace('/string\(\d+\) /', '', $new); + $new = \preg_replace('/array\(0\) \{\n\s*\}/', 'array()', $new); + return \trim($new); } } diff --git a/tests/Debug/InternalEventsTest.php b/tests/Debug/InternalEventsTest.php index 74f9eb22..2ff93989 100644 --- a/tests/Debug/InternalEventsTest.php +++ b/tests/Debug/InternalEventsTest.php @@ -28,6 +28,7 @@ public function testDumpCustom()
    \t
  • foo=><b>bar&baz</b>
  • \t
  • type=>someCustomValueType
  • +\t
  • value=>null
)'; $expect = \str_replace('\\t', "\t", $expect); $dumped = $this->debug->getDump('html')->valDumper->dump($val); diff --git a/tests/Debug/Method/ClearTest.php b/tests/Debug/Method/ClearTest.php index b6603aee..b93cc1da 100644 --- a/tests/Debug/Method/ClearTest.php +++ b/tests/Debug/Method/ClearTest.php @@ -31,9 +31,9 @@ public function testClearDefault() 'alerts' => false, 'log' => true, 'logErrors' => false, + 'silent' => false, 'summary' => false, 'summaryErrors' => false, - 'silent' => false, ), 'line' => $this->line, ), @@ -105,9 +105,9 @@ public function testClearAlerts() 'alerts' => true, 'log' => false, 'logErrors' => false, + 'silent' => false, 'summary' => false, 'summaryErrors' => false, - 'silent' => false, ), 'line' => $this->line, ), @@ -155,9 +155,9 @@ public function testClearSummary() 'alerts' => false, 'log' => false, 'logErrors' => false, + 'silent' => false, 'summary' => true, 'summaryErrors' => false, - 'silent' => false, ), 'line' => $this->line, ), @@ -215,9 +215,9 @@ public function testClearErrors() 'alerts' => false, 'log' => false, 'logErrors' => true, + 'silent' => false, 'summary' => false, 'summaryErrors' => false, - 'silent' => false, ), 'line' => $this->line, ), @@ -275,9 +275,9 @@ public function testClearAll() 'alerts' => true, 'log' => true, 'logErrors' => true, + 'silent' => false, 'summary' => true, 'summaryErrors' => true, - 'silent' => false, ), 'line' => $this->line, ), @@ -334,9 +334,9 @@ public function testClearSummaryInclErrors() 'alerts' => false, 'log' => false, 'logErrors' => false, + 'silent' => false, 'summary' => true, 'summaryErrors' => true, - 'silent' => false, ), 'line' => $this->line, ), @@ -393,9 +393,9 @@ public function testClearSummaryErrors() 'alerts' => false, 'log' => false, 'logErrors' => false, + 'silent' => false, 'summary' => false, 'summaryErrors' => true, - 'silent' => false, ), 'line' => $this->line, ), @@ -468,9 +468,9 @@ public function testClearCollectFalse() 'alerts' => false, 'log' => true, 'logErrors' => false, + 'silent' => false, 'summary' => false, 'summaryErrors' => false, - 'silent' => false, ), 'line' => $this->line, ), diff --git a/tests/Debug/Method/GroupTest.php b/tests/Debug/Method/GroupTest.php index 22415f61..98899535 100644 --- a/tests/Debug/Method/GroupTest.php +++ b/tests/Debug/Method/GroupTest.php @@ -23,6 +23,7 @@ function myFunctionThatCallsGroup() * PHPUnit tests for Debug Group Methods * * @covers \bdk\Debug + * @covers \bdk\Debug\Abstraction\Abstracter * @covers \bdk\Debug\Dump\Base * @covers \bdk\Debug\Dump\Html * @covers \bdk\Debug\Dump\Text @@ -106,7 +107,7 @@ public function testGroupArgs() $dateTime ); $logEntry = $this->debug->data->get('log/0'); - $logEntry = $this->helper->logEntryToArray($logEntry); + $logEntryArray = $this->helper->logEntryToArray($logEntry); $cfgAbsBak = $this->debug->abstracter->setCfg(array( 'brief' => true, 'caseCollect' => false, @@ -133,17 +134,17 @@ public function testGroupArgs() 'meta' => array(), ), $logEntry); */ - $this->assertSame('string', $logEntry['args'][0]); - $this->assertSame(42, $logEntry['args'][1]); - $this->assertSame(null, $logEntry['args'][2]); - $this->assertSame(false, $logEntry['args'][3]); - $this->assertSame($objExpect, $logEntry['args'][4]); - $this->assertTrue(($logEntry['args'][5]['cfgFlags'] & AbstractObject::BRIEF) === AbstractObject::BRIEF); + $this->assertSame('string', $logEntryArray['args'][0]); + $this->assertSame(42, $logEntryArray['args'][1]); + $this->assertSame(null, $logEntryArray['args'][2]); + $this->assertSame(false, $logEntryArray['args'][3]); + $this->assertSame($objExpect, $logEntryArray['args'][4]); + $this->assertTrue(($logEntryArray['args'][5]['cfgFlags'] & AbstractObject::BRIEF) === AbstractObject::BRIEF); $this->assertSame(array( 'returnValue' => 'toStringVal', 'visibility' => 'public', ), $logEntry['args'][5]['methods']['__toString']); - $this->assertTrue(($logEntry['args'][6]['cfgFlags'] & AbstractObject::BRIEF) === AbstractObject::BRIEF); + $this->assertTrue(($logEntryArray['args'][6]['cfgFlags'] & AbstractObject::BRIEF) === AbstractObject::BRIEF); } public function testGroupHideIfEmpty() @@ -816,6 +817,7 @@ public function testGroupsLeftOpen() This also tests that the values returned by getData have been dereferenced */ + $groupStack = $this->getSharedVar('reflectionProperties')['groupStack']; $this->debug->groupSummary(1); $this->debug->log('in summary'); @@ -826,7 +828,6 @@ public function testGroupsLeftOpen() collect some info before outputing confirm nothing has been closed yet */ - $groupStack = $this->getSharedVar('reflectionProperties')['groupStack']; $onOutputVals['groupPriorityStackA'] = $this->getSharedVar('reflectionProperties')['groupPriorityStack']->getValue($groupStack); $onOutputVals['groupStacksA'] = \array_map(function ($stack) { return \count($stack); diff --git a/tests/Debug/Method/MethodTest.php b/tests/Debug/Method/MethodTest.php index ce79f58c..5080bc76 100644 --- a/tests/Debug/Method/MethodTest.php +++ b/tests/Debug/Method/MethodTest.php @@ -223,7 +223,7 @@ public function testMethodSetsCfg() $this->debug->log(new \bdk\Test\Debug\Fixture\TestObj(), $this->debug->meta('cfg', 'methodCollect', false)); $methodCollect = $this->debug->data->get('log/__end__/args/0/cfgFlags') & \bdk\Debug\Abstraction\AbstractObject::METHOD_COLLECT; $this->assertSame(0, $methodCollect); - $this->assertCount(2, $this->debug->data->get('log/__end__/args/0/methods')); + $this->assertCount(3, $this->debug->data->get('log/__end__/args/0/methods')); $this->assertTrue($this->debug->getCfg('methodCollect')); } diff --git a/tests/Debug/Method/PluginMethodGeneralTest.php b/tests/Debug/Method/PluginMethodGeneralTest.php index 42ded69b..4845fce7 100644 --- a/tests/Debug/Method/PluginMethodGeneralTest.php +++ b/tests/Debug/Method/PluginMethodGeneralTest.php @@ -52,19 +52,19 @@ public function testErrorStats() $this->debug->errorHandler->handleError(E_NOTICE, 'we tried to warn you', __FILE__, __LINE__); $this->assertSame(array( - 'inConsole' => 1, - 'inConsoleCategories' => array( - 'warning', - ), - 'notInConsole' => 1, 'counts' => array( - 'fatal' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), - 'error' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), - 'warning' => array('inConsole' => 1, 'notInConsole' => 0, 'suppressed' => 0, ), 'deprecated' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), + 'error' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), + 'fatal' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), 'notice' => array('inConsole' => 0, 'notInConsole' => 1, 'suppressed' => 0, ), 'strict' => array('inConsole' => 0, 'notInConsole' => 0, 'suppressed' => 0, ), + 'warning' => array('inConsole' => 1, 'notInConsole' => 0, 'suppressed' => 0, ), + ), + 'inConsole' => 1, + 'inConsoleCategories' => array( + 'warning', ), + 'notInConsole' => 1, ), $this->debug->errorStats()); } diff --git a/tests/Debug/Plugin/LogFilesTest.php b/tests/Debug/Plugin/LogFilesTest.php index 7f8a2d2d..8ed70873 100644 --- a/tests/Debug/Plugin/LogFilesTest.php +++ b/tests/Debug/Plugin/LogFilesTest.php @@ -119,8 +119,8 @@ public function testOnOutput() ), array( 'attribs' => array( - 'data-file' => '/var/www/bootstrap.php', 'class' => array(), + 'data-file' => '/var/www/bootstrap.php', ), 'debug' => Abstracter::ABSTRACTION, 'type' => 'string', @@ -128,8 +128,8 @@ public function testOnOutput() ), array( 'attribs' => array( - 'data-file' => '/var/www/index.php', 'class' => array(), + 'data-file' => '/var/www/index.php', ), 'debug' => Abstracter::ABSTRACTION, 'type' => 'string', diff --git a/tests/Debug/Plugin/RedactionTest.php b/tests/Debug/Plugin/RedactionTest.php index 8453114c..dca108d5 100644 --- a/tests/Debug/Plugin/RedactionTest.php +++ b/tests/Debug/Plugin/RedactionTest.php @@ -64,7 +64,7 @@ public static function providerTestMethod() ), array( 'entry' => static function (LogEntry $logEntry) use ($base64snip) { - $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"typeMore":"base64","value":"' . $base64snip . '","valueDecoded":{"brief":false,"strlen":null,"typeMore":"json","value":"{\n \"poop\": \"\\\\ud83d\\\\udca9\",\n \"int\": 42,\n \"password\": \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\"\n}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"type":"string","attribs":{"class":["highlight","language-json"]},"addQuotes":false,"contentType":"application\/json","prettified":true,"prettifiedTag":true,"visualWhiteSpace":false,"debug":"\u0000debug\u0000"},"type":"string","debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; + $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"type":"string","typeMore":"base64","value":"' . $base64snip . '","valueDecoded":{"addQuotes":false,"attribs":{"class":["highlight","language-json"]},"brief":false,"contentType":"application\/json","prettified":true,"prettifiedTag":true,"strlen":null,"type":"string","typeMore":"json","value":"{\n \"poop\": \"\\\\ud83d\\\\udca9\",\n \"int\": 42,\n \"password\": \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\"\n}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"visualWhiteSpace":false,"debug":"\u0000debug\u0000"},"debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; $jsonified = \json_encode($logEntry); self::assertSame($jsonExpect, $jsonified); }, @@ -87,10 +87,6 @@ public static function providerTestMethod() $obj = $logEntry['args'][0]; self::assertSame(null, $obj['stringified']); self::assertSame('foo=bar&password=█████████&ding=dong', $obj['methods']['__toString']['returnValue']); - // $this->helper->stderr($logEntry); - // $jsonExpect = '{"method":"log","args":[{"strlen":null,"typeMore":"base64","value":"' . $base64snip . '","valueDecoded":{"strlen":null,"typeMore":"json","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"value":"{\n \"poop\": \"\\\\ud83d\\\\udca9\",\n \"int\": 42,\n \"password\": \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\"\n}","type":"string","attribs":{"class":["highlight","language-json"]},"addQuotes":false,"contentType":"application\/json","prettified":true,"prettifiedTag":true,"visualWhiteSpace":false,"debug":"\u0000debug\u0000"},"type":"string","debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; - // $jsonified = \json_encode($logEntry); - // $this->assertSame($jsonExpect, $jsonified); }, ), ), diff --git a/tests/Debug/Route/EmailTest.php b/tests/Debug/Route/EmailTest.php index f8107732..d0e6660d 100644 --- a/tests/Debug/Route/EmailTest.php +++ b/tests/Debug/Route/EmailTest.php @@ -30,8 +30,8 @@ public function testEmail() $this->assertStringContainsString($stringExpect, $this->emailInfo['body']); $data = \bdk\Debug\Utility\SerializeLog::unserialize($this->emailInfo['body']); $this->assertSame(array( - 'version', 'config', + 'version', 'alerts', 'log', 'logSummary', diff --git a/tests/Debug/SubstitutionTest.php b/tests/Debug/SubstitutionTest.php index 3826ed1f..9c9fc309 100644 --- a/tests/Debug/SubstitutionTest.php +++ b/tests/Debug/SubstitutionTest.php @@ -294,7 +294,7 @@ public function testMarkupSanitizeFirstFalse() '', 'sub bold', 'extra', - $this->debug->meta('sanitizeFirst', false) + $this->debug->meta('sanitizeFirst', false), ); $this->doTestSubstitution( @@ -377,13 +377,13 @@ public function doTestSubstitution($method, $args, $tests) $test[0] = \array_map(function ($val) { return $this->debug->getDump('base')->valDumper->dump($val); }, $test[0]); - $test[1] = \in_array($method, array('error','warn')) + $test[1] = \in_array($method, array('error','warn'), true) ? $this->file . ': ' . $this->line : null; - $test[2] = \in_array($method, array('alert','log')) + $test[2] = \in_array($method, array('alert','log'), true) ? '' : $method; - } elseif ($name === 'entry') { + } elseif ($name === 'entry' && \is_array($test)) { $test['method'] = $method; if ($method === 'alert') { $test['meta']['dismissible'] = false; @@ -477,9 +477,9 @@ public function doTestSubstitution($method, $args, $tests) $prefixes = array( 'alert' => '', 'assert' => '≠ ', - 'log' => '', 'error' => 'âĻģ ', 'info' => 'ℹ ', + 'log' => '', 'warn' => '⚠ ', ); $test = $prefixes[$method] . $test; @@ -500,11 +500,6 @@ public function doTestSubstitution($method, $args, $tests) } $tests[$name] = $test; } - /* - if ($method === 'alert') { - echo 'chromeLogger alert test ' . \print_r($tests['chromeLogger'], true) . "\n\n"; - } - */ $this->testMethod($method, $args, $tests); if ($method === 'assert') { \array_shift($args); diff --git a/tests/Debug/Type/ArrayTest.php b/tests/Debug/Type/ArrayTest.php index 4622df42..306a8b44 100644 --- a/tests/Debug/Type/ArrayTest.php +++ b/tests/Debug/Type/ArrayTest.php @@ -12,6 +12,7 @@ * @covers \bdk\Debug\Dump\BaseValue * @covers \bdk\Debug\Dump\Text * @covers \bdk\Debug\Dump\Html + * @covers \bdk\Debug\Dump\Html\Value * @covers \bdk\Debug\Dump\TextAnsiValue * @covers \bdk\Debug\Dump\TextValue * @covers \bdk\Debug\Abstraction\Abstracter diff --git a/tests/Debug/Type/BasicTest.php b/tests/Debug/Type/BasicTest.php index 1e0ca2c7..38adb350 100644 --- a/tests/Debug/Type/BasicTest.php +++ b/tests/Debug/Type/BasicTest.php @@ -141,9 +141,9 @@ static function ($foo, $bar) { self::assertSame('Closure', $values['className']); $line = __LINE__ - 10; self::assertSame(array( + 'extensionName' => false, 'fileName' => __FILE__, 'startLine' => $line, - 'extensionName' => false, ), $values['definition']); \array_walk($values['properties'], static function ($propInfo, $propName) use ($line) { // echo \json_encode($propInfo, JSON_PRETTY_PRINT); diff --git a/tests/Debug/Type/EnumTest.php b/tests/Debug/Type/EnumTest.php index 38439bd9..7305d54f 100644 --- a/tests/Debug/Type/EnumTest.php +++ b/tests/Debug/Type/EnumTest.php @@ -12,6 +12,7 @@ * * @covers \bdk\Debug\Abstraction\AbstractObject * @covers \bdk\Debug\Abstraction\AbstractObjectConstants + * @covers \bdk\Debug\Abstraction\AbstractObjectMethodParams * @covers \bdk\Debug\Dump\Html\HtmlObject * @covers \bdk\Debug\Dump\Html\ObjectConstants */ @@ -26,7 +27,7 @@ public static function providerTestMethod() ); } - // $regexTrim = '#^\s+#m'; + // @phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return array( 'basic' => array( 'log', @@ -139,7 +140,7 @@ public static function providerTestMethod() }, 'html' => '%a
public REGULAR_CONSTANT = test
properties
%a', - ) + ), ), 'backed' => array( diff --git a/tests/Debug/Type/ObjectTest.php b/tests/Debug/Type/ObjectTest.php index 3cfd6a56..14327bfe 100644 --- a/tests/Debug/Type/ObjectTest.php +++ b/tests/Debug/Type/ObjectTest.php @@ -78,7 +78,7 @@ public static function providerTestMethod() (✨ magic excluded) magicProp (debug) debugValue = "This property is debug only" Methods: - public: 8 + public: 9 protected: 1 private: 1 magic: 2 @@ -99,8 +99,8 @@ public static function providerTestMethod() \e[38;5;245m)\e[0m \e[38;5;250m(protected ✨ magic-read)\e[0m \e[38;5;83mmagicReadProp\e[0m \e[38;5;130m=\e[0m \e[38;5;250m"\e[0mnot null\e[38;5;250m"\e[0m \e[38;5;250m(protected)\e[0m \e[38;5;83mpropProtected\e[0m \e[38;5;130m=\e[0m \e[38;5;250m"\e[0mdefined only in TestBase (protected)\e[38;5;250m"\e[0m - \e[38;5;250m(private)\e[0m \e[38;5;83mdebug\e[0m \e[38;5;130m=\e[0m \e[38;5;9mNOT INSPECTED\e[0m - \e[38;5;250m(private)\e[0m \e[38;5;83minstance\e[0m \e[38;5;130m=\e[0m \e[38;5;9m*RECURSION*\e[0m + \e[38;5;250m(private)\e[0m \e[38;5;83mdebug\e[0m \e[38;5;130m=\e[0m \e[38;5;250mbdk\\e[0m\e[1mDebug\e[22m \e[38;5;9mNOT INSPECTED\e[0m + \e[38;5;250m(private)\e[0m \e[38;5;83minstance\e[0m \e[38;5;130m=\e[0m \e[38;5;250mbdk\Test\Debug\Fixture\\e[0m\e[1mTestObj\e[22m \e[38;5;196m*RECURSION*\e[0m \e[38;5;250m(private excluded)\e[0m \e[38;5;83mpropNoDebug\e[0m \e[38;5;250m(private)\e[0m \e[38;5;83mpropPrivate\e[0m \e[38;5;130m=\e[0m \e[38;5;250m"\e[0mredefined in Test (private) (alternate value via __debugInfo)\e[38;5;250m"\e[0m \e[38;5;250m(🔒 private)\e[0m \e[38;5;83mtestBasePrivate\e[0m \e[38;5;130m=\e[0m \e[38;5;250m"\e[0mdefined in TestBase (private)\e[38;5;250m"\e[0m @@ -109,7 +109,7 @@ public static function providerTestMethod() \e[38;5;250m(✨ magic excluded)\e[0m \e[38;5;83mmagicProp\e[0m \e[38;5;250m(debug)\e[0m \e[38;5;83mdebugValue\e[0m \e[38;5;130m=\e[0m \e[38;5;250m"\e[0mThis property is debug only\e[38;5;250m"\e[0m \e[4mMethods:\e[24m - public\e[38;5;245m:\e[0m \e[96m8\e[0m + public\e[38;5;245m:\e[0m \e[96m9\e[0m protected\e[38;5;245m:\e[0m \e[96m1\e[0m private\e[38;5;245m:\e[0m \e[96m1\e[0m magic\e[38;5;245m:\e[0m \e[96m2\e[0m @@ -203,7 +203,7 @@ public static function providerTestMethod() // properties $expect = \implode("\n", array( '
properties (via __debugInfo)
', - '
This object has a __get method
', + '
This object has __get and __set methods
', '
public propPublic = redefined in Test (public)
', '
public static propStatic = I\'m Static
', '
public someArray = array(', @@ -227,7 +227,7 @@ public static function providerTestMethod() '
private toStrThrow = 0
', '
magic bool magicProp
', '
debug debugValue = This property is debug only
', - '
methods
' + '
methods
', )); if (PHP_VERSION_ID >= 80100) { $expect = \str_replace('\'', ''', $expect); @@ -246,6 +246,7 @@ public static function providerTestMethod() '
public __call(string $name, array $args): mixed
', '
public __debugInfo(): array
', '
public __get(string $key): mixed
', + '
public __set(string $key, mixed $val): void
', '
public __toString(): string
', 'abracadabra
', '
final public methodPublic(bdk\Test\Debug\Fixture\SomeClass This is the song that never ends. Yes, it goes on and on my friend. Some people started singing it… (119 more bytes)', $str); - } + }, ), ), // 2 @@ -367,10 +368,10 @@ public static function providerTestMethod() foreach ($objAbs['constants'] as $const) { self::assertNull($const['desc']); } - foreach ($objAbs['properties'] as $name => $prop) { + foreach ($objAbs['properties'] as $prop) { self::assertNull($prop['desc']); } - foreach ($objAbs['methods'] as $name => $method) { + foreach ($objAbs['methods'] as $method) { self::assertSame( array('desc' => null, 'summary' => null), \array_intersect_key($method['phpDoc'], \array_flip(array('desc','summary'))) @@ -404,7 +405,7 @@ public static function providerTestMethod() 'value: "defined in TestBase"', )); self::assertEmpty($matches, 'Html should not contain phpDoc summary & descriptions'); - } + }, ), ), 'methodCollectFalse' => array( @@ -435,7 +436,7 @@ public static function providerTestMethod() 'text' => static function ($str) { $containsMethods = \preg_match('/methods/i', $str) === 1; self::assertFalse($containsMethods, 'Output should not contain methods'); - } + }, ), ), // 3 @@ -544,6 +545,7 @@ public static function providerTestMethod() '__call', '__debugInfo', '__get', + '__set', '__toString', 'methodPrivate', 'methodProtected', @@ -665,13 +667,13 @@ public function testAbstraction() ); self::assertArraySubset( array( - 'isPromoted' => false, - 'visibility' => 'protected', - 'value' => 'defined only in TestBase (protected)', 'inheritedFrom' => 'bdk\Test\Debug\Fixture\TestBase', - 'overrides' => null, + 'isPromoted' => false, 'originallyDeclared' => 'bdk\Test\Debug\Fixture\TestBase', + 'overrides' => null, + 'value' => 'defined only in TestBase (protected)', 'valueFrom' => 'value', + 'visibility' => 'protected', ), $abs['properties']['propProtected'] ); @@ -1208,9 +1210,8 @@ public function testRecursiveObjectProp1() $select = '.m_log > .t_object > .object-inner > .property - > .t_array .array-inner > li' - // > .t_array - . '> .t_recursion'; + > .t_array .array-inner > li + > .t_recursion'; self::assertSelectCount($select, 1, $output); } diff --git a/tests/Debug/Type/StringTest.php b/tests/Debug/Type/StringTest.php index 1edf4a83..fc883ee3 100644 --- a/tests/Debug/Type/StringTest.php +++ b/tests/Debug/Type/StringTest.php @@ -269,14 +269,15 @@ public static function providerTestMethod() . '' . \str_replace("\n", '' . "\n", $longStringExpect) . '… 1778 more bytes (not logged)' - . ''), + . '' + ), 'script' => 'console.log("long string",' . \json_encode($longStringExpect . '[1778 more bytes (not logged)]') . ');', 'streamAnsi' => "long string \e[38;5;245m=\e[0m \e[38;5;250m\"\e[0m" . $longStringExpect . "\e[38;5;250m\"\e[0m" . "\e[30;48;5;41m[1778 more bytes (not logged)]\e[0m", 'text' => 'long string = "' . $longStringExpect . '"[1778 more bytes (not logged)]', - ) + ), ), 'base64' => array( @@ -285,8 +286,8 @@ public static function providerTestMethod() \base64_encode(\file_get_contents(TEST_DIR . '/assets/logo.png')), ), array( - 'entry' => function (LogEntry $logEntry) use ($base64snip) { - $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":10852,"typeMore":"base64","value":' . \json_encode($base64snip) . ',"valueDecoded":{"brief":false,"strlen":%d,"typeMore":"binary","value":"","contentType":"%s","type":"string","debug":"\u0000debug\u0000"},"type":"string","debug":"\u0000debug\u0000"}],"meta":[]}'; + 'entry' => static function (LogEntry $logEntry) use ($base64snip) { + $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":10852,"type":"string","typeMore":"base64","value":' . \json_encode($base64snip) . ',"valueDecoded":{"brief":false,"contentType":"%s","strlen":%d,"type":"string","typeMore":"binary","value":"","debug":"\u0000debug\u0000"},"debug":"\u0000debug\u0000"}],"meta":[]}'; $jsonified = \json_encode($logEntry); self::assertStringMatchesFormat($jsonExpect, $jsonified); }, @@ -295,7 +296,7 @@ public static function providerTestMethod() $base64snip . '[10696 more bytes (not logged)]', ), null, - '' + '', ), 'html' => '
  • ' . "\n" . '' . "\n" @@ -318,7 +319,7 @@ public static function providerTestMethod() \base64_encode(\file_get_contents(TEST_DIR . '/assets/logo.png')), ), array( - 'entry' => function (LogEntry $logEntry) { + 'entry' => static function (LogEntry $logEntry) { }, 'html' => '
  • string(base64): ' @@ -335,8 +336,8 @@ public static function providerTestMethod() Debug::meta('redact'), ), array( - 'entry' => function (LogEntry $logEntry) use ($base64snip2) { - $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"typeMore":"base64","value":"' . $base64snip2 . '","valueDecoded":{"brief":false,"strlen":null,"typeMore":"json","value":"{\n \"poop\": \"\\\\ud83d\\\\udca9\",\n \"int\": 42,\n \"password\": \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\"\n}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"type":"string","attribs":{"class":["highlight","language-json"]},"addQuotes":false,"contentType":"application\/json","prettified":true,"prettifiedTag":true,"visualWhiteSpace":false,"debug":"\u0000debug\u0000"},"type":"string","debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; + 'entry' => static function (LogEntry $logEntry) use ($base64snip2) { + $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"type":"string","typeMore":"base64","value":"' . $base64snip2 . '","valueDecoded":{"addQuotes":false,"attribs":{"class":["highlight","language-json"]},"brief":false,"contentType":"application\/json","prettified":true,"prettifiedTag":true,"strlen":null,"type":"string","typeMore":"json","value":"{\n \"poop\": \"\\\\ud83d\\\\udca9\",\n \"int\": 42,\n \"password\": \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\"\n}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"visualWhiteSpace":false,"debug":"\u0000debug\u0000"},"debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; $jsonified = \json_encode($logEntry); self::assertSame($jsonExpect, $jsonified); }, @@ -364,7 +365,7 @@ public static function providerTestMethod()
  • ', 'script' => 'console.log("' . $base64snip2 . '");', 'text' => $base64snip2, - ) + ), ), 'base64.serialized.redact' => array( @@ -374,8 +375,8 @@ public static function providerTestMethod() Debug::meta('redact'), ), array( - 'entry' => function (LogEntry $logEntry) use ($base64snip3) { - $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"typeMore":"base64","value":"YTozOntzOjQ6InBvb3AiO3M6NDoi8J+SqSI7czozOiJpbnQiO2k6NDI7czo4OiJwYXNzd29yZCI7czo2OiJzZWNyZXQiO30=","valueDecoded":{"brief":false,"strlen":null,"typeMore":"serialized","value":"a:3:{s:4:\"poop\";s:4:\"\ud83d\udca9\";s:3:\"int\";i:42;s:8:\"password\";s:6:\"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\";}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"type":"string","debug":"\u0000debug\u0000"},"type":"string","debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; + 'entry' => static function (LogEntry $logEntry) use ($base64snip3) { + $jsonExpect = '{"method":"log","args":[{"brief":false,"strlen":null,"type":"string","typeMore":"base64","value":"' . $base64snip3 . '","valueDecoded":{"brief":false,"strlen":null,"type":"string","typeMore":"serialized","value":"a:3:{s:4:\"poop\";s:4:\"\ud83d\udca9\";s:3:\"int\";i:42;s:8:\"password\";s:6:\"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\";}","valueDecoded":{"poop":"\ud83d\udca9","int":42,"password":"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"},"debug":"\u0000debug\u0000"},"debug":"\u0000debug\u0000"}],"meta":{"redact":true}}'; $jsonified = \json_encode($logEntry); self::assertSame($jsonExpect, $jsonified); }, @@ -399,7 +400,7 @@ public static function providerTestMethod() ', 'script' => 'console.log("' . $base64snip3 . '");', 'text' => $base64snip3, - ) + ), ), 'binary' => array( @@ -534,7 +535,7 @@ public static function providerTestMethod() 'typeMore' => Abstracter::TYPE_STRING_JSON, 'value' => '{"poop":"\ud83d\udca9","int":42,"password":"█████████"}', 'valueDecoded' => null, - ) + ), ), 'meta' => array( 'redact' => true, @@ -543,7 +544,7 @@ public static function providerTestMethod() 'html' => '
  • {"poop":"\ud83d\udca9","int":42,"password":"█████████"}
      ', - ) + ), ), 'dblEncode' => array( @@ -575,7 +576,7 @@ public static function providerTestMethod() 'valueDecoded' => array( 'foo' => 'bar', ), - ) + ), ), 'meta' => array(), ), @@ -587,7 +588,7 @@ public static function providerTestMethod() . '
    • foo=>bar
    • ' . "\n" . '
    )
  • ' . "\n" . '', - ) + ), ), 'serialized.brief' => array( 'group', @@ -606,14 +607,14 @@ public static function providerTestMethod() 'typeMore' => Abstracter::TYPE_STRING_SERIALIZED, 'value' => 'a:1:{s:3:"foo";s:3:"bar";}', 'valueDecoded' => null, - ) + ), ), 'meta' => array(), ), 'html' => '
  • a:1:{s:3:"foo";s:3:"bar";}
      ', - ) + ), ), ); } diff --git a/tests/Debug/Utility/FileTreeTest.php b/tests/Debug/Utility/FileTreeTest.php index 834c01f4..9ab6149c 100644 --- a/tests/Debug/Utility/FileTreeTest.php +++ b/tests/Debug/Utility/FileTreeTest.php @@ -33,33 +33,33 @@ public function testFileTree() '/var/www' => array( 'excludedDir' => array( array( - 'value' => '2 omitted', 'attribs' => array( 'class' => array( 'exclude-count', ), ), 'type' => 'string', + 'value' => '2 omitted', 'debug' => Abstracter::ABSTRACTION, ), ), array( - 'value' => 'bootstrap.php', 'attribs' => array( - 'data-file' => '/var/www/bootstrap.php', 'class' => [], + 'data-file' => '/var/www/bootstrap.php', ), 'type' => 'string', - 'debug' => Abstracter::ABSTRACTION + 'value' => 'bootstrap.php', + 'debug' => Abstracter::ABSTRACTION, ), array( - 'value' => 'index.php', 'attribs' => array( - 'data-file' => '/var/www/index.php', 'class' => [], + 'data-file' => '/var/www/index.php', ), 'type' => 'string', - 'debug' => Abstracter::ABSTRACTION + 'value' => 'index.php', + 'debug' => Abstracter::ABSTRACTION, ), ), ); diff --git a/tests/Debug/Utility/PhpDocTest.php b/tests/Debug/Utility/PhpDocTest.php index c2403ed3..ec169c87 100644 --- a/tests/Debug/Utility/PhpDocTest.php +++ b/tests/Debug/Utility/PhpDocTest.php @@ -40,93 +40,93 @@ public function testGetParsedObject() $parsed = Debug::getInstance()->phpDoc->getParsed($obj); $expectJson = <<<'EOD' { - "summary": "Implement me!", - "desc": null, - "property": [ + "author": [ { - "type": "bool", - "name": "magicProp", - "desc": "I'm avail via __get()" + "desc": "Author desc is non-standard", + "email": "bkfake-github@yahoo.com", + "name": "Brad Kent" } ], - "property-read": [ + "desc": null, + "link": [ { - "type": "bool", - "name": "magicReadProp", - "desc": "Read Only!" + "desc": null, + "uri": "https:\/\/github.com\/bkdotcom\/PHPDebugConsole" } ], "method": [ { - "static": false, - "type": "void", + "desc": "I'm a magic method", "name": "presto", "param": [ { - "type": null, - "name": "$foo" + "name": "$foo", + "type": null }, { - "type": "int", + "defaultValue": "1", "name": "$int", - "defaultValue": "1" + "type": "int" }, { - "type": null, + "defaultValue": "true", "name": "$bool", - "defaultValue": "true" + "type": null }, { - "type": null, + "defaultValue": "null", "name": "$null", - "defaultValue": "null" + "type": null } ], - "desc": "I'm a magic method" + "static": false, + "type": "void" }, { - "static": true, - "type": "void", + "desc": "I'm a static magic method", "name": "prestoStatic", "param": [ { - "type": "string", - "name": "$noDefault" + "name": "$noDefault", + "type": "string" }, { - "type": null, + "defaultValue": "array()", "name": "$arr", - "defaultValue": "array()" + "type": null }, { - "type": null, + "defaultValue": "array('a'=>'ay','b'=>'bee')", "name": "$opts", - "defaultValue": "array('a'=>'ay','b'=>'bee')" + "type": null } ], - "desc": "I'm a static magic method" + "static": true, + "type": "void" } ], - "author": [ + "property": [ { - "name": "Brad Kent", - "email": "bkfake-github@yahoo.com", - "desc": "Author desc is non-standard" + "desc": "I'm avail via __get()", + "name": "magicProp", + "type": "bool" } ], - "link": [ + "property-read": [ { - "uri": "https:\/\/github.com\/bkdotcom\/PHPDebugConsole", - "desc": null + "desc": "Read Only!", + "name": "magicReadProp", + "type": "bool" } ], "see": [ { - "uri": null, + "desc": null, "fqsen": "subclass::method()", - "desc": null + "uri": null } ], + "summary": "Implement me!", "unknown": [ { "desc": "Some phpdoc tag" @@ -144,8 +144,8 @@ public function testGetParsedObject() $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocNoParent'); self::assertSame(array( - 'summary' => null, 'desc' => null, + 'summary' => null, ), $parsed); } @@ -153,28 +153,28 @@ public function testGetParsedMethod() { $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocImplements::someMethod()'); self::assertSame(array( - 'summary' => 'SomeInterface summary', 'desc' => 'SomeInterface description', 'return' => array( - 'type' => 'bdk\Test\Debug\Fixture\SomeInterface', 'desc' => null, + 'type' => 'bdk\Test\Debug\Fixture\SomeInterface', ), + 'summary' => 'SomeInterface summary', ), $parsed); $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocExtends::someMethod2()'); self::assertSame(array( - 'summary' => 'PhpDocImplements summary', 'desc' => 'PhpDocImplements desc', 'return' => array( - 'type' => 'void', 'desc' => null, + 'type' => 'void', ), + 'summary' => 'PhpDocImplements summary', ), $parsed); $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocExtends::someMethod3()'); self::assertSame(array( - 'summary' => 'PhpDocExtends summary', 'desc' => 'PhpDocExtends desc / PhpDocImplements desc', + 'summary' => 'PhpDocExtends summary', /* 'return' => array( 'type' => 'void', @@ -185,8 +185,8 @@ public function testGetParsedMethod() $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocNoParent::someMethod()'); self::assertSame(array( - 'summary' => null, 'desc' => null, + 'summary' => null, ), $parsed); } @@ -194,26 +194,26 @@ public function testGetParsedProperty() { $phpDoc = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Test2::$magicReadProp'); self::assertSame(array( - 'summary' => 'This property is important', 'desc' => null, + 'summary' => 'This property is important', 'var' => array( array( - 'type' => 'string', - 'name' => 'magicReadProp', 'desc' => '', + 'name' => 'magicReadProp', + 'type' => 'string', ), ), ), $phpDoc); $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocImplements::$someProperty'); self::assertSame(array( - 'summary' => '$someProperty summary', 'desc' => null, + 'summary' => '$someProperty summary', 'var' => array( array( - 'type' => 'string', - 'name' => 'someProperty', 'desc' => 'desc', + 'name' => 'someProperty', + 'type' => 'string', ), ), ), $parsed); @@ -227,8 +227,8 @@ public function testGetParsedConstant() $reflector = new \ReflectionClassConstant('\bdk\Test\Debug\Fixture\Utility\PhpDocExtends', 'SOME_CONSTANT'); $parsed = Debug::getInstance()->phpDoc->getParsed($reflector); self::assertSame(array( - 'summary' => 'PhpDocImplements summary', 'desc' => null, + 'summary' => 'PhpDocImplements summary', /* 'var' => array( array( @@ -242,8 +242,8 @@ public function testGetParsedConstant() $parsed = Debug::getInstance()->phpDoc->getParsed('\bdk\Test\Debug\Fixture\Utility\PhpDocExtends::SOME_CONSTANT'); self::assertSame(array( - 'summary' => 'PhpDocImplements summary', 'desc' => null, + 'summary' => 'PhpDocImplements summary', /* 'var' => array( array( @@ -256,7 +256,7 @@ public function testGetParsedConstant() ), $parsed); } - public static function dataProviderComments() + public static function providerComments() { return array( 'basic' => array( @@ -264,13 +264,13 @@ public static function dataProviderComments() * @var string $comment phpdoc comment */', array( - 'summary' => null, 'desc' => null, + 'summary' => null, 'var' => array( array( - 'type' => 'string', + 'desc' => 'phpdoc comment', 'name' => 'comment', - 'desc' => 'phpdoc comment' + 'type' => 'string', ), ), ), @@ -280,17 +280,17 @@ public static function dataProviderComments() * @method boolean magicMethod() */', array( - 'summary' => null, 'desc' => null, 'method' => array( array( - 'static' => false, - 'type' => 'bool', + 'desc' => null, 'name' => 'magicMethod', 'param' => array(), - 'desc' => null, + 'static' => false, + 'type' => 'bool', ), ), + 'summary' => null, ), ), 'missing $' => array( @@ -298,15 +298,15 @@ public static function dataProviderComments() * @param string comment */', array( - 'summary' => null, 'desc' => null, 'param' => array( array( - 'type' => 'string', - 'name' => 'comment', 'desc' => null, + 'name' => 'comment', + 'type' => 'string', ), ), + 'summary' => null, ), ), 'missing $ 2' => array( @@ -314,15 +314,15 @@ public static function dataProviderComments() * @param string comment here */', array( - 'summary' => null, 'desc' => null, 'param' => array( array( - 'type' => 'string', - 'name' => null, 'desc' => 'comment here', + 'name' => null, + 'type' => 'string', ), ), + 'summary' => null, ), ), 'multi lines' => array( @@ -336,19 +336,19 @@ public static function dataProviderComments() * @return self */', array( - 'summary' => 'Ding.', 'desc' => "Indented\nIndented 2", 'param' => array( array( - 'type' => 'int[]', - 'name' => '$number', 'desc' => "Some number\ndoes things", + 'name' => '$number', + 'type' => 'int[]', ), ), 'return' => array( - 'type' => 'self', 'desc' => null, + 'type' => 'self', ), + 'summary' => 'Ding.', ), ), 'complexType 1' => array( @@ -356,12 +356,12 @@ public static function dataProviderComments() * @return array{title: string, value: string, short: false} Very clear description */', array( - 'summary' => null, 'desc' => null, 'return' => array( - 'type' => 'array{title: string, value: string, short: false}', 'desc' => 'Very clear description', + 'type' => 'array{title: string, value: string, short: false}', ), + 'summary' => null, ), ), 'complexType 2' => array( @@ -369,12 +369,12 @@ public static function dataProviderComments() * @return array mumbo jumbo */', array( - 'summary' => null, 'desc' => null, 'return' => array( - 'type' => 'array', 'desc' => 'mumbo jumbo', + 'type' => 'array', ), + 'summary' => null, ), ), ); @@ -384,7 +384,7 @@ public static function dataProviderComments() * @param string $comment * @param array $expect * - * @dataProvider dataProviderComments + * @dataProvider providerComments */ public function testStrings($comment, $expect) { diff --git a/tests/Debug/Utility/SerializeLogTest.php b/tests/Debug/Utility/SerializeLogTest.php index 91a6dbf4..efe0ee45 100644 --- a/tests/Debug/Utility/SerializeLogTest.php +++ b/tests/Debug/Utility/SerializeLogTest.php @@ -7,6 +7,7 @@ use bdk\Debug\Utility\SerializeLog; use bdk\HttpMessage\ServerRequest; use bdk\Test\Debug\DebugTestFramework; +use bdk\Test\Debug\Fixture\TestObj; use bdk\Test\PolyFill\AssertionTrait; /** @@ -22,6 +23,7 @@ class SerializeLogTest extends DebugTestFramework public function testSerializeUnserialize() { $debug = new Debug(array( + 'collect' => true, 'logResponse' => false, 'serviceProvider' => array( 'serverRequest' => new ServerRequest( @@ -39,18 +41,19 @@ public function testSerializeUnserialize() $debug->alert('some alert'); $debug->groupSummary(); $debug->log('in summary'); + $debug->log(new TestObj()); $debug->groupEnd(); $debug->info('this is a test'); $serialized = SerializeLog::serialize($debug); $unserialized = SerializeLog::unserialize($serialized); - $this->assertIsArray($unserialized); + self::assertIsArray($unserialized); $channelNameRoot = $debug->getCfg('channelName', Debug::CONFIG_DEBUG); $expect = array( 'alerts' => $this->helper->deObjectifyData($debug->data->get('alerts'), false), 'config' => array( 'channelIcon' => $debug->getCfg('channelIcon', Debug::CONFIG_DEBUG), 'channelName' => $channelNameRoot, - 'channels' => \array_map(function (Debug $channel) use ($channelNameRoot) { + 'channels' => \array_map(static function (Debug $channel) use ($channelNameRoot) { $channelName = $channel->getCfg('channelName', Debug::CONFIG_DEBUG); return array( 'channelIcon' => $channel->getCfg('channelIcon', Debug::CONFIG_DEBUG), @@ -61,20 +64,22 @@ public function testSerializeUnserialize() }, $debug->getChannels(true, true)), 'logRuntime' => $debug->getCfg('logRuntime'), ), - 'log' => $this->helper->deObjectifyData($debug->data->get('log'), false), - 'logSummary' => $this->helper->deObjectifyData($debug->data->get('logSummary'), false), + 'log' => $this->helper->deObjectifyData($debug->data->get('log'), false, true), + 'logSummary' => $this->helper->deObjectifyData($debug->data->get('logSummary'), false, true), 'runtime' => $debug->data->get('runtime'), 'requestId' => $debug->data->get('requestId'), 'version' => Debug::VERSION, ); - $this->assertEquals( + self::assertEquals( $expect, $this->helper->deObjectifyData($unserialized) ); $debug = SerializeLog::import($unserialized); + $objAbs = $debug->data->get('logSummary.0.1.args.0'); + self::assertInstanceOf('bdk\\Debug\\Abstraction\\Abstraction', $objAbs); $serialized = SerializeLog::serialize($debug); $unserialized = SerializeLog::unserialize($serialized); - $this->assertEquals( + self::assertEquals( $expect, $this->helper->deObjectifyData($unserialized) ); @@ -95,7 +100,7 @@ public function testSerialieNotBase64() } $serialized = \base64_decode($serialized); $unserialized = SerializeLog::unserialize($serialized); - $this->assertFalse($unserialized); + self::assertFalse($unserialized); } public function testUnserializeLogLegacy() @@ -124,11 +129,11 @@ public function testUnserializeLogLegacy() EOD; $unserialized = SerializeLog::unserialize($serialized); $expect = array( - 'version' => '2.3', 'config' => array( 'channels' => array(), 'channelName' => 'general', ), + 'version' => '2.3', 'alerts' => array( array( 'alert', @@ -333,9 +338,9 @@ public function testUnserializeLogLegacy() 'channelName' => 'general', ), ); - $this->assertSame($expect, $unserialized); - $debug = SerializeLog::import($unserialized); + self::assertSame($expect, $unserialized); + $debug = SerializeLog::import($unserialized); /* Now test that imported log serializes as expected @@ -365,6 +370,7 @@ public function testUnserializeLogLegacy() $serialized = SerializeLog::serialize($debug); $unserialized = SerializeLog::unserialize($serialized); + $keysCompare = array('alerts', 'log','logSummary'); foreach ($expect['log'] as $i => $logEntryArray) { if (empty($logEntryArray[2])) { @@ -376,7 +382,7 @@ public function testUnserializeLogLegacy() unset($expect['logSummary'][0][$i][2]); } } - $this->assertEquals( + self::assertEquals( \array_intersect_key($expect, \array_flip($keysCompare)), \array_intersect_key($this->helper->deObjectifyData($unserialized), \array_flip($keysCompare)) ); diff --git a/tests/Debug/Utility/Utf8Test.php b/tests/Debug/Utility/Utf8Test.php index 454f084f..323e6088 100644 --- a/tests/Debug/Utility/Utf8Test.php +++ b/tests/Debug/Utility/Utf8Test.php @@ -31,7 +31,7 @@ public function testBufferAnalyze() 'blocks' => array( array( 'utf8special', - "\xef\xbb\xbf" + "\xef\xbb\xbf", ), array( 'utf8', @@ -42,8 +42,8 @@ public function testBufferAnalyze() 'bytesOther' => 0, 'bytesSpecial' => 3, 'bytesUtf8' => 9, - 'percentBinary' => 0, 'mbStrlen' => 10, + 'percentBinary' => 0, 'strlen' => 12, ), $stats1); self::assertSame($stats1, $stats2); diff --git a/tests/HttpMessage/UriUtilsTest.php b/tests/HttpMessage/UriUtilsTest.php index fa183d1f..68f453fb 100644 --- a/tests/HttpMessage/UriUtilsTest.php +++ b/tests/HttpMessage/UriUtilsTest.php @@ -9,7 +9,7 @@ /** * @covers bdk\HttpMessage\UriUtils * - * @phpcs:disable SlevomatCodingStandard.Arrays.AlphabeticallySortedKeys.IncorrectKeyOrder + * @phpcs:disable SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder */ class UriUtilsTest extends TestCase {