Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP code style updated to 7.1 #577

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions demo/bridge/doctrine/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
$config = Setup::createAnnotationMetadataConfiguration([__DIR__."/src"], $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);

// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
$conn = ['driver' => 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite'];

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
4 changes: 2 additions & 2 deletions demo/bridge/doctrine/cli-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once "bootstrap.php";

$em = $entityManager;
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
$helperSet = new \Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
]);
4 changes: 2 additions & 2 deletions demo/bridge/swiftmailer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
$debugbar->addCollector(new SwiftMailCollector($mailer));

$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('[email protected]' => 'John Doe'))
->setTo(array('[email protected]', '[email protected]' => 'A name'))
->setFrom(['[email protected]' => 'John Doe'])
->setTo(['[email protected]', '[email protected]' => 'A name'])
->setBody('Here is the message itself');

$mailer->send($message);
Expand Down
2 changes: 1 addition & 1 deletion demo/bridge/twig/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
$debugbar->addCollector(new DebugBar\Bridge\TwigProfileCollector($profile));

render_demo_page(function() use ($twig) {
echo $twig->render('hello.html', array('name' => 'peter pan'));
echo $twig->render('hello.html', ['name' => 'peter pan']);
});
2 changes: 1 addition & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$debugbar['time']->stopMeasure('op2');

$debugbar['messages']->addMessage('world', 'warning');
$debugbar['messages']->addMessage(array('toto' => array('titi', 'tata')));
$debugbar['messages']->addMessage(['toto' => ['titi', 'tata']]);
$debugbar['messages']->addMessage('oups', 'error');

$debugbar['time']->startMeasure('render');
Expand Down
6 changes: 3 additions & 3 deletions demo/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

$pdo->exec('create table users (name varchar)');
$stmt = $pdo->prepare('insert into users (name) values (?)');
$stmt->execute(array('foo'));
$stmt->execute(array('bar'));
$stmt->execute(['foo']);
$stmt->execute(['bar']);

$users = $pdo->query('select * from users')->fetchAll();
$stmt = $pdo->prepare('select * from users where name=?');
$stmt->execute(array('foo'));
$stmt->execute(['foo']);
$foo = $stmt->fetch();

$pdo->exec('delete from users');
Expand Down
26 changes: 13 additions & 13 deletions src/DebugBar/Bridge/DoctrineCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ public function __construct($debugStackOrEntityManager)
*/
public function collect()
{
$queries = array();
$queries = [];
$totalExecTime = 0;
foreach ($this->debugStack->queries as $q) {
$queries[] = array(
$queries[] = [
'sql' => $q['sql'],
'params' => (object) $q['params'],
'duration' => $q['executionMS'],
'duration_str' => $this->formatDuration($q['executionMS'])
);
];
$totalExecTime += $q['executionMS'];
}

return array(
return [
'nb_statements' => count($queries),
'accumulated_duration' => $totalExecTime,
'accumulated_duration_str' => $this->formatDuration($totalExecTime),
'statements' => $queries
);
];
}

/**
Expand All @@ -88,28 +88,28 @@ public function getName()
*/
public function getWidgets()
{
return array(
"database" => array(
return [
"database" => [
"icon" => "arrow-right",
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
"map" => "doctrine",
"default" => "[]"
),
"database:badge" => array(
],
"database:badge" => [
"map" => "doctrine.nb_statements",
"default" => 0
)
);
]
];
}

/**
* @return array
*/
public function getAssets()
{
return array(
return [
'css' => 'widgets/sqlqueries/widget.css',
'js' => 'widgets/sqlqueries/widget.js'
);
];
}
}
22 changes: 11 additions & 11 deletions src/DebugBar/Bridge/MonologCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MonologCollector extends AbstractProcessingHandler implements DataCollecto
{
protected $name;

protected $records = array();
protected $records = [];

/**
* @param Logger $logger
Expand Down Expand Up @@ -61,12 +61,12 @@ public function addLogger(Logger $logger)
*/
protected function write($record): void
{
$this->records[] = array(
$this->records[] = [
'message' => $record['formatted'],
'is_string' => true,
'label' => strtolower($record['level_name']),
'time' => $record['datetime']->format('U')
);
];
}

/**
Expand All @@ -82,10 +82,10 @@ public function getMessages()
*/
public function collect()
{
return array(
return [
'count' => count($this->records),
'records' => $this->records
);
];
}

/**
Expand All @@ -102,17 +102,17 @@ public function getName()
public function getWidgets()
{
$name = $this->getName();
return array(
$name => array(
return [
$name => [
"icon" => "suitcase",
"widget" => "PhpDebugBar.Widgets.MessagesWidget",
"map" => "$name.records",
"default" => "[]"
),
"$name:badge" => array(
],
"$name:badge" => [
"map" => "$name.count",
"default" => "null"
)
);
]
];
}
}
58 changes: 29 additions & 29 deletions src/DebugBar/Bridge/Propel2Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class Propel2Collector extends DataCollector implements Renderable, AssetProvide
/**
* @var array
*/
protected $config = array();
protected $config = [];

/**
* @var array
*/
protected $errors = array();
protected $errors = [];

/**
* @var int
Expand All @@ -65,15 +65,15 @@ class Propel2Collector extends DataCollector implements Renderable, AssetProvide
*/
public function __construct(
ConnectionInterface $connection,
array $logMethods = array(
array $logMethods = [
'beginTransaction',
'commit',
'rollBack',
'forceRollBack',
'exec',
'query',
'execute'
)
]
) {
if ($connection instanceof ProfilerConnectionWrapper) {
$connection->setLogMethods($logMethods);
Expand Down Expand Up @@ -140,24 +140,24 @@ protected function getQueryCount()
*/
protected function getStatements($records, $config)
{
$statements = array();
$statements = [];
foreach ($records as $record) {
$duration = null;
$memory = null;

$isSuccess = ( LogLevel::INFO === strtolower($record['level_name']) );

$detailsCount = count($config['details']);
$detailsCount = is_array($config['details']) || $config['details'] instanceof \Countable ? count($config['details']) : 0;
$parameters = explode($config['outerGlue'], $record['message'], $detailsCount + 1);
if (count($parameters) === ($detailsCount + 1)) {
$parameters = array_map('trim', $parameters);
$_details = array();
$_details = [];
foreach (array_splice($parameters, 0, $detailsCount) as $string) {
list($key, $value) = array_map('trim', explode($config['innerGlue'], $string, 2));
[$key, $value] = array_map('trim', explode($config['innerGlue'], $string, 2));
$_details[$key] = $value;
}

$details = array();
$details = [];
foreach ($config['details'] as $key => $detail) {
if (isset($_details[$detail['name']])) {
$value = $_details[$detail['name']];
Expand All @@ -168,12 +168,12 @@ protected function getStatements($records, $config)
$value = (float)$value;
}
} else {
$suffixes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$suffixes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$suffix = substr($value, -2);
$i = array_search($suffix, $suffixes, true);
$i = (false === $i) ? 0 : $i;

$value = ((float)$value) * pow(1024, $i);
$value = ((float)$value) * 1024 ** $i;
}
$details[$key] = $value;
}
Expand All @@ -196,14 +196,14 @@ protected function getStatements($records, $config)
$message = $record['message'];
}

$statement = array(
$statement = [
'sql' => $message,
'is_success' => $isSuccess,
'duration' => $duration,
'duration_str' => $this->getDataFormatter()->formatDuration($duration),
'memory' => $memory,
'memory_str' => $this->getDataFormatter()->formatBytes($memory),
);
];

if (false === $isSuccess) {
$statement['sql'] = '';
Expand All @@ -222,17 +222,17 @@ protected function getStatements($records, $config)
public function collect()
{
if (count($this->errors)) {
return array(
return [
'statements' => array_map(function ($message) {
return array('sql' => '', 'is_success' => false, 'error_code' => 500, 'error_message' => $message);
return ['sql' => '', 'is_success' => false, 'error_code' => 500, 'error_message' => $message];
}, $this->errors),
'nb_statements' => 0,
'nb_failed_statements' => count($this->errors),
);
];
}

if ($this->getHandler() === null) {
return array();
return [];
}

$statements = $this->getStatements($this->getHandler()->getRecords(), $this->getConfig());
Expand All @@ -242,24 +242,24 @@ public function collect()
}));
$accumulatedDuration = array_reduce($statements, function ($accumulatedDuration, $statement) {

$time = isset($statement['duration']) ? $statement['duration'] : 0;
$time = $statement['duration'] ?? 0;
return $accumulatedDuration += $time;
});
$memoryUsage = array_reduce($statements, function ($memoryUsage, $statement) {

$time = isset($statement['memory']) ? $statement['memory'] : 0;
$time = $statement['memory'] ?? 0;
return $memoryUsage += $time;
});

return array(
return [
'nb_statements' => $this->getQueryCount(),
'nb_failed_statements' => $failedStatement,
'accumulated_duration' => $accumulatedDuration,
'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($accumulatedDuration),
'memory_usage' => $memoryUsage,
'memory_usage_str' => $this->getDataFormatter()->formatBytes($memoryUsage),
'statements' => $statements
);
];
}

/**
Expand All @@ -280,28 +280,28 @@ public function getName()
*/
public function getWidgets()
{
return array(
$this->getName() => array(
return [
$this->getName() => [
'icon' => 'bolt',
'widget' => 'PhpDebugBar.Widgets.SQLQueriesWidget',
'map' => $this->getName(),
'default' => '[]'
),
$this->getName().':badge' => array(
],
$this->getName().':badge' => [
'map' => $this->getName().'.nb_statements',
'default' => 0
),
);
]
];
}

/**
* @return array
*/
public function getAssets()
{
return array(
return [
'css' => 'widgets/sqlqueries/widget.css',
'js' => 'widgets/sqlqueries/widget.js'
);
];
}
}
Loading