Skip to content

Commit

Permalink
add TYPE_IDENTIFIER_CLASSNAME, TYPE_IDENTIFIER_CONST, & TYPE_IDENTIFI…
Browse files Browse the repository at this point in the history
…ER_METHOD
  • Loading branch information
bkdotcom committed Oct 14, 2024
1 parent a95e23f commit f32cb55
Show file tree
Hide file tree
Showing 42 changed files with 137 additions and 170 deletions.
9 changes: 1 addition & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@
<include>
<directory suffix=".php">src</directory>
</include>
<!--
<report>
<clover outputFile="coverage/coverage.xml"/>
<html outputDirectory="coverage/html"/>
<text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
</report>
-->
<exclude>
<file>src/Debug/Collector/DoctrineLogger/CompatTrait_legacy.php</file>
<file>src/Debug/Collector/Doctrine/LoggerCompatTrait_legacy.php</file>
<file>src/Debug/Dump/charData.php</file>
<directory>src/Debug/Framework</directory>
<directory>src/Debug/node_modules</directory>
Expand Down
9 changes: 7 additions & 2 deletions src/Debug/Abstraction/Abstraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ public function setSubject($subject = null)
*/
protected function onSet($values = array())
{
if ($this->values['type'] === Type::TYPE_CONST) {
if ($this->values['type'] === Type::TYPE_CONST && $this->getValue('name') !== null) {
\trigger_error('Deprecated: TYPE_CONST', \E_USER_DEPRECATED);
$this->values['type'] = Type::TYPE_IDENTIFIER;
$this->values['typeMore'] = Type::TYPE_IDENTIFIER_CONST;
$this->values['backedValue'] = $this->values['value'];
$this->values['value'] = $this->values['name'];
unset($this->values['name']);
}
if ($this->getValue('typeMore') === Type::TYPE_STRING_CLASSNAME) {
\trigger_error('Deprecated: TYPE_STRING_CLASSNAME', \E_USER_DEPRECATED);
$this->values['type'] = Type::TYPE_IDENTIFIER;
$this->values['typeMore'] = 'className';
$this->values['typeMore'] = Type::TYPE_IDENTIFIER_CLASSNAME;
}
if (isset($values['attribs']) === false) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/Abstraction/Object/MethodParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private function getParamDefaultVal(ReflectionParameter $refParameter)
} elseif (PHP_VERSION_ID >= 50406 && $refParameter->isDefaultValueConstant()) {
$defaultValue = new Abstraction(Type::TYPE_IDENTIFIER, array(
'backedValue' => $defaultValue,
'typeMore' => 'const',
'typeMore' => Type::TYPE_IDENTIFIER_CONST,
'value' => $this->getConstantName($refParameter),
));
}
Expand Down Expand Up @@ -241,14 +241,14 @@ private function phpDocConstant($defaultValue, $className, array $matches)
if ($matches['classname'] === 'self' && \defined($className . '::' . $matches['const'])) {
return new Abstraction(Type::TYPE_IDENTIFIER, array(
'backedValue' => \constant($className . '::' . $matches['const']),
'typeMore' => 'const',
'typeMore' => Type::TYPE_IDENTIFIER_CONST,
'value' => $defaultValue, // constant name
));
}
if (\defined($defaultValue)) {
return new Abstraction(Type::TYPE_IDENTIFIER, array(
'backedValue' => \constant($defaultValue),
'typeMore' => 'const',
'typeMore' => Type::TYPE_IDENTIFIER_CONST,
'value' => $defaultValue, // constant name
));
}
Expand Down
5 changes: 4 additions & 1 deletion src/Debug/Abstraction/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Type
const TYPE_STRING = 'string';
const TYPE_CONST = 'const'; // non-native type (Abstraction: we store name and value)
// deprecated (use TYPE_IDENTIFIER)
const TYPE_IDENTIFIER = 'identifier'; // constant, className, method, property
const TYPE_IDENTIFIER = 'identifier'; // const, className, method, property
// value: identifier
// backedValue: underlying const or property value
// typeMore: 'const', 'className', 'method', 'property'
Expand All @@ -49,6 +49,9 @@ class Type
const TYPE_RAW = 'raw'; // raw object or array
const TYPE_FLOAT_INF = "\x00inf\x00";
const TYPE_FLOAT_NAN = "\x00nan\x00";
const TYPE_IDENTIFIER_CLASSNAME = 'className';
const TYPE_IDENTIFIER_CONST = 'const';
const TYPE_IDENTIFIER_METHOD = 'method';
const TYPE_STRING_BASE64 = 'base64';
const TYPE_STRING_BINARY = 'binary';
const TYPE_STRING_CLASSNAME = 'classname'; // deprecated (use TYPE_IDENTIFIER)
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Collector/StatementInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private function logParamsTypes()
$params[$name]['type'] = $isIntOrString && isset(self::$constants[$type])
? new Abstraction(Type::TYPE_IDENTIFIER, array(
'backedValue' => $type,
'typeMore' => 'const',
'typeMore' => Type::TYPE_IDENTIFIER_CONST,
'value' => self::$constants[$type],
))
: $type; // integer value (or enum)
Expand Down
9 changes: 3 additions & 6 deletions src/Debug/Dump/AbstractValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,13 @@ protected function getPerValueOptions($val, $opts)
* classname may be namespace\classname
* identifier = classname, constant function, or property
*
* @param Abstraction|array|string $val classname or classname(::|->)name (method/property/const)
* @param string $what ("classname"), "const", or "method"
* @param string|array $val classname or classname(::|->)name (method/property/const)
* @param string $what ("classname"), "const", or "method"
*
* @return array
*/
protected function parseIdentifier($val, $what = 'classname')
protected function parseIdentifier($val, $what = 'className')
{
if ($val instanceof Abstraction) {
$val = $val['value'];
}
$parts = \array_fill_keys(['classname', 'name', 'namespace', 'operator'], '');
$parts['classname'] = $val;
$matches = array();
Expand Down
23 changes: 3 additions & 20 deletions src/Debug/Dump/Base/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ class Value extends AbstractValue
/**
* Extend me to format classname/constant, etc
*
* @param mixed $val classname or classname(::|->)name (method/property/const)
* @param string|array $val classname or classname(::|->)name (method/property/const)
*
* @return string
*/
public function markupIdentifier($val)
{
if ($val instanceof Abstraction) {
$val = $val['value'];
}
if (\is_array($val)) {
$val = $val[0] . '::' . $val[1];
}
Expand Down Expand Up @@ -87,22 +84,8 @@ protected function dumpBool($val)
*/
protected function dumpCallable(Abstraction $abs)
{
return (!$abs['hideType'] ? 'callable: ' : '')
. $this->markupIdentifier($abs);
}

/**
* Dump constant
*
* @param Abstraction $abs constant abstraction
*
* @return string
*
* @deprecated 3.3
*/
protected function dumpConst(Abstraction $abs)
{
return $abs['name'];
return 'callable: '
. $this->markupIdentifier($abs['value']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Dump/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function substitutionAsString($val, $opts)
$opts['tagName'] = null;
$toStr = (string) $val; // objects __toString or its classname
return $toStr === $val['className']
? $this->valDumper->markupIdentifier($toStr, 'classname')
? $this->valDumper->markupIdentifier($toStr, 'className')
: $this->valDumper->dump($toStr, $opts);
}
return $this->valDumper->dump($val);
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/Dump/Html/HtmlObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function dumpAttributes(ObjectAbstraction $abs)
return '<dt class="attributes">attributes</dt>' . "\n"
. \implode(\array_map(function ($info) {
return '<dd class="attribute">'
. $this->valDumper->markupIdentifier($info['name'], 'classname')
. $this->valDumper->markupIdentifier($info['name'], 'className')
. $this->dumpAttributeArgs($info['arguments'])
. '</dd>' . "\n";
}, $attributes));
Expand Down Expand Up @@ -258,12 +258,12 @@ protected function dumpClassName(ObjectAbstraction $abs)
$absValues = \strpos(\json_encode($abs['implements']), '"UnitEnum"') !== false
? array(
'attribs' => $attribs,
'typeMore' => 'const',
'typeMore' => Type::TYPE_IDENTIFIER_CONST,
'value' => $abs['className'] . '::' . $abs['properties']['name']['value'],
)
: array(
'attribs' => $attribs,
'typeMore' => 'className',
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
'value' => $abs['className'],
);
$absTemp = new Abstraction(Type::TYPE_IDENTIFIER, $absValues);
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Dump/Html/Object/AbstractSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function dumpItems(ObjectAbstraction $abs, $what, array $cfg)
protected function buildInheritedFromHeading($className)
{
return '<dd class="heading">Inherited from '
. $this->valDumper->markupIdentifier($className, 'classname')
. $this->valDumper->markupIdentifier($className, 'className')
. '</dd>' . "\n";
}

Expand Down
4 changes: 2 additions & 2 deletions src/Debug/Dump/Html/Object/ExtendsImplements.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function buildTree(array $implements, $cssClass, array $interfacesCollap
'toggle-off' => \in_array($className, $interfacesCollapse, true),
),
),
$this->valDumper->markupIdentifier($className, 'classname')
$this->valDumper->markupIdentifier($className, 'className')
)
. (\is_array($v) ? "\n" . self::buildTree($v, $cssClass, $interfacesCollapse) : '')
. '</li>' . "\n";
Expand Down Expand Up @@ -138,7 +138,7 @@ private function dumpExtendsImplements(array $listOrTree, $label, $treeClass, $i
'toggle-off' => \in_array($className, $interfacesCollapse, true),
),
),
$this->valDumper->markupIdentifier($className, 'classname')
$this->valDumper->markupIdentifier($className, 'className')
) . "\n";
}, $listOrTree));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/Dump/Html/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function buildCaption()
}
$class = $this->dumper->valDumper->markupIdentifier(
$this->options['tableInfo']['class'],
'classname',
'className',
'span',
array(
'title' => $this->options['tableInfo']['summary'] ?: null,
Expand Down Expand Up @@ -170,7 +170,7 @@ protected function buildHeader()
foreach ($this->options['tableInfo']['columns'] as $colInfo) {
$label = $colInfo['key'];
if (isset($colInfo['class'])) {
$label .= ' ' . $this->dumper->valDumper->markupIdentifier($colInfo['class'], 'classname');
$label .= ' ' . $this->dumper->valDumper->markupIdentifier($colInfo['class'], 'className');
}
$labels[] = $label;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ protected function buildRow($row, array $rowInfo, $rowKey)
*/
if ($this->options['tableInfo']['haveObjRow']) {
$str .= $rowInfo['class']
? $this->dumper->valDumper->markupIdentifier($rowInfo['class'], 'classname', 'td', array(
? $this->dumper->valDumper->markupIdentifier($rowInfo['class'], 'className', 'td', array(
'title' => $rowInfo['summary'] ?: null,
))
: '<td class="t_undefined"></td>';
Expand Down
40 changes: 9 additions & 31 deletions src/Debug/Dump/Html/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public function dump($val, $opts = array())
* if namespaced additionally wrap namespace in span.namespace
* If callable, also wrap with .t_operator and .t_identifier
*
* @param mixed $val classname or classname(::|->)name (method/property/const)
* @param string $what ("classname"), "const", or "function" - specify what we're marking if ambiguous
* @param string $tagName ("span") html tag to use
* @param array $attribs (optional) additional html attributes for classname span (such as title)
* @param bool $wbr (false) whether to add a <wbr /> after the classname
* @param string|array $val classname or classname(::|->)name (method/property/const)
* @param string $what ("className"), "const", or "function" - specify what we're marking if ambiguous
* @param string $tagName ("span") html tag to use
* @param array $attribs (optional) additional html attributes for classname span (such as title)
* @param bool $wbr (false) whether to add a <wbr /> after the classname
*
* @return string html snippet
*/
public function markupIdentifier($val, $what = 'classname', $tagName = 'span', $attribs = array(), $wbr = false)
public function markupIdentifier($val, $what = 'className', $tagName = 'span', $attribs = array(), $wbr = false)
{
$parts = \array_map([$this->string, 'dump'], $this->parseIdentifier($val, $what));
$class = 'classname';
Expand Down Expand Up @@ -271,34 +271,12 @@ protected function dumpCallable(Abstraction $abs)
if ($this->optionGet('tagName') !== 'td') {
$this->optionSet('tagName', null);
}
return (!$abs['hideType'] ? '<span class="t_type">callable</span> ' : '')
. '<span class="t_identifier">'
. $this->markupIdentifier($abs)
return '<span class="t_type">callable</span> '
. '<span class="t_identifier" data-type-more="callable">'
. $this->markupIdentifier($abs['value'], 'callable')
. '</span>';
}

/**
* Dump "const" abstraction as html
*
* Object constant or method param's default value
*
* @param Abstraction $abs const abstraction
*
* @return string
*
* @deprecated 3.3
*/
protected function dumpConst(Abstraction $abs)
{
$this->optionSet('type', Type::TYPE_IDENTIFIER);
$this->optionSet('typeMore', 'const');
return $this->dumpIdentifier(new Abstraction(Type::TYPE_IDENTIFIER, array(
'backedValue' => $abs['value'],
'typeMore' => 'const',
'value' => $abs['name'],
)));
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Dump/Text/TextObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(ValDumper $valDumper)
*/
public function dump(ObjectAbstraction $abs)
{
$className = $this->valDumper->markupIdentifier($abs['className'], 'classname');
$className = $this->valDumper->markupIdentifier($abs['className'], 'className');
if ($abs['isRecursion']) {
return $className . ' *RECURSION*';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Dump/TextAnsi/TextAnsiObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(ValDumper $valDumper)
*/
public function dump(ObjectAbstraction $abs)
{
$className = $this->valDumper->markupIdentifier($abs['className'], 'classname');
$className = $this->valDumper->markupIdentifier($abs['className'], 'className');
$escapeCodes = $this->valDumper->getCfg('escapeCodes');
$escapeReset = $this->valDumper->escapeReset;
if ($abs['isRecursion']) {
Expand Down
23 changes: 3 additions & 20 deletions src/Debug/Dump/TextAnsi/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function setEscapeReset($escapeReset = "\e[0m")
/**
* Add ansi escape sequences for classname type strings
*
* @param mixed $val classname or classname(::|->)name (method/property/const)
* @param string $what ("classname"), "const", or "function" - specify what we're marking if ambiguous
* @param string|array $val classname or classname(::|->)name (method/property/const)
* @param string $what ("classname"), "const", or "function" - specify what we're marking if ambiguous
*
* @return string
*/
public function markupIdentifier($val, $what = 'classname')
public function markupIdentifier($val, $what = 'className')
{
$parts = $this->parseIdentifier($val, $what);
$escapeReset = $this->escapeReset;
Expand Down Expand Up @@ -183,23 +183,6 @@ protected function dumpBool($val)
: $this->cfg['escapeCodes']['false'] . 'false' . $this->escapeReset;
}

/**
* Dump constant
*
* @param Abstraction $abs constant abstraction
*
* @return string
*
* @deprecated 3.3
*/
protected function dumpConst(Abstraction $abs)
{
return $this->dumpIdentifier(new Abstraction(Type::TYPE_IDENTIFIER, array(
'typeMore' => 'const',
'value' => $abs['name'],
)));
}

/**
* Dump float value
*
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Framework/Cake4.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function logEvents()
\get_class($event->getSubject()),
array(
'type' => Type::TYPE_IDENTIFIER,
'typeMore' => 'className',
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
)
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Framework/Laravel/LogViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function logViewParams(View $view)
$data[$k] = $type === 'object'
? $this->debug->abstracter->crateWithVals(\get_class($v), array(
'type' => Type::TYPE_IDENTIFIER,
'typeMore' => 'className',
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
))
: $type;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Framework/Laravel/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected function logSession()
$debug->log(
$this->debug->abstracter->crateWithVals(\get_class($this->container['session']), array(
'type' => Type::TYPE_IDENTIFIER,
'typeMore' => 'className',
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
))
);
$debug->log(
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Framework/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function buildModelCountTable(&$tableInfoRows)
'data-file' => $ref->getFileName(),
),
'type' => Type::TYPE_IDENTIFIER,
'typeMore' => 'className',
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
)),
);
}
Expand Down
Loading

0 comments on commit f32cb55

Please sign in to comment.