Skip to content

Commit

Permalink
Php 8.4 - E_STRICT is deprecated
Browse files Browse the repository at this point in the history
Html output - update Extends and Implements to use t_identifier class
coding standards
  • Loading branch information
bkdotcom committed Oct 18, 2024
1 parent 4d102d5 commit 018f720
Show file tree
Hide file tree
Showing 26 changed files with 318 additions and 227 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ jobs:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
# windows-latest, macOS-latest
operating-system: [ubuntu-latest]
php-version: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-version: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
name: PHP ${{ matrix.php-version }} Test on ${{ matrix.operating-system }}
# services:
# mysql:
# image: mysql:5.7
# env:
# MYSQL_ALLOW_EMPTY_PASSWORD: yes
# MYSQL_DATABASE: test
# ports:
# - 3306
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
MYSQL_DATABASE: test
MYSQL_USERNAME: root
Expand Down
1 change: 0 additions & 1 deletion src/Debug/AbstractDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use bdk\Debug\LogEntry;
use bdk\Debug\ServiceProvider;
use bdk\PubSub\Event;
use InvalidArgumentException;
use ReflectionMethod;

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Debug/Collector/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function prepare(string $sql): StatementInterface
return new Statement(
parent::prepare($sql),
$this,
$sql,
$sql
);
}

Expand Down Expand Up @@ -127,6 +127,11 @@ public function rollBack(): void
parent::rollBack();
}

/**
* Build DSN url from params
*
* @return string
*/
private function buildDsn()
{
$params = \array_merge(array(
Expand Down
8 changes: 6 additions & 2 deletions src/Debug/Collector/Doctrine/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ public function __construct(
$this->sql = $sql;
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING): void
{
$this->params[$param] = $value;
$this->types[$param] = $type;
parent::bindValue($param, $value, $type);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
public function execute($params = null): ResultInterface
{
$info = new StatementInfo(
Expand Down
5 changes: 3 additions & 2 deletions src/Debug/Collector/DoctrineMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class DoctrineMiddleware implements MiddlewareInterface
*
* @param Debug|null $debug Debug instance
*/
public function __construct(?Debug $debug = null) {
public function __construct(?Debug $debug = null)
{
if (!$debug) {
$debug = Debug::getChannel('Doctrine', array('channelIcon' => $this->icon));
} elseif ($debug === $debug->rootInstance) {
Expand All @@ -54,4 +55,4 @@ public function wrap(DriverInterface $driver): DriverInterface
{
return new Driver($driver, $this->debug);
}
}
}
3 changes: 1 addition & 2 deletions src/Debug/Collector/StatementInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ protected function getErrorMessage()
*/
private function getGroupLabel()
{
$label = $this->sql;
$label = \preg_replace('/[\r\n\s]+/', ' ', $label);
$label = \preg_replace('/[\r\n\s]+/', ' ', $this->sql);
$label = $this->debug->sql->replaceParams($label, $this->params);
$parsed = $this->debug->sql->parse($label);
if ($parsed === false) {
Expand Down
129 changes: 129 additions & 0 deletions src/Debug/Dump/Html/HtmlArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

/**
* This file is part of PHPDebugConsole
*
* @package PHPDebugConsole
* @author Brad Kent <[email protected]>
* @license http://opensource.org/licenses/MIT MIT
* @copyright 2014-2024 Brad Kent
* @since 3.3
*/

namespace bdk\Debug\Dump\Html;

use bdk\Debug;
use bdk\Debug\Abstraction\Abstraction;
use bdk\Debug\Dump\Html\Value as ValDumper;

/**
* Output array with HTML markup
*/
class HtmlArray
{
/** @var Debug */
public $debug;

/** @var ValDumper */
public $valDumper;

/** @var \bdk\Debug\Utility\Html */
protected $html;

/**
* Constructor
*
* @param ValDumper $valDumper Dump\Html\Value instance
*/
public function __construct(ValDumper $valDumper)
{
$this->debug = $valDumper->debug;
$this->html = $this->debug->html;
$this->valDumper = $valDumper;
}

/**
* Dump array
*
* @param array $array string value
* @param Abstraction|null $abs (optional) full abstraction
*
* @return string
*/
public function dump(array $array, $abs = null)
{
\bdk\Debug\Utility\Php::assertType($abs, 'bdk\Debug\Abstraction\Abstraction');

$opts = $this->optionsGet();
if ($opts['isMaxDepth']) {
$this->valDumper->optionSet('attribs.class.__push__', 'max-depth');
return '<span class="t_keyword">array</span> <span class="t_maxDepth">*MAX DEPTH*</span>';
}
if (empty($array)) {
return '<span class="t_keyword">array</span><span class="t_punct">()</span>';
}
if ($opts['expand'] !== null) {
$this->valDumper->optionSet('attribs.data-expand', $opts['expand']);
}
if ($opts['asFileTree']) {
$this->valDumper->optionSet('attribs.class.__push__', 'array-file-tree');
}
$keys = isset($abs['keys']) ? $abs['keys'] : array();
$outputKeys = $opts['showListKeys'] || !$this->debug->arrayUtil->isList($array);
return '<span class="t_keyword">array</span><span class="t_punct">(</span>' . "\n"
. '<ul class="array-inner list-unstyled">' . "\n"
. $this->dumpArrayValues($array, $outputKeys, $keys)
. '</ul><span class="t_punct">)</span>';
}

/**
* Dump an array key/value pair
*
* @param array $array array to output
* @param bool $outputKeys include key with value?
* @param array $absKeys keys that required abstraction (ie, non-utf8, or containing confusable characters)
*
* @return string
*/
private function dumpArrayValues(array $array, $outputKeys, array $absKeys)
{
$html = '';
foreach ($array as $key => $val) {
if (isset($absKeys[$key])) {
$key = $absKeys[$key];
}
$html .= $outputKeys
? "\t" . '<li>'
. $this->html->buildTag(
'span',
array(
'class' => array(
't_int' => \is_int($key),
't_key' => true,
),
),
$this->valDumper->dump($key, array('tagName' => null)) // don't wrap it
)
. '<span class="t_operator">=&gt;</span>'
. $this->valDumper->dump($val)
. '</li>' . "\n"
: "\t" . $this->valDumper->dump($val, array('tagName' => 'li')) . "\n";
}
return $html;
}

/**
* Return current options with defaults
*
* @return array<non-empty-string,mixed>
*/
private function optionsGet()
{
return \array_merge(array(
'asFileTree' => false,
'expand' => null,
'isMaxDepth' => false,
'showListKeys' => true,
), $this->valDumper->optionGet());
}
}
25 changes: 15 additions & 10 deletions src/Debug/Dump/Html/Object/ExtendsImplements.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

namespace bdk\Debug\Dump\Html\Object;

use bdk\Debug\Abstraction\Abstraction;
use bdk\Debug\Abstraction\Object\Abstraction as ObjectAbstraction;
use bdk\Debug\Abstraction\Type;
use bdk\Debug\Dump\Html\Helper;
use bdk\Debug\Dump\Html\Value as ValDumper;
use bdk\Debug\Utility\Html as HtmlUtil;
Expand Down Expand Up @@ -92,16 +94,17 @@ private function buildTree(array $implements, $cssClass, array $interfacesCollap
? $k
: $v;
$str .= '<li>'
. $this->html->buildTag(
'span',
array(
. $this->valDumper->dump(new Abstraction(Type::TYPE_IDENTIFIER, array(
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
'value' => $className,
)), array(
'attribs' => array(
'class' => array(
$cssClass => true,
'toggle-off' => \in_array($className, $interfacesCollapse, true),
),
),
$this->valDumper->markupIdentifier($className, 'className')
)
))
. (\is_array($v) ? "\n" . self::buildTree($v, $cssClass, $interfacesCollapse) : '')
. '</li>' . "\n";
}
Expand Down Expand Up @@ -130,16 +133,18 @@ private function dumpExtendsImplements(array $listOrTree, $label, $treeClass, $i
if ($this->valDumper->debug->arrayUtil->isList($listOrTree)) {
return '<dt>' . $label . '</dt>' . "\n"
. \implode(\array_map(function ($className) use ($itemClass, $interfacesCollapse) {
return $this->html->buildTag(
'dd',
array(
return $this->valDumper->dump(new Abstraction(Type::TYPE_IDENTIFIER, array(
'typeMore' => Type::TYPE_IDENTIFIER_CLASSNAME,
'value' => $className,
)), array(
'attribs' => array(
'class' => array(
$itemClass => true,
'toggle-off' => \in_array($className, $interfacesCollapse, true),
),
),
$this->valDumper->markupIdentifier($className, 'className')
) . "\n";
'tagName' => 'dd',
)) . "\n";
}, $listOrTree));
}
return '<dt>' . $label . '</dt>' . "\n"
Expand Down
69 changes: 6 additions & 63 deletions src/Debug/Dump/Html/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use bdk\Debug\Abstraction\Type;
use bdk\Debug\Dump\Base\Value as BaseValue;
use bdk\Debug\Dump\Html as Dumper;
use bdk\Debug\Dump\Html\HtmlArray;
use bdk\Debug\Dump\Html\HtmlObject;
use bdk\Debug\Dump\Html\HtmlString;

Expand All @@ -27,6 +28,9 @@
*/
class Value extends BaseValue
{
/** @var HtmlArray array dumper */
public $array;

/** @var HtmlString string dumper */
public $string;

Expand All @@ -45,6 +49,7 @@ public function __construct(Dumper $dumper)
{
parent::__construct($dumper); // sets debug and dumper
$this->html = $this->debug->html;
$this->array = new HtmlArray($this);
$this->string = new HtmlString($this);
$this->optionStackPush(array(
'charHighlight' => true,
Expand Down Expand Up @@ -181,69 +186,7 @@ public function optionSet($what, $val = null)
*/
protected function dumpArray(array $array, $abs = null)
{
\bdk\Debug\Utility\Php::assertType($abs, 'bdk\Debug\Abstraction\Abstraction');

$opts = \array_merge(array(
'asFileTree' => false,
'expand' => null,
'isMaxDepth' => false,
'showListKeys' => true,
), $this->optionGet());
if ($opts['isMaxDepth']) {
$this->optionSet('attribs.class.__push__', 'max-depth');
return '<span class="t_keyword">array</span> <span class="t_maxDepth">*MAX DEPTH*</span>';
}
if (empty($array)) {
return '<span class="t_keyword">array</span><span class="t_punct">()</span>';
}
if ($opts['expand'] !== null) {
$this->optionSet('attribs.data-expand', $opts['expand']);
}
if ($opts['asFileTree']) {
$this->optionSet('attribs.class.__push__', 'array-file-tree');
}
$keys = isset($abs['keys']) ? $abs['keys'] : array();
$outputKeys = $opts['showListKeys'] || !$this->debug->arrayUtil->isList($array);
return '<span class="t_keyword">array</span><span class="t_punct">(</span>' . "\n"
. '<ul class="array-inner list-unstyled">' . "\n"
. $this->dumpArrayValues($array, $outputKeys, $keys)
. '</ul><span class="t_punct">)</span>';
}

/**
* Dump an array key/value pair
*
* @param array $array array to output
* @param bool $outputKeys include key with value?
* @param array $absKeys keys that required abstraction (ie, non-utf8, or containing confusable characters)
*
* @return string
*/
private function dumpArrayValues(array $array, $outputKeys, array $absKeys)
{
$html = '';
foreach ($array as $key => $val) {
if (isset($absKeys[$key])) {
$key = $absKeys[$key];
}
$html .= $outputKeys
? "\t" . '<li>'
. $this->html->buildTag(
'span',
array(
'class' => array(
't_int' => \is_int($key),
't_key' => true,
),
),
$this->dump($key, array('tagName' => null)) // don't wrap it
)
. '<span class="t_operator">=&gt;</span>'
. $this->dump($val)
. '</li>' . "\n"
: "\t" . $this->dump($val, array('tagName' => 'li')) . "\n";
}
return $html;
return $this->array->dump($array, $abs);
}

/**
Expand Down
Loading

0 comments on commit 018f720

Please sign in to comment.