Skip to content

Commit

Permalink
coding standards (primarily Arrays.AlphabeticallySortedByKeys)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Apr 25, 2023
1 parent 3262ef5 commit 888e1de
Show file tree
Hide file tree
Showing 121 changed files with 642 additions and 583 deletions.
7 changes: 6 additions & 1 deletion phpcs.slevomat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Complexity.Cognitive" />
<rule ref="SlevomatCodingStandard.Complexity.Cognitive">
<properties>
<property name="warningThreshold" value="6" />
<property name="errorThreshold" value="10" />
</properties>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses" />
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses" />
Expand Down
4 changes: 0 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<rule ref="./phpcs.slevomat.xml" />
-->

<!--
<rule ref="./vendor/rarst/phpcs-cognitive-complexity/src/CognitiveComplexity/ruleset.xml" />
-->

<rule ref="./Sniffs">
<exclude name="bdk.Commenting.FunctionComment.EmptyThrows" />
<exclude name="bdk.Commenting.FunctionComment.ParamCommentFullStop" />
Expand Down
6 changes: 3 additions & 3 deletions src/Backtrace/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

/**
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Backtrace/SkipInternal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Debug/AbstractDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
77 changes: 41 additions & 36 deletions src/Debug/Abstraction/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Debug/Abstraction/AbstractObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Abstraction/AbstractObjectMethodParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 3 additions & 4 deletions src/Debug/Abstraction/AbstractObjectMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class AbstractObjectMethods
'summary' => null,
),
'return' => array(
'type' => null,
'desc' => null,
'type' => null,
),
'visibility' => 'public', // public | private | protected | magic
);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 13 additions & 14 deletions src/Debug/Abstraction/AbstractObjectProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -360,7 +359,6 @@ private function addViaPhpDocInherit(Abstraction $abs)
if (!$tagIntersect) {
continue;
}
// $haveMagic = true;
$inheritedFrom = $reflector->getName();
$abs['phpDoc'] = \array_merge(
$abs['phpDoc'],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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']) {
Expand All @@ -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']);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Abstraction/AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Abstraction/Abstracter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down
Loading

0 comments on commit 888e1de

Please sign in to comment.