Skip to content

Commit

Permalink
backport some work that's gone into v3.1 - notably: don't apply strin…
Browse files Browse the repository at this point in the history
…gMaxLen to StatementInfo query
  • Loading branch information
bkdotcom committed May 18, 2023
1 parent cb75f76 commit c2f126f
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 118 deletions.
6 changes: 3 additions & 3 deletions src/Debug/Abstraction/AbstractArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Abstracter $abstracter)
*
* @return array|string
*/
public function crate($array, $method = null, $hist = array())
public function crate(array $array, $method = null, array $hist = array())
{
if (\in_array($array, $hist, true)) {
return Abstracter::RECURSION;
Expand All @@ -63,7 +63,7 @@ public function crate($array, $method = null, $hist = array())
*
* @return Abstraction
*/
public function getAbstraction(&$array, $method = null, $hist = array())
public function getAbstraction(array &$array, $method = null, array $hist = array())
{
return new Abstraction(Abstracter::TYPE_ARRAY, array(
'value' => $this->crate($array, $method, $hist),
Expand All @@ -77,7 +77,7 @@ public function getAbstraction(&$array, $method = null, $hist = array())
*
* @return Abstraction
*/
public function getCallableAbstraction($array)
public function getCallableAbstraction(array $array)
{
$className = \is_object($array[0])
? \get_class($array[0])
Expand Down
8 changes: 4 additions & 4 deletions src/Debug/Abstraction/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function getAbstraction($obj, $method = null, $hist = array())
*
* @return array
*/
public static function buildObjValues($values = array())
public static function buildObjValues(array $values = array())
{
$cfgFlags = \array_reduce(self::$cfgFlags, static function ($carry, $val) {
return $carry | $val;
Expand Down Expand Up @@ -313,7 +313,7 @@ private function absClean(Abstraction $abs)
*
* @return void
*/
private function addEnumCasePhpDoc($abs)
private function addEnumCasePhpDoc(Abstraction $abs)
{
if (!($abs['cfgFlags'] & self::PHPDOC_COLLECT)) {
return;
Expand Down Expand Up @@ -480,7 +480,7 @@ private function getCfgFlags()
*
* @return null|string
*/
private function getScopeClass(&$hist)
private function getScopeClass(array &$hist)
{
for ($i = \count($hist) - 1; $i >= 0; $i--) {
if (\is_object($hist[$i])) {
Expand Down Expand Up @@ -544,7 +544,7 @@ private function isExcluded($obj)
*
* @return bool
*/
private function isObjInList($obj, $list)
private function isObjInList($obj, array $list)
{
$classname = \get_class($obj);
if (\array_intersect(array('*', $classname), $list)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/Abstraction/AbstractObjectConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function add(Abstraction $abs)
while ($reflector) {
PHP_VERSION_ID >= 70100
? $this->addConstantsReflection($reflector)
: $this->addConstants($reflector);
: $this->addConstantsLegacy($reflector);
$reflector = $reflector->getParentClass();
}
foreach ($this->constants as $name => $info) {
Expand All @@ -84,7 +84,7 @@ public function add(Abstraction $abs)
*
* @return void
*/
public function addCases($abs)
public function addCases(Abstraction $abs)
{
$abs['cases'] = array();
if ($abs['isTraverseOnly']) {
Expand Down Expand Up @@ -113,7 +113,7 @@ public function addCases($abs)
*
* @return void
*/
private function addConstants(ReflectionClass $reflector)
private function addConstantsLegacy(ReflectionClass $reflector)
{
foreach ($reflector->getConstants() as $name => $value) {
if (isset($this->constants[$name])) {
Expand Down
28 changes: 15 additions & 13 deletions src/Debug/Abstraction/AbstractObjectProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,30 +400,32 @@ private function addViaPhpDocIter(Abstraction $abs, $inheritedFrom)
*/
private function addViaRef(Abstraction $abs)
{
$refObject = $abs['reflector'];
/*
We trace our ancestory to learn where properties are inherited from
*/
while ($refObject) {
$className = $refObject->getName();
$properties = $refObject->getProperties();
while ($properties) {
$refProperty = \array_shift($properties);
$reflector = $abs['reflector'];
$properties = $abs['properties'];
while ($reflector) {
$className = $reflector->getName();
$refProperties = $reflector->getProperties();
while ($refProperties) {
$refProperty = \array_shift($refProperties);
$name = $refProperty->getName();
if (isset($abs['properties'][$name])) {
if (isset($properties[$name])) {
// already have info... we're in an ancestor
$abs['properties'][$name]['overrides'] = $this->propOverrides(
$properties[$name]['overrides'] = $this->propOverrides(
$refProperty,
$abs['properties'][$name],
$properties[$name],
$className
);
$abs['properties'][$name]['originallyDeclared'] = $className;
$properties[$name]['originallyDeclared'] = $className;
continue;
}
$abs['properties'][$name] = $this->buildPropViaRef($abs, $refProperty);
$properties[$name] = $this->buildPropViaRef($abs, $refProperty);
}
$refObject = $refObject->getParentClass();
$reflector = $reflector->getParentClass();
}
$abs['properties'] = $properties;
}

/**
Expand Down Expand Up @@ -465,8 +467,8 @@ private function buildPropViaPhpDoc(Abstraction $abs, $phpDocProp, $inheritedFro
*/
private function buildPropViaRef(Abstraction $abs, ReflectionProperty $refProperty)
{
$refProperty->setAccessible(true); // only accessible via reflection
$phpDoc = $this->helper->getPhpDocVar($refProperty); // phpDocVar
$refProperty->setAccessible(true); // only accessible via reflection
/*
getDeclaringClass returns "LAST-declared/overriden"
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Debug/Abstraction/AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function getAbstraction($string, $typeMore = null, $crateVals = array())
$absValues = $this->getAbsValuesSerialized($absValues);
break;
default:
$absValues['value'] = $this->debug->utf8->strcut($string, 0, $absValues['maxlen']);
if ($absValues['maxlen'] > -1) {
$absValues['value'] = $this->debug->utf8->strcut($string, 0, $absValues['maxlen']);
}
}
$absValues = $this->absValuesFinish($absValues);
return new Abstraction(Abstracter::TYPE_STRING, $absValues);
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 @@ -423,7 +423,7 @@ private function getTypePhp($val)
'integer' => self::TYPE_INT,
'NULL' => self::TYPE_NULL,
'resource (closed)' => self::TYPE_RESOURCE,
'unknown type' => self::TYPE_UNKNOWN, // closed resource < php 7.2
'unknown type' => self::TYPE_UNKNOWN, // closed resource (php < 7.2)
);
if (isset($map[$type])) {
$type = $map[$type];
Expand Down
6 changes: 5 additions & 1 deletion src/Debug/Collector/StatementInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ private function getGroupLabel()
}
$label = \preg_replace('/[\r\n\s]+/', ' ', $label);
}
return $label;
return \strlen($label) > 100
? \substr($label, 0, 100) . '…'
: (string) $label;
}

/**
Expand Down Expand Up @@ -367,6 +369,7 @@ private function logQuery($label)
if (\preg_replace('/[\r\n\s]+/', ' ', $this->sql) === $label) {
return;
}
$stringMaxLenWas = $this->debug->setCfg('stringMaxLen', -1);
$sqlPretty = $this->debug->prettify($this->sql, 'application/sql');
if ($sqlPretty instanceof Abstraction) {
$this->prettified = $sqlPretty['prettified'];
Expand All @@ -380,6 +383,7 @@ private function logQuery($label)
),
))
);
$this->debug->setCfg('stringMaxLen', $stringMaxLenWas);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/Debug/Dump/Html/ObjectConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ public function dumpCases(Abstraction $abs)
public function dumpConstants(Abstraction $abs)
{
$constants = $abs['constants'];
$cfg = array(
$opts = array(
'attributeOutput' => $abs['cfgFlags'] & AbstractObject::CONST_ATTRIBUTE_OUTPUT,
'constCollect' => $abs['cfgFlags'] & AbstractObject::CONST_COLLECT,
'constOutput' => $abs['cfgFlags'] & AbstractObject::CONST_OUTPUT,
'phpDocOutput' => $abs['cfgFlags'] & AbstractObject::PHPDOC_OUTPUT,
);
if (!$cfg['constOutput']) {
if (!$opts['constOutput']) {
return '';
}
if (!$cfg['constCollect']) {
if (!$opts['constCollect']) {
return '<dt class="constants">constants <i>not collected</i></dt>' . "\n";
}
if (!$constants) {
return '';
}
$html = '<dt class="constants">constants</dt>' . "\n";
foreach ($constants as $name => $info) {
$html .= $this->dumpConstant($name, $info, $cfg);
$html .= $this->dumpConstant($name, $info, $opts) . "\n";
}
return $html;
}
Expand Down Expand Up @@ -141,21 +141,21 @@ protected function dumpCase($name, $info, $cfg)
}

/**
* Dump Constant
* Dump constant as HTML
*
* @param string $name Constant's name
* @param array $info Constant info
* @param array $cfg Constant config vals
* @param array $opts options
*
* @return string html fragment
*/
protected function dumpConstant($name, $info, $cfg)
protected function dumpConstant($name, array $info, array $opts)
{
$modifiers = \array_keys(\array_filter(array(
$info['visibility'] => true,
'final' => $info['isFinal'],
)));
$title = $cfg['phpDocOutput']
$title = $opts['phpDocOutput']
? (string) $info['desc']
: '';
return $this->html->buildTag(
Expand All @@ -165,7 +165,7 @@ protected function dumpConstant($name, $info, $cfg)
array('constant'),
$modifiers
),
'data-attributes' => $cfg['attributeOutput'] && $info['attributes']
'data-attributes' => $opts['attributeOutput'] && $info['attributes']
? $info['attributes']
: null,
),
Expand All @@ -175,6 +175,6 @@ protected function dumpConstant($name, $info, $cfg)
. ' <span class="t_identifier" title="' . \htmlspecialchars($title) . '">' . $name . '</span>'
. ' <span class="t_operator">=</span> '
. $this->valDumper->dump($info['value'])
) . "\n";
);
}
}
Loading

0 comments on commit c2f126f

Please sign in to comment.