Skip to content

Commit e821aec

Browse files
committed
Code cleanup
1 parent 01ac069 commit e821aec

40 files changed

+297
-196
lines changed

src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function tokenExpired($createdAt)
2727
$date = $createdAt->toDateTime();
2828
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
2929
$createdAt = $date->format('Y-m-d H:i:s');
30-
} elseif (is_array($createdAt) and isset($createdAt['date'])) {
30+
} elseif (is_array($createdAt) && isset($createdAt['date'])) {
3131
$date = new DateTime($createdAt['date'], new DateTimeZone(isset($createdAt['timezone']) ? $createdAt['timezone'] : 'UTC'));
3232
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
3333
$createdAt = $date->format('Y-m-d H:i:s');

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ public function raw($expression = null)
188188
*/
189189
protected function addUpdatedAtColumn(array $values)
190190
{
191-
if (! $this->model->usesTimestamps() ||
192-
is_null($this->model->getUpdatedAtColumn())) {
191+
if (! $this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) {
193192
return $values;
194193
}
195194

src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
2222
// If no relation name was given, we will use this debug backtrace to extract
2323
// the calling method's name and use that as the relationship name as most
2424
// of the time this will be what we desire to use for the relationships.
25-
if (is_null($relation)) {
25+
if ($relation === null) {
2626
list(, $caller) = debug_backtrace(false);
2727

2828
$relation = $caller['function'];
2929
}
3030

31-
if (is_null($localKey)) {
31+
if ($localKey === null) {
3232
$localKey = $relation;
3333
}
3434

35-
if (is_null($foreignKey)) {
35+
if ($foreignKey === null) {
3636
$foreignKey = Str::snake(class_basename($this));
3737
}
3838

@@ -57,17 +57,17 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
5757
// If no relation name was given, we will use this debug backtrace to extract
5858
// the calling method's name and use that as the relationship name as most
5959
// of the time this will be what we desire to use for the relationships.
60-
if (is_null($relation)) {
60+
if ($relation === null) {
6161
list(, $caller) = debug_backtrace(false);
6262

6363
$relation = $caller['function'];
6464
}
6565

66-
if (is_null($localKey)) {
66+
if ($localKey === null) {
6767
$localKey = $relation;
6868
}
6969

70-
if (is_null($foreignKey)) {
70+
if ($foreignKey === null) {
7171
$foreignKey = Str::snake(class_basename($this));
7272
}
7373

src/Jenssegers/Mongodb/Eloquent/HybridRelations.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
133133
// If no relation name was given, we will use this debug backtrace to extract
134134
// the calling method's name and use that as the relationship name as most
135135
// of the time this will be what we desire to use for the relationships.
136-
if (is_null($relation)) {
136+
if ($relation === null) {
137137
list($current, $caller) = debug_backtrace(false, 2);
138138

139139
$relation = $caller['function'];
@@ -147,7 +147,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
147147
// If no foreign key was supplied, we can use a backtrace to guess the proper
148148
// foreign key name by using the name of the relationship function, which
149149
// when combined with an "_id" should conventionally match the columns.
150-
if (is_null($foreignKey)) {
150+
if ($foreignKey === null) {
151151
$foreignKey = Str::snake($relation) . '_id';
152152
}
153153

@@ -177,7 +177,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
177177
// If no name is provided, we will use the backtrace to get the function name
178178
// since that is most likely the name of the polymorphic interface. We can
179179
// use that to get both the class and foreign key that will be utilized.
180-
if (is_null($name)) {
180+
if ($name === null) {
181181
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
182182

183183
$name = Str::snake($caller['function']);
@@ -188,7 +188,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
188188
// If the type value is null it is probably safe to assume we're eager loading
189189
// the relationship. When that is the case we will pass in a dummy query as
190190
// there are multiple types in the morph and we can't use single queries.
191-
if (is_null($class = $this->$type)) {
191+
if (($class = $this->$type) === null) {
192192
return new MorphTo(
193193
$this->newQuery(), $this, $id, null, $type, $name
194194
);
@@ -197,15 +197,13 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
197197
// If we are not eager loading the relationship we will essentially treat this
198198
// as a belongs-to style relationship since morph-to extends that class and
199199
// we will pass in the appropriate values so that it behaves as expected.
200-
else {
201-
$class = $this->getActualClassNameForMorph($class);
200+
$class = $this->getActualClassNameForMorph($class);
202201

203-
$instance = new $class;
202+
$instance = new $class;
204203

205-
return new MorphTo(
206-
$instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
207-
);
208-
}
204+
return new MorphTo(
205+
$instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
206+
);
209207
}
210208

211209
/**
@@ -232,7 +230,7 @@ public function belongsToMany(
232230
// If no relationship name was passed, we will pull backtraces to get the
233231
// name of the calling function. We will use that function name as the
234232
// title of this relation since that is a great convention to apply.
235-
if (is_null($relation)) {
233+
if ($relation === null) {
236234
$relation = $this->guessBelongsToManyRelation();
237235
}
238236

@@ -261,7 +259,7 @@ public function belongsToMany(
261259
// If no table name was provided, we can guess it by concatenating the two
262260
// models using underscores in alphabetical order. The two model names
263261
// are transformed to snake case from their default CamelCase also.
264-
if (is_null($collection)) {
262+
if ($collection === null) {
265263
$collection = $instance->getTable();
266264
}
267265

@@ -303,8 +301,8 @@ public function newEloquentBuilder($query)
303301
{
304302
if (is_subclass_of($this, \Jenssegers\Mongodb\Eloquent\Model::class)) {
305303
return new Builder($query);
306-
} else {
307-
return new EloquentBuilder($query);
308304
}
305+
306+
return new EloquentBuilder($query);
309307
}
310308
}

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function getFresh($columns = [])
233233
// If no columns have been specified for the select statement, we will set them
234234
// here to either the passed columns, or the standard default of retrieving
235235
// all of the columns on the table using the "wildcard" column character.
236-
if (is_null($this->columns)) {
236+
if ($this->columns === null) {
237237
$this->columns = $columns;
238238
}
239239

@@ -469,7 +469,7 @@ public function aggregate($function, $columns = [])
469469
*/
470470
public function exists()
471471
{
472-
return !is_null($this->first());
472+
return $this->first() !== null;
473473
}
474474

475475
/**
@@ -580,7 +580,7 @@ public function insertGetId(array $values, $sequence = null)
580580
$result = $this->collection->insertOne($values);
581581

582582
if (1 == (int) $result->isAcknowledged()) {
583-
if (is_null($sequence)) {
583+
if ($sequence === null) {
584584
$sequence = '_id';
585585
}
586586

@@ -652,7 +652,7 @@ public function forPageAfterId($perPage = 15, $lastId = 0, $column = '_id')
652652
*/
653653
public function pluck($column, $key = null)
654654
{
655-
$results = $this->get(is_null($key) ? [$column] : [$column, $key]);
655+
$results = $this->get($key === null ? [$column] : [$column, $key]);
656656

657657
// Convert ObjectID's to strings
658658
if ($key == '_id') {
@@ -674,7 +674,7 @@ public function delete($id = null)
674674
// If an ID is passed to the method, we will set the where clause to check
675675
// the ID to allow developers to simply and quickly remove a single row
676676
// from their database without manually specifying the where clauses.
677-
if (!is_null($id)) {
677+
if ($id !== null) {
678678
$this->where('_id', '=', $id);
679679
}
680680

@@ -730,8 +730,10 @@ public function raw($expression = null)
730730
// Execute the closure on the mongodb collection
731731
if ($expression instanceof Closure) {
732732
return call_user_func($expression, $this->collection);
733-
} // Create an expression for the given value
734-
elseif (!is_null($expression)) {
733+
}
734+
735+
// Create an expression for the given value
736+
if ($expression !== null) {
735737
return new Expression($expression);
736738
}
737739

@@ -854,7 +856,9 @@ public function convertKey($id)
854856
{
855857
if (is_string($id) && strlen($id) === 24 && ctype_xdigit($id)) {
856858
return new ObjectID($id);
857-
} elseif (is_string($id) && strlen($id) === 16 && preg_match('~[^\x20-\x7E\t\r\n]~', $id) > 0) {
859+
}
860+
861+
if (is_string($id) && strlen($id) === 16 && preg_match('~[^\x20-\x7E\t\r\n]~', $id) > 0) {
858862
return new Binary($id, Binary::TYPE_UUID);
859863
}
860864

@@ -1009,7 +1013,7 @@ protected function compileWhereBasic(array $where)
10091013
$regex = '^' . $regex;
10101014
}
10111015
if (!Str::endsWith($value, '%')) {
1012-
$regex = $regex . '$';
1016+
$regex .= '$';
10131017
}
10141018

10151019
$value = new Regex($regex, 'i');
@@ -1121,14 +1125,14 @@ protected function compileWhereBetween(array $where)
11211125
],
11221126
],
11231127
];
1124-
} else {
1125-
return [
1126-
$column => [
1127-
'$gte' => $values[0],
1128-
'$lte' => $values[1],
1129-
],
1130-
];
11311128
}
1129+
1130+
return [
1131+
$column => [
1132+
'$gte' => $values[0],
1133+
'$lte' => $values[1],
1134+
],
1135+
];
11321136
}
11331137

11341138
/**

src/Jenssegers/Mongodb/Queue/MongoQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function pop($queue = null)
3939
{
4040
$queue = $this->getQueue($queue);
4141

42-
if (!is_null($this->retryAfter)) {
42+
if ($this->retryAfter !== null) {
4343
$this->releaseJobsThatHaveBeenReservedTooLong($queue);
4444
}
4545

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public function associate(Model $model)
130130
{
131131
if (!$this->contains($model)) {
132132
return $this->associateNew($model);
133-
} else {
134-
return $this->associateExisting($model);
135133
}
134+
135+
return $this->associateExisting($model);
136136
}
137137

138138
/**

src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ protected function toCollection(array $records = [])
279279
*/
280280
protected function toModel($attributes = [])
281281
{
282-
if (is_null($attributes)) {
282+
if ($attributes === null) {
283283
return;
284284
}
285285

src/Jenssegers/Mongodb/Schema/Blueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function sparse_and_unique($columns = null, $options = [])
243243
*/
244244
protected function fluent($columns = null)
245245
{
246-
if (is_null($columns)) {
246+
if ($columns === null) {
247247
return $this->columns;
248248
} elseif (is_string($columns)) {
249249
return $this->columns = [$columns];

src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getCount($collection, $column, $value, $excludeId = null, $idCol
1919
{
2020
$query = $this->table($collection)->where($column, 'regex', "/$value/i");
2121

22-
if (!is_null($excludeId) && $excludeId != 'NULL') {
22+
if ($excludeId !== null && $excludeId != 'NULL') {
2323
$query->where($idColumn ?: 'id', '<>', $excludeId);
2424
}
2525

tests/CollectionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
use Jenssegers\Mongodb\Connection;
45
use Jenssegers\Mongodb\Collection;

tests/ConnectionTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
2+
declare(strict_types=1);
3+
4+
use Illuminate\Support\Facades\DB;
25

36
class ConnectionTest extends TestCase
47
{
58
public function testConnection()
69
{
710
$connection = DB::connection('mongodb');
8-
$this->assertInstanceOf('Jenssegers\Mongodb\Connection', $connection);
11+
$this->assertInstanceOf(\Jenssegers\Mongodb\Connection::class, $connection);
912
}
1013

1114
public function testReconnect()
@@ -23,22 +26,22 @@ public function testReconnect()
2326
public function testDb()
2427
{
2528
$connection = DB::connection('mongodb');
26-
$this->assertInstanceOf('MongoDB\Database', $connection->getMongoDB());
29+
$this->assertInstanceOf(\MongoDB\Database::class, $connection->getMongoDB());
2730

2831
$connection = DB::connection('mongodb');
29-
$this->assertInstanceOf('MongoDB\Client', $connection->getMongoClient());
32+
$this->assertInstanceOf(\MongoDB\Client::class, $connection->getMongoClient());
3033
}
3134

3235
public function testCollection()
3336
{
3437
$collection = DB::connection('mongodb')->getCollection('unittest');
35-
$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
38+
$this->assertInstanceOf(Jenssegers\Mongodb\Collection::class, $collection);
3639

3740
$collection = DB::connection('mongodb')->collection('unittests');
38-
$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
41+
$this->assertInstanceOf(Jenssegers\Mongodb\Query\Builder::class, $collection);
3942

4043
$collection = DB::connection('mongodb')->table('unittests');
41-
$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
44+
$this->assertInstanceOf(Jenssegers\Mongodb\Query\Builder::class, $collection);
4245
}
4346

4447
// public function testDynamic()
@@ -87,7 +90,7 @@ public function testQueryLog()
8790
public function testSchemaBuilder()
8891
{
8992
$schema = DB::connection('mongodb')->getSchemaBuilder();
90-
$this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema);
93+
$this->assertInstanceOf(\Jenssegers\Mongodb\Schema\Builder::class, $schema);
9194
}
9295

9396
public function testDriverName()

tests/DsnTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
class DsnTest extends TestCase
45
{

0 commit comments

Comments
 (0)