Skip to content

Commit 78f60f9

Browse files
Use short array syntax (#141)
1 parent d633143 commit 78f60f9

29 files changed

+135
-135
lines changed

src/Gitonomy/Git/Admin.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class Admin
3333
*
3434
* @return Repository
3535
*/
36-
public static function init($path, $bare = true, array $options = array())
36+
public static function init($path, $bare = true, array $options = [])
3737
{
38-
$process = static::getProcess('init', array_merge(array('-q'), $bare ? array('--bare') : array(), array($path)), $options);
38+
$process = static::getProcess('init', array_merge(['-q'], $bare ? ['--bare'] : [], [$path]), $options);
3939

4040
$process->run();
4141

@@ -58,9 +58,9 @@ public static function init($path, $bare = true, array $options = array())
5858
*
5959
* @return bool true if url is valid
6060
*/
61-
public static function isValidRepository($url, array $options = array())
61+
public static function isValidRepository($url, array $options = [])
6262
{
63-
$process = static::getProcess('ls-remote', array($url), $options);
63+
$process = static::getProcess('ls-remote', [$url], $options);
6464

6565
$process->run();
6666

@@ -77,9 +77,9 @@ public static function isValidRepository($url, array $options = array())
7777
*
7878
* @return Repository
7979
*/
80-
public static function cloneTo($path, $url, $bare = true, array $options = array())
80+
public static function cloneTo($path, $url, $bare = true, array $options = [])
8181
{
82-
$args = $bare ? array('--bare') : array();
82+
$args = $bare ? ['--bare'] : [];
8383

8484
return static::cloneRepository($path, $url, $args, $options);
8585
}
@@ -95,9 +95,9 @@ public static function cloneTo($path, $url, $bare = true, array $options = array
9595
*
9696
* @return Repository
9797
*/
98-
public static function cloneBranchTo($path, $url, $branch, $bare = true, $options = array())
98+
public static function cloneBranchTo($path, $url, $branch, $bare = true, $options = [])
9999
{
100-
$args = array('--branch', $branch);
100+
$args = ['--branch', $branch];
101101
if ($bare) {
102102
$args[] = '--bare';
103103
}
@@ -114,9 +114,9 @@ public static function cloneBranchTo($path, $url, $branch, $bare = true, $option
114114
*
115115
* @return Repository
116116
*/
117-
public static function mirrorTo($path, $url, array $options = array())
117+
public static function mirrorTo($path, $url, array $options = [])
118118
{
119-
return static::cloneRepository($path, $url, array('--mirror'), $options);
119+
return static::cloneRepository($path, $url, ['--mirror'], $options);
120120
}
121121

122122
/**
@@ -129,9 +129,9 @@ public static function mirrorTo($path, $url, array $options = array())
129129
*
130130
* @return Repository
131131
*/
132-
public static function cloneRepository($path, $url, array $args = array(), array $options = array())
132+
public static function cloneRepository($path, $url, array $args = [], array $options = [])
133133
{
134-
$process = static::getProcess('clone', array_merge(array('-q'), $args, array($url, $path)), $options);
134+
$process = static::getProcess('clone', array_merge(['-q'], $args, [$url, $path]), $options);
135135

136136
$process->run();
137137

@@ -145,16 +145,16 @@ public static function cloneRepository($path, $url, array $args = array(), array
145145
/**
146146
* This internal method is used to create a process object.
147147
*/
148-
private static function getProcess($command, array $args = array(), array $options = array())
148+
private static function getProcess($command, array $args = [], array $options = [])
149149
{
150150
$is_windows = defined('PHP_WINDOWS_VERSION_BUILD');
151-
$options = array_merge(array(
152-
'environment_variables' => $is_windows ? array('PATH' => getenv('PATH')) : array(),
151+
$options = array_merge([
152+
'environment_variables' => $is_windows ? ['PATH' => getenv('PATH')] : [],
153153
'command' => 'git',
154154
'process_timeout' => 3600,
155-
), $options);
155+
], $options);
156156

157-
$commandline = array_merge(array($options['command'], $command), $args);
157+
$commandline = array_merge([$options['command'], $command], $args);
158158

159159
// Backward compatible layer for Symfony Process < 4.0.
160160
if (class_exists('Symfony\Component\Process\ProcessBuilder')) {

src/Gitonomy/Git/Blame.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,24 @@ public function getLine($number)
8484
*/
8585
public function getGroupedLines()
8686
{
87-
$result = array();
87+
$result = [];
8888
$commit = null;
89-
$current = array();
89+
$current = [];
9090

9191
foreach ($this->getLines() as $lineNumber => $line) {
9292
if ($commit !== $line->getCommit()) {
9393
if (count($current)) {
94-
$result[] = array($commit, $current);
94+
$result[] = [$commit, $current];
9595
}
9696
$commit = $line->getCommit();
97-
$current = array();
97+
$current = [];
9898
}
9999

100100
$current[$lineNumber] = $line;
101101
}
102102

103103
if (count($current)) {
104-
$result[] = array($commit, $current);
104+
$result[] = [$commit, $current];
105105
}
106106

107107
return $result;
@@ -118,7 +118,7 @@ public function getLines()
118118
return $this->lines;
119119
}
120120

121-
$args = array('-p');
121+
$args = ['-p'];
122122

123123
if (null !== $this->lineRange) {
124124
$args[] = '-L';

src/Gitonomy/Git/Blob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getHash()
6565
public function getContent()
6666
{
6767
if (null === $this->content) {
68-
$this->content = $this->repository->run('cat-file', array('-p', $this->hash));
68+
$this->content = $this->repository->run('cat-file', ['-p', $this->hash]);
6969
}
7070

7171
return $this->content;

src/Gitonomy/Git/Commit.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class Commit extends Revision
3030
*
3131
* @var array
3232
*/
33-
private $data = array();
33+
private $data = [];
3434

3535
/**
3636
* Constructor.
3737
*
3838
* @param Gitonomy\Git\Repository $repository Repository of the commit
3939
* @param string $hash Hash of the commit
4040
*/
41-
public function __construct(Repository $repository, $hash, array $data = array())
41+
public function __construct(Repository $repository, $hash, array $data = [])
4242
{
4343
if (!preg_match('/^[a-f0-9]{40}$/', $hash)) {
4444
throw new ReferenceNotFoundException($hash);
@@ -61,7 +61,7 @@ public function setData(array $data)
6161
*/
6262
public function getDiff()
6363
{
64-
$args = array('-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision);
64+
$args = ['-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision];
6565

6666
$diff = Diff::parse($this->repository->run('diff-tree', $args));
6767
$diff->setRepository($this->repository);
@@ -114,7 +114,7 @@ public function getParentHashes()
114114
*/
115115
public function getParents()
116116
{
117-
$result = array();
117+
$result = [];
118118
foreach ($this->getData('parentHashes') as $parentHash) {
119119
$result[] = $this->repository->getCommit($parentHash);
120120
}
@@ -150,7 +150,7 @@ public function getLastModification($path = null)
150150
$path = $getWorkingDir.'/'.$path;
151151
}
152152

153-
$result = $this->repository->run('log', array('--format=%H', '-n', 1, $this->revision, '--', $path));
153+
$result = $this->repository->run('log', ['--format=%H', '-n', 1, $this->revision, '--', $path]);
154154

155155
return $this->repository->getCommit(trim($result));
156156
}
@@ -201,7 +201,7 @@ public function resolveReferences()
201201
*/
202202
public function getIncludingBranches($local = true, $remote = true)
203203
{
204-
$arguments = array('--contains', $this->revision);
204+
$arguments = ['--contains', $this->revision];
205205

206206
if ($local && $remote) {
207207
$arguments[] = '-a';
@@ -214,11 +214,11 @@ public function getIncludingBranches($local = true, $remote = true)
214214
try {
215215
$result = $this->repository->run('branch', $arguments);
216216
} catch (ProcessException $e) {
217-
return array();
217+
return [];
218218
}
219219

220220
if (!$result) {
221-
return array();
221+
return [];
222222
}
223223

224224
$branchesName = explode("\n", trim(str_replace('*', '', $result)));
@@ -229,7 +229,7 @@ public function getIncludingBranches($local = true, $remote = true)
229229

230230
$references = $this->repository->getReferences();
231231

232-
$branches = array();
232+
$branches = [];
233233
foreach ($branchesName as $branchName) {
234234
if (false === $local) {
235235
$branches[] = $references->getRemoteBranch($branchName);
@@ -348,7 +348,7 @@ private function getData($name)
348348
}
349349

350350
if ($name === 'shortHash') {
351-
$this->data['shortHash'] = trim($this->repository->run('log', array('--abbrev-commit', '--format=%h', '-n', 1, $this->revision)));
351+
$this->data['shortHash'] = trim($this->repository->run('log', ['--abbrev-commit', '--format=%h', '-n', 1, $this->revision]));
352352

353353
return $this->data['shortHash'];
354354
}
@@ -382,7 +382,7 @@ private function getData($name)
382382
$parser = new Parser\CommitParser();
383383

384384
try {
385-
$result = $this->repository->run('cat-file', array('commit', $this->revision));
385+
$result = $this->repository->run('cat-file', ['commit', $this->revision]);
386386
} catch (ProcessException $e) {
387387
throw new ReferenceNotFoundException(sprintf('Can not find reference "%s"', $this->revision));
388388
}

src/Gitonomy/Git/Diff/Diff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public function getRawDiff()
9797
*/
9898
public function toArray()
9999
{
100-
return array(
100+
return [
101101
'rawDiff' => $this->rawDiff,
102102
'files' => array_map(
103103
function (File $file) {
104104
return $file->toArray();
105105
},
106106
$this->files
107107
),
108-
);
108+
];
109109
}
110110

111111
/**

src/Gitonomy/Git/Diff/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $
7777
$this->newIndex = $newIndex;
7878
$this->isBinary = $isBinary;
7979

80-
$this->changes = array();
80+
$this->changes = [];
8181
}
8282

8383
public function addChange(FileChange $change)
@@ -222,7 +222,7 @@ public function getChanges()
222222

223223
public function toArray()
224224
{
225-
return array(
225+
return [
226226
'old_name' => $this->oldName,
227227
'new_name' => $this->newName,
228228
'old_mode' => $this->oldMode,
@@ -233,7 +233,7 @@ public function toArray()
233233
'changes' => array_map(function (FileChange $change) {
234234
return $change->toArray();
235235
}, $this->changes),
236-
);
236+
];
237237
}
238238

239239
public static function fromArray(array $array)

src/Gitonomy/Git/Diff/FileChange.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public function getLines()
7272

7373
public function toArray()
7474
{
75-
return array(
75+
return [
7676
'range_old_start' => $this->rangeOldStart,
7777
'range_old_count' => $this->rangeOldCount,
7878
'range_new_start' => $this->rangeNewStart,
7979
'range_new_count' => $this->rangeNewCount,
8080
'lines' => $this->lines,
81-
);
81+
];
8282
}
8383

8484
public static function fromArray(array $array)

src/Gitonomy/Git/Log.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function __construct(Repository $repository, $revisions = null, $paths =
6262
}
6363

6464
if (null === $paths) {
65-
$paths = array();
65+
$paths = [];
6666
} elseif (is_string($paths)) {
67-
$paths = array($paths);
67+
$paths = [$paths];
6868
} elseif (!is_array($paths)) {
6969
throw new \InvalidArgumentException(sprintf('Expected a string or an array, got a "%s".', is_object($paths) ? get_class($paths) : gettype($paths)));
7070
}
@@ -155,7 +155,7 @@ public function getSingleCommit()
155155
*/
156156
public function getCommits()
157157
{
158-
$args = array('--encoding='.StringHelper::getEncoding(), '--format=raw');
158+
$args = ['--encoding='.StringHelper::getEncoding(), '--format=raw'];
159159

160160
if (null !== $this->offset) {
161161
$args[] = '--skip='.((int) $this->offset);
@@ -185,7 +185,7 @@ public function getCommits()
185185
$parser = new Parser\LogParser();
186186
$parser->parse($output);
187187

188-
$result = array();
188+
$result = [];
189189
foreach ($parser->log as $commitData) {
190190
$hash = $commitData['id'];
191191
unset($commitData['id']);
@@ -223,9 +223,9 @@ public function getIterator()
223223
public function countCommits()
224224
{
225225
if (null !== $this->revisions && count($this->revisions)) {
226-
$output = $this->repository->run('rev-list', array_merge(array('--count'), $this->revisions->getAsTextArray(), array('--'), $this->paths));
226+
$output = $this->repository->run('rev-list', array_merge(['--count'], $this->revisions->getAsTextArray(), ['--'], $this->paths));
227227
} else {
228-
$output = $this->repository->run('rev-list', array_merge(array('--count', '--all', '--'), $this->paths));
228+
$output = $this->repository->run('rev-list', array_merge(['--count', '--all', '--'], $this->paths));
229229
}
230230

231231
return (int) $output;

src/Gitonomy/Git/Parser/BlameParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct(Repository $repository)
2828

2929
protected function doParse()
3030
{
31-
$this->lines = array();
31+
$this->lines = [];
3232

33-
$memory = array();
33+
$memory = [];
3434

3535
$line = 1;
3636
while (!$this->isFinished()) {
@@ -44,9 +44,9 @@ protected function doParse()
4444
$this->consumeNewLine();
4545

4646
if (!isset($memory[$hash])) {
47-
foreach (array('author', 'author-mail', 'author-time', 'author-tz',
47+
foreach (['author', 'author-mail', 'author-time', 'author-tz',
4848
'committer', 'committer-mail', 'committer-time', 'committer-tz',
49-
'summary', ) as $key) {
49+
'summary', ] as $key) {
5050
$this->consume($key);
5151
$this->consumeTo("\n");
5252
$this->consumeNewLine();

src/Gitonomy/Git/Parser/CommitParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function doParse()
3232
$this->tree = $this->consumeHash();
3333
$this->consumeNewLine();
3434

35-
$this->parents = array();
35+
$this->parents = [];
3636
while ($this->expects('parent ')) {
3737
$this->parents[] = $this->consumeHash();
3838
$this->consumeNewLine();
@@ -64,7 +64,7 @@ protected function consumeNameEmailDate()
6464

6565
$this->cursor += strlen($vars[1]);
6666

67-
return array($vars[2], $vars[3], $vars[4]);
67+
return [$vars[2], $vars[3], $vars[4]];
6868
}
6969

7070
protected function parseDate($text)

0 commit comments

Comments
 (0)