Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 93b39a8

Browse files
committed
Short array syntax
1 parent 6c7c301 commit 93b39a8

6 files changed

Lines changed: 46 additions & 46 deletions

File tree

src/Command/Metrics/AllMetricsCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AllMetricsCommand extends MetricsCommandBase
1919
/**
2020
* @var array
2121
*/
22-
private static $tableHeader = array(
22+
private static $tableHeader = [
2323
'timestamp' => 'Timestamp',
2424
'service' => 'Service',
2525
'type' => 'Type',
@@ -47,12 +47,12 @@ class AllMetricsCommand extends MetricsCommandBase
4747
'tmp_inodes_used' => '/tmp inodes used',
4848
'tmp_inodes_limit' => '/tmp inodes limit',
4949
'tmp_inodes_percent' => '/tmp inodes %',
50-
);
50+
];
5151

5252
/**
5353
* @var array
5454
*/
55-
private $defaultColumns = array(
55+
private $defaultColumns = [
5656
'timestamp',
5757
'service',
5858

@@ -63,7 +63,7 @@ class AllMetricsCommand extends MetricsCommandBase
6363

6464
'tmp_disk_percent',
6565
'tmp_inodes_percent',
66-
);
66+
];
6767

6868

6969
/**
@@ -72,7 +72,7 @@ class AllMetricsCommand extends MetricsCommandBase
7272
protected function configure()
7373
{
7474
$this->setName('metrics:all')
75-
->setAliases(array('metrics', 'met'))
75+
->setAliases(['metrics', 'met'])
7676
->setDescription('Show CPU, disk and memory metrics for an environment')
7777
->addOption('bytes', 'B', InputOption::VALUE_NONE, 'Show sizes in bytes');
7878
$this->addExample('Show metrics for the last ' . (new Duration())->humanize(self::DEFAULT_RANGE));
@@ -90,19 +90,19 @@ protected function configure()
9090
*/
9191
protected function execute(InputInterface $input, OutputInterface $output)
9292
{
93-
$result = $this->processQuery($input, array(
93+
$result = $this->processQuery($input, [
9494
MetricKind::API_TYPE_CPU,
9595
MetricKind::API_TYPE_DISK,
9696
MetricKind::API_TYPE_MEMORY,
9797
MetricKind::API_TYPE_INODES,
98-
), array(MetricKind::API_AGG_AVG));
98+
], [MetricKind::API_AGG_AVG]);
9999

100100
$values = $result[0];
101101
$environment = $result[1];
102102

103103
$bytes = $input->getOption('bytes');
104104

105-
$rows = $this->buildRows($values, array(
105+
$rows = $this->buildRows($values, [
106106
'cpu_used' => new Field(
107107
Format::ROUNDED_2P,
108108
new SourceField(MetricKind::CPU_USED, Aggregation::AVG)
@@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199199
new SourceField(MetricKind::INODES_LIMIT, Aggregation::MAX, '/tmp')
200200
)
201201
),
202-
), $environment);
202+
], $environment);
203203

204204
/** @var \Platformsh\Cli\Service\Table $table */
205205
$table = $this->getService('table');

src/Command/Metrics/CpuCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ class CpuCommand extends MetricsCommandBase
1818
/**
1919
* @var array
2020
*/
21-
private static $tableHeader = array(
21+
private static $tableHeader = [
2222
'timestamp' => 'Timestamp',
2323
'service' => 'Service',
2424
'type' => 'Type',
2525
'used' => 'Used',
2626
'limit' => 'Limit',
2727
'percent' => 'Used %',
28-
);
28+
];
2929

3030
/**
3131
* @var array
3232
*/
33-
private $defaultColumns = array('timestamp', 'service', 'used', 'limit', 'percent');
33+
private $defaultColumns = ['timestamp', 'service', 'used', 'limit', 'percent'];
3434

3535
/**
3636
* {@inheritdoc}
3737
*/
3838
protected function configure()
3939
{
4040
$this->setName('metrics:cpu')
41-
->setAliases(array('cpu'))
41+
->setAliases(['cpu'])
4242
->setDescription('Show CPU usage of an environment');
4343
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
4444
Table::configureInput($this->getDefinition(), self::$tableHeader, $this->defaultColumns);
@@ -52,12 +52,12 @@ protected function configure()
5252
*/
5353
protected function execute(InputInterface $input, OutputInterface $output)
5454
{
55-
$result = $this->processQuery($input, array(MetricKind::API_TYPE_CPU), array(MetricKind::API_AGG_AVG));
55+
$result = $this->processQuery($input, [MetricKind::API_TYPE_CPU], [MetricKind::API_AGG_AVG]);
5656

5757
$values = $result[0];
5858
$environment = $result[1];
5959

60-
$rows = $this->buildRows($values, array(
60+
$rows = $this->buildRows($values, [
6161
'used' => new Field(
6262
Format::ROUNDED_2P,
6363
new SourceField(MetricKind::CPU_USED, Aggregation::AVG)
@@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
new SourceField(MetricKind::CPU_LIMIT, Aggregation::MAX)
7474
)
7575
),
76-
), $environment);
76+
], $environment);
7777

7878
/** @var \Platformsh\Cli\Service\Table $table */
7979
$table = $this->getService('table');

src/Command/Metrics/DiskUsageCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DiskUsageCommand extends MetricsCommandBase
1919
/**
2020
* @var array
2121
*/
22-
private static $tableHeader = array(
22+
private static $tableHeader = [
2323
'timestamp' => 'Timestamp',
2424
'service' => 'Service',
2525
'type' => 'Type',
@@ -35,25 +35,25 @@ class DiskUsageCommand extends MetricsCommandBase
3535
'tmp_iused' => '/tmp inodes used',
3636
'tmp_ilimit' => '/tmp inodes limit',
3737
'tmp_ipercent' => '/tmp inodes %',
38-
);
38+
];
3939

4040
/**
4141
* @var array
4242
*/
43-
private $defaultColumns = array('timestamp', 'service', 'used', 'limit', 'percent', 'ipercent', 'tmp_percent');
43+
private $defaultColumns = ['timestamp', 'service', 'used', 'limit', 'percent', 'ipercent', 'tmp_percent'];
4444

4545
/**
4646
* @var array
4747
*/
48-
private $tmpReportColumns = array('timestamp', 'service', 'tmp_used', 'tmp_limit', 'tmp_percent', 'tmp_ipercent');
48+
private $tmpReportColumns = ['timestamp', 'service', 'tmp_used', 'tmp_limit', 'tmp_percent', 'tmp_ipercent'];
4949

5050
/**
5151
* {@inheritdoc}
5252
*/
5353
protected function configure()
5454
{
5555
$this->setName('metrics:disk-usage')
56-
->setAliases(array('disk'))
56+
->setAliases(['disk'])
5757
->setDescription('Show disk usage of an environment')
5858
->addOption('bytes', 'B', InputOption::VALUE_NONE, 'Show sizes in bytes')
5959
->addOption('tmp', null, InputOption::VALUE_NONE, 'Report temporary disk usage (shows columns: ' . implode(', ', $this->tmpReportColumns) . ')');
@@ -73,14 +73,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
$input->setOption('columns', $this->tmpReportColumns);
7474
}
7575

76-
$result = $this->processQuery($input, array(MetricKind::API_TYPE_DISK, MetricKind::API_TYPE_INODES), array(MetricKind::API_AGG_AVG));
76+
$result = $this->processQuery($input, [MetricKind::API_TYPE_DISK, MetricKind::API_TYPE_INODES], [MetricKind::API_AGG_AVG]);
7777

7878
$values = $result[0];
7979
$environment = $result[1];
8080

8181
$bytes = $input->getOption('bytes');
8282

83-
$rows = $this->buildRows($values, array(
83+
$rows = $this->buildRows($values, [
8484
'used' => new Field(
8585
$bytes ? Format::ROUNDED : Format::DISK,
8686
new SourceField(MetricKind::DISK_USED, Aggregation::AVG, '/mnt')
@@ -144,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144144
new SourceField(MetricKind::INODES_LIMIT, Aggregation::MAX, '/tmp')
145145
)
146146
),
147-
), $environment);
147+
], $environment);
148148

149149
/** @var \Platformsh\Cli\Service\Table $table */
150150
$table = $this->getService('table');

src/Command/Metrics/MemCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ class MemCommand extends MetricsCommandBase
1919
/**
2020
* @var array
2121
*/
22-
private static $tableHeader = array(
22+
private static $tableHeader = [
2323
'timestamp' => 'Timestamp',
2424
'service' => 'Service',
2525
'type' => 'Type',
2626
'used' => 'Used',
2727
'limit' => 'Limit',
2828
'percent' => 'Used %',
29-
);
29+
];
3030

3131
/**
3232
* @var array
3333
*/
34-
private $defaultColumns = array('timestamp', 'service', 'used', 'limit', 'percent');
34+
private $defaultColumns = ['timestamp', 'service', 'used', 'limit', 'percent'];
3535

3636
/**
3737
* {@inheritdoc}
3838
*/
3939
protected function configure()
4040
{
4141
$this->setName('metrics:memory')
42-
->setAliases(array('mem', 'memory'))
42+
->setAliases(['mem', 'memory'])
4343
->setDescription('Show memory usage of an environment')
4444
->addOption('bytes', 'B', InputOption::VALUE_NONE, 'Show sizes in bytes');
4545
$this->addMetricsOptions()->addProjectOption()->addEnvironmentOption();
@@ -54,14 +54,14 @@ protected function configure()
5454
*/
5555
protected function execute(InputInterface $input, OutputInterface $output)
5656
{
57-
$result = $this->processQuery($input, array(MetricKind::API_TYPE_MEMORY), array(MetricKind::API_AGG_AVG));
57+
$result = $this->processQuery($input, [MetricKind::API_TYPE_MEMORY], [MetricKind::API_AGG_AVG]);
5858

5959
$values = $result[0];
6060
$environment = $result[1];
6161

6262
$bytes = $input->getOption('bytes');
6363

64-
$rows = $this->buildRows($values, array(
64+
$rows = $this->buildRows($values, [
6565
'used' => new Field(
6666
$bytes ? Format::ROUNDED : Format::MEMORY,
6767
new SourceField(MetricKind::MEMORY_USED, Aggregation::AVG)
@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
),
7979
false
8080
),
81-
), $environment);
81+
], $environment);
8282

8383
/** @var \Platformsh\Cli\Service\Table $table */
8484
$table = $this->getService('table');

src/Command/Metrics/MetricsCommandBase.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function processQuery(InputInterface $input, array $metricTypes, array
152152
if ($input->getOption('latest')) {
153153
foreach (array_reverse($items['data']) as $item) {
154154
if (isset($item['services'])) {
155-
$items['data'] = array($item);
155+
$items['data'] = [$item];
156156
break;
157157
}
158158
}
@@ -173,7 +173,7 @@ protected function processQuery(InputInterface $input, array $metricTypes, array
173173
throw new \RuntimeException('No data points were found in the metrics response.');
174174
}
175175

176-
return array($items, $environment);
176+
return [$items, $environment];
177177
}
178178

179179
/**
@@ -187,23 +187,23 @@ private function getServices(InputInterface $input, Environment $environment)
187187
$deployment = $this->api()->getCurrentDeployment($environment);
188188
$allServices = array_merge($deployment->webapps, $deployment->services, $deployment->workers);
189189
$servicesInput = ArrayArgument::getOption($input, 'service');
190-
$selectedServiceNames = array();
190+
$selectedServiceNames = [];
191191
if (!empty($servicesInput)) {
192-
$selectedServiceNames = Wildcard::select(array_merge(array_keys($allServices), array('router')), $servicesInput);
192+
$selectedServiceNames = Wildcard::select(array_merge(array_keys($allServices), ['router']), $servicesInput);
193193
if (!$selectedServiceNames) {
194194
$this->stdErr->writeln('No services were found matching the name(s): <error>' . implode(', ', $servicesInput) . '</error>');
195195

196196
throw new \RuntimeException('No services were found matching the name(s): ' . implode(', ', $servicesInput));
197197
}
198198
} elseif ($typeInput = ArrayArgument::getOption($input, 'type')) {
199-
$byType = array();
199+
$byType = [];
200200
foreach ($allServices as $name => $service) {
201201
$type = $service->type;
202202
list($prefix) = explode(':', $service->type, 2);
203203
$byType[$type][] = $name;
204204
$byType[$prefix][] = $name;
205205
}
206-
$selectedKeys = Wildcard::select(array_merge(array_keys($byType), array('router')), $typeInput);
206+
$selectedKeys = Wildcard::select(array_merge(array_keys($byType), ['router']), $typeInput);
207207
if (!$selectedKeys) {
208208
$this->stdErr->writeln('No services were found matching the type(s): <error>' . implode(', ', $typeInput) . '</error>');
209209

@@ -276,9 +276,9 @@ protected function buildRows(array $values, array $fieldMapping, Environment $en
276276
/** @var \Platformsh\Cli\Service\PropertyFormatter $formatter */
277277
$formatter = $this->getService('property_formatter');
278278
$sortServices = $this->getSortedServices($environment);
279-
$serviceTypes = array();
279+
$serviceTypes = [];
280280

281-
$rows = array();
281+
$rows = [];
282282
$lastCountPerTimestamp = 0;
283283
foreach ($values['data'] as $point) {
284284
$timestamp = $point['timestamp'];
@@ -301,8 +301,8 @@ protected function buildRows(array $values, array $fieldMapping, Environment $en
301301
$serviceTypes[$service] = $this->getServiceType($environment, $service);
302302
}
303303

304-
$row = array();
305-
$row['timestamp'] = new AdaptiveTableCell($formattedTimestamp, array('wrap' => false));
304+
$row = [];
305+
$row['timestamp'] = new AdaptiveTableCell($formattedTimestamp, ['wrap' => false]);
306306
$row['service'] = $service;
307307
$row['type'] = $formatter->format($serviceTypes[$service], 'service_type');
308308
foreach ($fieldMapping as $field => $fieldDefinition) {
@@ -356,7 +356,7 @@ private function getSortedServices(Environment $environment)
356356
sort($appAndWorkerNames, SORT_NATURAL);
357357
$serviceNames = array_keys($deployment->services);
358358
sort($serviceNames, SORT_NATURAL);
359-
$nameOrder = array_flip(array_merge($appAndWorkerNames, $serviceNames, array('router')));
359+
$nameOrder = array_flip(array_merge($appAndWorkerNames, $serviceNames, ['router']));
360360
$sortServices = function ($a, $b) use ($nameOrder) {
361361
$aPos = isset($nameOrder[$a]) ? $nameOrder[$a] : 1000;
362362
$bPos = isset($nameOrder[$b]) ? $nameOrder[$b] : 1000;

src/Model/Metrics/Query.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class Query
1010
/** @var array|null */
1111
private $services = null;
1212
/** @var array */
13-
private $types = array();
13+
private $types = [];
1414
/** @var array */
15-
private $aggs = array();
15+
private $aggs = [];
1616
/** @var int */
1717
private $startTime;
1818
/** @var int */
@@ -75,10 +75,10 @@ public function setAggs($aggs)
7575
*/
7676
public function asArray()
7777
{
78-
$query = array(
78+
$query = [
7979
'from' => $this->startTime,
8080
'to' => $this->endTime,
81-
);
81+
];
8282

8383
if (!empty($this->services)) {
8484
$query['services_mode'] = '1';

0 commit comments

Comments
 (0)