Skip to content

Commit 285ebda

Browse files
committed
PSR-2 conversion
1 parent 2ae9c4d commit 285ebda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+472
-664
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ Note that we did not tell Eloquent which collection to use for the `User` model.
117117
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
118118

119119
class User extends Eloquent {
120-
121120
protected $collection = 'users_collection';
122121

123122
}
@@ -129,7 +128,6 @@ class User extends Eloquent {
129128
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
130129

131130
class MyModel extends Eloquent {
132-
133131
protected $connection = 'mongodb';
134132

135133
}
@@ -238,7 +236,6 @@ To solve this, you will need to check two things. First check if your model is e
238236
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
239237

240238
class User extends Eloquent {
241-
242239
protected $connection = 'mongodb';
243240

244241
}
@@ -533,7 +530,6 @@ Example:
533530
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
534531

535532
class User extends Eloquent {
536-
537533
protected $dates = array('birthday');
538534

539535
}
@@ -758,7 +754,6 @@ Example SQL-based User model:
758754
use Jenssegers\Eloquent\Model as Eloquent;
759755

760756
class User extends Eloquent {
761-
762757
protected $connection = 'mysql';
763758

764759
public function messages()
@@ -775,7 +770,6 @@ And the Mongodb-based Message model:
775770
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
776771

777772
class Message extends Eloquent {
778-
779773
protected $connection = 'mongodb';
780774

781775
public function user()

src/Jenssegers/Eloquent/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use Jenssegers\Mongodb\Eloquent\HybridRelations;
44

5-
abstract class Model extends \Illuminate\Database\Eloquent\Model {
5+
abstract class Model extends \Illuminate\Database\Eloquent\Model
6+
{
67

78
use HybridRelations;
8-
99
}

src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use DateTime;
44
use MongoDate;
55

6-
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository {
7-
6+
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository
7+
{
88
/**
99
* Build the record payload for the table.
1010
*
@@ -26,20 +26,16 @@ protected function getPayload($email, $token)
2626
protected function tokenExpired($token)
2727
{
2828
// Convert MongoDate to a date string.
29-
if ($token['created_at'] instanceof MongoDate)
30-
{
29+
if ($token['created_at'] instanceof MongoDate) {
3130
$date = new DateTime;
3231

3332
$date->setTimestamp($token['created_at']->sec);
3433

3534
$token['created_at'] = $date->format('Y-m-d H:i:s');
36-
}
37-
elseif (is_array($token['created_at']) and isset($token['created_at']['date']))
38-
{
39-
$token['created_at'] = $token['created_at']['date'];
35+
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) {
36+
$token['created_at'] = $token['created_at']['date'];
4037
}
4138

4239
return parent::tokenExpired($token);
4340
}
44-
4541
}

src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
44

5-
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider {
6-
5+
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider
6+
{
77
/**
88
* Register the token repository implementation.
99
*
1010
* @return void
1111
*/
1212
protected function registerTokenRepository()
1313
{
14-
$this->app->singleton('auth.password.tokens', function ($app)
15-
{
14+
$this->app->singleton('auth.password.tokens', function ($app) {
1615
$connection = $app['db']->connection();
1716

1817
// The database token repository is an implementation of the token repository
@@ -25,5 +24,4 @@ protected function registerTokenRepository()
2524
return new DbRepository($connection, $table, $key, $expire);
2625
});
2726
}
28-
2927
}

src/Jenssegers/Mongodb/Collection.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use Exception;
44
use MongoCollection;
55

6-
class Collection {
7-
6+
class Collection
7+
{
88
/**
99
* The connection instance.
1010
*
@@ -41,8 +41,7 @@ public function __call($method, $parameters)
4141

4242
$result = call_user_func_array([$this->collection, $method], $parameters);
4343

44-
if ($this->connection->logging())
45-
{
44+
if ($this->connection->logging()) {
4645
// Once we have run the query we will calculate the time that it took to run and
4746
// then log the query, bindings, and execution time so we will report them on
4847
// the event that the developer needs them. We'll log time in milliseconds.
@@ -51,14 +50,10 @@ public function __call($method, $parameters)
5150
$query = [];
5251

5352
// Convert the query paramters to a json string.
54-
foreach ($parameters as $parameter)
55-
{
56-
try
57-
{
53+
foreach ($parameters as $parameter) {
54+
try {
5855
$query[] = json_encode($parameter);
59-
}
60-
catch (Exception $e)
61-
{
56+
} catch (Exception $e) {
6257
$query[] = '{...}';
6358
}
6459
}
@@ -70,5 +65,4 @@ public function __call($method, $parameters)
7065

7166
return $result;
7267
}
73-
7468
}

src/Jenssegers/Mongodb/Connection.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use MongoClient;
44

5-
class Connection extends \Illuminate\Database\Connection {
6-
5+
class Connection extends \Illuminate\Database\Connection
6+
{
77
/**
88
* The MongoDB database handler.
99
*
@@ -131,21 +131,18 @@ protected function createConnection($dsn, array $config, array $options)
131131
{
132132
// Add credentials as options, this makes sure the connection will not fail if
133133
// the username or password contains strange characters.
134-
if ( ! empty($config['username']))
135-
{
134+
if (! empty($config['username'])) {
136135
$options['username'] = $config['username'];
137136
}
138137

139-
if ( ! empty($config['password']))
140-
{
138+
if (! empty($config['password'])) {
141139
$options['password'] = $config['password'];
142140
}
143141

144142
// By default driver options is an empty array.
145143
$driverOptions = [];
146144

147-
if (isset($config['driver_options']) && is_array($config['driver_options']))
148-
{
145+
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
149146
$driverOptions = $config['driver_options'];
150147
}
151148

@@ -174,19 +171,16 @@ protected function getDsn(array $config)
174171
extract($config);
175172

176173
// Check if the user passed a complete dsn to the configuration.
177-
if ( ! empty($dsn))
178-
{
174+
if (! empty($dsn)) {
179175
return $dsn;
180176
}
181177

182178
// Treat host option as array of hosts
183179
$hosts = is_array($host) ? $host : [$host];
184180

185-
foreach ($hosts as &$host)
186-
{
181+
foreach ($hosts as &$host) {
187182
// Check if we need to add a port to the host
188-
if (strpos($host, ':') === false and isset($port))
189-
{
183+
if (strpos($host, ':') === false and isset($port)) {
190184
$host = "{$host}:{$port}";
191185
}
192186
}
@@ -228,5 +222,4 @@ public function __call($method, $parameters)
228222
{
229223
return call_user_func_array([$this->db, $method], $parameters);
230224
}
231-
232225
}

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use Illuminate\Database\Eloquent\Relations\Relation;
55
use MongoCursor;
66

7-
class Builder extends EloquentBuilder {
8-
7+
class Builder extends EloquentBuilder
8+
{
99
/**
1010
* The methods that should be returned from query builder.
1111
*
@@ -26,8 +26,7 @@ public function update(array $values)
2626
{
2727
// Intercept operations on embedded models and delegate logic
2828
// to the parent relation instance.
29-
if ($relation = $this->model->getParentRelation())
30-
{
29+
if ($relation = $this->model->getParentRelation()) {
3130
$relation->performUpdate($this->model, $values);
3231

3332
return 1;
@@ -46,8 +45,7 @@ public function insert(array $values)
4645
{
4746
// Intercept operations on embedded models and delegate logic
4847
// to the parent relation instance.
49-
if ($relation = $this->model->getParentRelation())
50-
{
48+
if ($relation = $this->model->getParentRelation()) {
5149
$relation->performInsert($this->model, $values);
5250

5351
return true;
@@ -67,8 +65,7 @@ public function insertGetId(array $values, $sequence = null)
6765
{
6866
// Intercept operations on embedded models and delegate logic
6967
// to the parent relation instance.
70-
if ($relation = $this->model->getParentRelation())
71-
{
68+
if ($relation = $this->model->getParentRelation()) {
7269
$relation->performInsert($this->model, $values);
7370

7471
return $this->model->getKey();
@@ -86,8 +83,7 @@ public function delete()
8683
{
8784
// Intercept operations on embedded models and delegate logic
8885
// to the parent relation instance.
89-
if ($relation = $this->model->getParentRelation())
90-
{
86+
if ($relation = $this->model->getParentRelation()) {
9187
$relation->performDelete($this->model);
9288

9389
return $this->model->getKey();
@@ -108,8 +104,7 @@ public function increment($column, $amount = 1, array $extra = [])
108104
{
109105
// Intercept operations on embedded models and delegate logic
110106
// to the parent relation instance.
111-
if ($relation = $this->model->getParentRelation())
112-
{
107+
if ($relation = $this->model->getParentRelation()) {
113108
$value = $this->model->{$column};
114109

115110
// When doing increment and decrements, Eloquent will automatically
@@ -139,8 +134,7 @@ public function decrement($column, $amount = 1, array $extra = [])
139134
{
140135
// Intercept operations on embedded models and delegate logic
141136
// to the parent relation instance.
142-
if ($relation = $this->model->getParentRelation())
143-
{
137+
if ($relation = $this->model->getParentRelation()) {
144138
$value = $this->model->{$column};
145139

146140
// When doing increment and decrements, Eloquent will automatically
@@ -174,13 +168,13 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
174168
$relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
175169

176170
// Remove unwanted related objects based on the operator and count.
177-
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator)
178-
{
171+
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
179172
// If we are comparing to 0, we always need all results.
180-
if ($count == 0) return true;
173+
if ($count == 0) {
174+
return true;
175+
}
181176

182-
switch ($operator)
183-
{
177+
switch ($operator) {
184178
case '>=':
185179
case '<':
186180
return $counted >= $count;
@@ -197,7 +191,9 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
197191
$not = in_array($operator, ['<', '<=', '!=']);
198192

199193
// If we are comparing to 0, we need an additional $not flip.
200-
if ($count == 0) $not = !$not;
194+
if ($count == 0) {
195+
$not = !$not;
196+
}
201197

202198
// All related ids.
203199
$relatedIds = array_keys($relationCount);
@@ -218,16 +214,14 @@ public function raw($expression = null)
218214
$results = $this->query->raw($expression);
219215

220216
// Convert MongoCursor results to a collection of models.
221-
if ($results instanceof MongoCursor)
222-
{
217+
if ($results instanceof MongoCursor) {
223218
$results = iterator_to_array($results, false);
224219

225220
return $this->model->hydrate($results);
226221
}
227222

228223
// The result is a single object.
229-
elseif (is_array($results) and array_key_exists('_id', $results))
230-
{
224+
elseif (is_array($results) and array_key_exists('_id', $results)) {
231225
$model = $this->model->newFromBuilder($results);
232226

233227
$model->setConnection($this->model->getConnection());
@@ -237,5 +231,4 @@ public function raw($expression = null)
237231

238232
return $results;
239233
}
240-
241234
}

0 commit comments

Comments
 (0)