Skip to content

Commit

Permalink
used PHP 7.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 13, 2018
1 parent 93ce168 commit 17d2eae
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/Nette/MailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(Nette\Mail\IMailer $mailer, $fromEmail = null)
*/
public function send($message, $email)
{
$host = preg_replace('#[^\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
$host = preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n'));

$mail = new Nette\Mail\Message;
$mail->setHeader('X-Mailer', 'Tracy');
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Nette/TracyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
}

$logger = $builder->getDefinition($this->prefix('logger'));
if ($logger->getFactory()->getEntity() !== ['Tracy\Debugger', 'getLogger']) {
if ($logger->getFactory()->getEntity() !== [Tracy\Debugger::class, 'getLogger']) {
$initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger]));
}
if ($this->config['netteMailer'] && $builder->getByType('Nette\Mail\IMailer')) {
if ($this->config['netteMailer'] && $builder->getByType(Nette\Mail\IMailer::class)) {
$initialize->addBody($builder->formatPhp('Tracy\Debugger::getLogger(?)->mailer = ?;', [
$logger,
[new Nette\DI\Statement('Tracy\Bridges\Nette\MailSender', ['fromEmail' => $this->config['fromEmail']]), 'send'],
[new Nette\DI\Statement(Tracy\Bridges\Nette\MailSender::class, ['fromEmail' => $this->config['fromEmail']]), 'send'],
]));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tracy/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function addPanel(IBarPanel $panel, $id = null)
*/
public function getPanel($id)
{
return isset($this->panels[$id]) ? $this->panels[$id] : null;
return $this->panels[$id] ?? null;
}


Expand Down Expand Up @@ -186,7 +186,7 @@ private function renderPanels($suffix = null)
*/
public function dispatchAssets()
{
$asset = isset($_GET['_tracy_bar']) ? $_GET['_tracy_bar'] : null;
$asset = $_GET['_tracy_bar'] ?? null;
if ($asset === 'js') {
header('Content-Type: text/javascript');
header('Cache-Control: max-age=864000');
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private function renderPanels($ex)
$res = [];
foreach ($this->panels as $callback) {
try {
$panel = call_user_func($callback, $ex);
$panel = $callback($ex);
if (empty($panel['tab']) || empty($panel['panel'])) {
continue;
}
Expand Down
18 changes: 8 additions & 10 deletions src/Tracy/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
class Debugger
{
const VERSION = '3.0-dev';
public const VERSION = '3.0-dev';

/** server modes for Debugger::enable() */
const
public const
DEVELOPMENT = false,
PRODUCTION = true,
DETECT = null;

const COOKIE_SECRET = 'tracy-debug';
public const COOKIE_SECRET = 'tracy-debug';

/** @var bool in production mode is suppressed any debugging output */
public static $productionMode = self::DETECT;
Expand Down Expand Up @@ -80,7 +80,7 @@ class Debugger
public static $email;

/** for Debugger::log() and Debugger::fireLog() */
const
public const
DEBUG = ILogger::DEBUG,
INFO = ILogger::INFO,
WARNING = ILogger::WARNING,
Expand Down Expand Up @@ -153,7 +153,7 @@ public static function enable($mode = null, $logDirectory = null, $email = null)

self::$maxLen = &self::$maxLength;
self::$reserved = str_repeat('t', 30000);
self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
self::$time = $_SERVER['REQUEST_TIME_FLOAT'] ?? microtime(true);
self::$obLevel = ob_get_level();
self::$cpuUsage = !self::$productionMode && function_exists('getrusage') ? getrusage() : null;

Expand Down Expand Up @@ -345,7 +345,7 @@ public static function exceptionHandler($exception, $exit = true)
try {
$e = null;
foreach (self::$onFatalError as $handler) {
call_user_func($handler, $exception);
$handler($exception);
}
} catch (\Throwable $e) {
try {
Expand Down Expand Up @@ -455,7 +455,7 @@ public static function getBlueScreen()
self::$blueScreen = new BlueScreen;
self::$blueScreen->info = [
'PHP ' . PHP_VERSION,
isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null,
$_SERVER['SERVER_SOFTWARE'] ?? null,
'Tracy ' . self::VERSION,
];
}
Expand Down Expand Up @@ -616,9 +616,7 @@ public static function fireLog($message)
*/
public static function detectDebugMode($list = null)
{
$addr = isset($_SERVER['REMOTE_ADDR'])
? $_SERVER['REMOTE_ADDR']
: php_uname('n');
$addr = $_SERVER['REMOTE_ADDR'] ?? php_uname('n');
$secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])
? $_COOKIE[self::COOKIE_SECRET]
: null;
Expand Down
12 changes: 6 additions & 6 deletions src/Tracy/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Dumper
{
const
public const
DEPTH = 'depth', // how many nested levels of array/object properties display (defaults to 4)
TRUNCATE = 'truncate', // how truncate long strings? (defaults to 150)
COLLAPSE = 'collapse', // collapse top array/object or how big are collapsed? (defaults to 14)
Expand All @@ -23,7 +23,7 @@ class Dumper
LIVE = 'live', // will be rendered using JavaScript
DEBUGINFO = 'debuginfo'; // use magic method __debugInfo if exists (defaults to false)

const
public const
LOCATION_SOURCE = 0b0001, // shows where dump was called
LOCATION_LINK = 0b0010, // appends clickable anchor
LOCATION_CLASS = 0b0100; // shows where class is defined
Expand Down Expand Up @@ -104,7 +104,7 @@ public static function toHtml($var, array $options = null)
});

$live = !empty($options[self::LIVE]) && $var && (is_array($var) || is_object($var) || is_resource($var));
list($file, $line, $code) = $loc ? self::findLocation() : null;
[$file, $line, $code] = $loc ? self::findLocation() : null;
$locAttrs = $file && $loc & self::LOCATION_SOURCE ? Helpers::formatHtml(
' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line, Helpers::editorUri($file, $line)
) : null;
Expand Down Expand Up @@ -292,7 +292,7 @@ private static function dumpResource(&$var, $options, $level)
. '<span class="tracy-dump-hash">#' . (int) $var . '</span>';
if (isset(self::$resources[$type])) {
$out = "<span class=\"tracy-toggle tracy-collapsed\">$out</span>\n<div class=\"tracy-collapsed\">";
foreach (call_user_func(self::$resources[$type], $var) as $k => $v) {
foreach ((self::$resources[$type])($var) as $k => $v) {
$out .= '<span class="tracy-dump-indent"> ' . str_repeat('| ', $level) . '</span>'
. '<span class="tracy-dump-key">' . Helpers::escapeHtml($k) . '</span> => ' . self::dumpVar($v, $options, $level + 1);
}
Expand Down Expand Up @@ -380,7 +380,7 @@ private static function toJson(&$var, $options, $level = 0)
$type = get_resource_type($var);
$obj = ['id' => self::$livePrefix . (int) $var, 'name' => $type . ' resource'];
if (isset(self::$resources[$type])) {
foreach (call_user_func(self::$resources[$type], $var) as $k => $v) {
foreach ((self::$resources[$type])($var) as $k => $v) {
$obj['items'][] = [$k, self::toJson($v, $options, $level + 1)];
}
}
Expand Down Expand Up @@ -460,7 +460,7 @@ private static function exportObject($obj, array $exporters, $useDebugInfo)
{
foreach ($exporters as $type => $dumper) {
if (!$type || $obj instanceof $type) {
return call_user_func($dumper, $obj);
return $dumper($obj);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function fixStack($exception)
$frame = [
'file' => $row['file'],
'line' => $row['line'],
'function' => isset($row['function']) ? $row['function'] : '*unknown*',
'function' => $row['function'] ?? '*unknown*',
'args' => [],
];
if (!empty($row['class'])) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public static function errorTypeToString($type)
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated',
];
return isset($types[$type]) ? $types[$type] : 'Unknown error';
return $types[$type] ?? 'Unknown error';
}


Expand All @@ -163,7 +163,7 @@ public static function getSource()
{
if (isset($_SERVER['REQUEST_URI'])) {
return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
. (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
. ($_SERVER['HTTP_HOST'] ?? '')
. $_SERVER['REQUEST_URI'];
} else {
return 'CLI (PID: ' . getmypid() . ')'
Expand Down
4 changes: 2 additions & 2 deletions src/Tracy/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function sendEmail($message)
&& @filemtime($this->directory . '/email-sent') + $snooze < time() // @ file may not exist
&& @file_put_contents($this->directory . '/email-sent', 'sent') // @ file may not be writable
) {
call_user_func($this->mailer, $message, implode(', ', (array) $this->email));
($this->mailer)($message, implode(', ', (array) $this->email));
}
}

Expand All @@ -188,7 +188,7 @@ protected function sendEmail($message)
*/
public function defaultMailer($message, $email)
{
$host = preg_replace('#[^\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
$host = preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n'));
$parts = str_replace(
["\r\n", "\n"],
["\n", PHP_EOL],
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/OutputDebugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class OutputDebugger
{
const BOM = "\xEF\xBB\xBF";
private const BOM = "\xEF\xBB\xBF";

/** @var array of [file, line, output, stack] */
private $list = [];
Expand Down
12 changes: 6 additions & 6 deletions src/Tracy/assets/Bar/info.panel.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ $info = [
'OPcache' => $opcache ? round(count($cachedFiles) * 100 / count(get_included_files())) . '% cached' : null,
'Classes + interfaces + traits' => $countClasses(get_declared_classes()) . ' + '
. $countClasses(get_declared_interfaces()) . ' + ' . $countClasses(get_declared_traits()),
'Your IP' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null,
'Server IP' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null,
'Your IP' => $_SERVER['REMOTE_ADDR'] ?? null,
'Server IP' => $_SERVER['SERVER_ADDR'] ?? null,
'HTTP method / response code' => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] . ' / ' . http_response_code() : null,
'PHP' => PHP_VERSION,
'Xdebug' => extension_loaded('xdebug') ? phpversion('xdebug') : null,
'Tracy' => Debugger::VERSION,
'Server' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null,
'Server' => $_SERVER['SERVER_SOFTWARE'] ?? null,
];

$info = array_map('strval', array_filter($info + (array) $this->data));
Expand All @@ -51,10 +51,10 @@ if (class_exists('Composer\Autoload\ClassLoader', false)) {
$composer = @json_decode(file_get_contents($lockFile)); // @ may not exist or be valid
list($packages, $devPackages) = [(array) @$composer->packages, (array) @$composer->{'packages-dev'}]; // @ keys may not exist
foreach ([&$packages, &$devPackages] as &$items) {
@array_walk($items, function($package) { // @ keys may not exist
$package->hash = $package->source->reference ?: $package->dist->reference;
array_walk($items, function($package) {
$package->hash = $package->source->reference ?? $package->dist->reference ?? null;
}, $items);
usort($items, function ($a, $b) { return strcmp($a->name, $b->name); });
usort($items, function ($a, $b) { return $a->name <=> $b->name; });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/shortcuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function dumpe($var)
*/
function bdump($var)
{
call_user_func_array('Tracy\Debugger::barDump', func_get_args());
Tracy\Debugger::barDump(...func_get_args());
return $var;
}
}

0 comments on commit 17d2eae

Please sign in to comment.