Skip to content

Commit 07c18b8

Browse files
authored
Merge pull request #27 from redthor/v2/array-bracket-syntax
V2/array bracket syntax
2 parents 9761259 + 38d3a1e commit 07c18b8

32 files changed

+251
-241
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
66
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
77
composer.lock
8+
.php_cs.cache

.php_cs.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
;
6+
7+
$config = PhpCsFixer\Config::create()
8+
->setRules([
9+
'@PSR2' => true,
10+
'@Symfony' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'concat_space' => ['spacing' => 'one'],
13+
])
14+
->setFinder($finder)
15+
;
16+
17+
return $config;

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ cache:
77

88
matrix:
99
include:
10-
# Test the latest
10+
# Test the latest dependencies
1111
- php: 7.1
1212
- php: 7.2
1313

14-
# Test with the lowest deps
14+
# Test with the lowest dependencies
1515
- php: 7.2
1616
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest --prefer-dist"
1717

@@ -22,7 +22,7 @@ before_script:
2222
- composer config "platform.ext-mongo" "1.6.16"
2323
- composer self-update
2424
# To be removed when this issue is resolved: https://github.com/composer/composer/issues/5355
25-
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --ignore-platform-reqs --quiet; fi
25+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
2626
- composer update -v ${COMPOSER_FLAGS}
2727

2828
script:

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ Example Connection configuration "test\_antimattr\_mongodb.php"
4141
/**
4242
* @link http://php.net/manual/en/mongoclient.construct.php
4343
*/
44-
return array(
44+
return [
4545
'host' => 'localhost', // default is localhost
4646
'port' => '27017', // default is 27017
4747
'dbname' => null, // optional, if authentication DB is required
4848
'user' => null, // optional, if authentication is required
4949
'password' => null, // optional, if authentication is required
50-
'options' => array(
50+
'options' => [
5151
'connect' => true // recommended
52-
)
53-
);
52+
]
53+
];
5454
```
5555

5656
XML or YAML Migration Configurations are supported
@@ -103,13 +103,13 @@ use AntiMattr\MongoDB\Migrations\Tools\Console\Command as AntiMattr;
103103
use Symfony\Component\Console\Application;
104104

105105
$application = new Application();
106-
$application->addCommands(array(
106+
$application->addCommands([
107107
new AntiMattr\ExecuteCommand(),
108108
new AntiMattr\GenerateCommand(),
109109
new AntiMattr\MigrateCommand(),
110110
new AntiMattr\StatusCommand(),
111111
new AntiMattr\VersionCommand()
112-
));
112+
]);
113113
$application->run();
114114
```
115115

@@ -343,8 +343,3 @@ Don't have the pre-commit hook running, please make sure to run the fixer/sniffe
343343
$ vendor/bin/php-cs-fixer fix src/
344344
$ vendor/bin/php-cs-fixer fix tests/
345345
```
346-
347-
PHP 7
348-
-----
349-
Please run before:
350-
composer require alcaeus/mongo-php-adapter

demo/ConsoleApplication/Example/Migrations/TestAntiMattr/MongoDB/Version20140822185742.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,26 @@ public function up(Database $db)
2020
$testA = $db->selectCollection('test_a');
2121
$this->analyze($testA);
2222

23-
$testA->ensureIndex(array('actor' => -1));
23+
$testA->ensureIndex(['actor' => -1]);
2424
}
2525

2626
public function down(Database $db)
2727
{
2828
// this down() migration is auto-generated, please modify it to your needs
29-
3029
}
3130

3231
/**
33-
* This preUp is not required
34-
* I use it to demonstrate the analyzer
35-
*/
32+
* This preUp is not required
33+
* I use it to demonstrate the analyzer.
34+
*/
3635
public function preUp(Database $db)
3736
{
3837
$testA = $db->selectCollection('test_a');
3938

40-
$testDocuments = array();
39+
$testDocuments = [];
4140

42-
for ($i = 0; $i < 100; $i++) {
43-
$testDocument = array();
41+
for ($i = 0; $i < 100; ++$i) {
42+
$testDocument = [];
4443
$testDocument['iteration'] = $i;
4544
$testDocument['actor'] = $this->generateRandomString();
4645
$testDocument['object'] = $this->generateRandomString();
@@ -53,9 +52,9 @@ public function preUp(Database $db)
5352
}
5453

5554
/**
56-
* This postUp is not required
57-
* I use it to demonstrate the analyzer
58-
*/
55+
* This postUp is not required
56+
* I use it to demonstrate the analyzer.
57+
*/
5958
public function postUp(Database $db)
6059
{
6160
$testA = $db->selectCollection('test_a');
@@ -67,7 +66,7 @@ private function generateRandomString()
6766
$length = rand(10, 50);
6867
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
6968
$randomString = '';
70-
for ($i = 0; $i < $length; $i++) {
69+
for ($i = 0; $i < $length; ++$i) {
7170
$randomString .= $characters[rand(0, strlen($characters) - 1)];
7271
}
7372

demo/ConsoleApplication/Example/Migrations/TestAntiMattr/MongoDB/Version20140822185743.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@ public function up(Database $db)
2727
public function down(Database $db)
2828
{
2929
// this down() migration is auto-generated, please modify it to your needs
30-
3130
}
3231

3332
/**
3433
* This preUp is not required
35-
* I use it to demonstrate the analyzer
34+
* I use it to demonstrate the analyzer.
3635
*/
3736
public function preUp(Database $db)
3837
{
3938
$testA = $db->selectCollection('test_a');
4039

41-
$testDocuments = array();
40+
$testDocuments = [];
4241

43-
for ($i = 0; $i < 100; $i++) {
44-
$testDocument = array();
42+
for ($i = 0; $i < 100; ++$i) {
43+
$testDocument = [];
4544
$testDocument['iteration'] = $i;
4645
$testDocument['actor'] = $this->generateRandomString();
4746
$testDocument['object'] = $this->generateRandomString();
@@ -55,7 +54,7 @@ public function preUp(Database $db)
5554

5655
/**
5756
* This postUp is not required
58-
* I use it to demonstrate the analyzer
57+
* I use it to demonstrate the analyzer.
5958
*/
6059
public function postUp(Database $db)
6160
{
@@ -68,7 +67,7 @@ private function generateRandomString()
6867
$length = rand(10, 50);
6968
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
7069
$randomString = '';
71-
for ($i = 0; $i < $length; $i++) {
70+
for ($i = 0; $i < $length; ++$i) {
7271
$randomString .= $characters[rand(0, strlen($characters) - 1)];
7372
}
7473

demo/ConsoleApplication/Example/Migrations/TestAntiMattr/MongoDB/Version20140822185744.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ public function getDescription()
2121
public function up(Database $db)
2222
{
2323
// this up() migration is auto-generated, please modify it to your needs
24-
2524
}
2625

2726
public function down(Database $db)
2827
{
2928
// this down() migration is auto-generated, please modify it to your needs
30-
3129
}
3230
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

33
/**
4-
* @link http://php.net/manual/en/mongoclient.construct.php
4+
* @see http://php.net/manual/en/mongoclient.construct.php
55
*/
6-
return array(
6+
return [
77
'host' => 'localhost', // default is localhost
88
'port' => '27017', // default is 27017
99
'dbname' => null, // optional, if authentication DB is required
1010
'user' => null, // optional, if authentication is required
1111
'password' => null, // optional, if authentication is required
12-
'options' => array(
13-
'connect' => true // recommended
14-
)
15-
);
12+
'options' => [
13+
'connect' => true, // recommended
14+
],
15+
];

src/AntiMattr/MongoDB/Migrations/AbstractMigration.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace AntiMattr\MongoDB\Migrations;
1313

14-
use AntiMattr\MongoDB\Migrations\Configuration\Configuration;
1514
use AntiMattr\MongoDB\Migrations\Exception\AbortException;
1615
use AntiMattr\MongoDB\Migrations\Exception\IrreversibleException;
1716
use AntiMattr\MongoDB\Migrations\Exception\SkipException;
@@ -65,7 +64,9 @@ public function __construct(Version $version)
6564
* @return string
6665
*/
6766
abstract public function getDescription();
67+
6868
abstract public function up(Database $db);
69+
6970
abstract public function down(Database $db);
7071

7172
/**
@@ -100,7 +101,7 @@ protected function write($message)
100101
*/
101102
protected function throwIrreversibleMigrationException($message = null)
102103
{
103-
if ($message === null) {
104+
if (null === $message) {
104105
$message = 'This migration is irreversible and cannot be reverted.';
105106
}
106107
throw new IrreversibleException($message);
@@ -116,8 +117,8 @@ public function warnIf($condition, $message = '')
116117
{
117118
$message = (strlen($message)) ? $message : 'Unknown Reason';
118119

119-
if ($condition === true) {
120-
$this->outputWriter->write(' <warning>Warning during '.$this->version->getExecutionState().': '.$message.'</warning>');
120+
if (true === $condition) {
121+
$this->outputWriter->write(' <warning>Warning during ' . $this->version->getExecutionState() . ': ' . $message . '</warning>');
121122
}
122123
}
123124

@@ -133,7 +134,7 @@ public function abortIf($condition, $message = '')
133134
{
134135
$message = (strlen($message)) ? $message : 'Unknown Reason';
135136

136-
if ($condition === true) {
137+
if (true === $condition) {
137138
throw new AbortException($message);
138139
}
139140
}
@@ -150,7 +151,7 @@ public function skipIf($condition, $message = '')
150151
{
151152
$message = (strlen($message)) ? $message : 'Unknown Reason';
152153

153-
if ($condition === true) {
154+
if (true === $condition) {
154155
throw new SkipException($message);
155156
}
156157
}

src/AntiMattr/MongoDB/Migrations/Collection/Statistics.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Statistics
2929
const PADDING_FACTOR = 'paddingFactor';
3030
const TOTAL_INDEX_SIZE = 'totalIndexSize';
3131

32-
public static $metrics = array(
32+
public static $metrics = [
3333
self::COUNT,
3434
self::SIZE,
3535
self::AVG_OBJ_SIZE,
@@ -39,7 +39,7 @@ class Statistics
3939
self::LAST_EXTENT_SIZE,
4040
self::PADDING_FACTOR,
4141
self::TOTAL_INDEX_SIZE,
42-
);
42+
];
4343

4444
/**
4545
* @var Doctrine\MongoDB\Collection
@@ -49,12 +49,12 @@ class Statistics
4949
/**
5050
* @var array
5151
*/
52-
private $before = array();
52+
private $before = [];
5353

5454
/**
5555
* @var array
5656
*/
57-
private $after = array();
57+
private $after = [];
5858

5959
/**
6060
* @param Doctrine\MongoDB\Collection
@@ -119,7 +119,7 @@ protected function getCollectionStats()
119119
$name = $this->collection->getName();
120120

121121
try {
122-
if (!$data = $database->command(array('collStats' => $name))) {
122+
if (!$data = $database->command(['collStats' => $name])) {
123123
$message = sprintf(
124124
'Statistics not found for collection %s',
125125
$name
@@ -135,6 +135,6 @@ protected function getCollectionStats()
135135
throw $e;
136136
}
137137

138-
return array();
138+
return [];
139139
}
140140
}

0 commit comments

Comments
 (0)