Skip to content

Commit 7d3be9f

Browse files
authored
Remove calls to Str::contains and Arr::get when not necessary (#2571)
* Replace Laravel Str helpers with native PHP8 functions * Remove Arr::get where not necessary
1 parent 0604d71 commit 7d3be9f

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

src/Connection.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use function class_exists;
66
use Composer\InstalledVersions;
77
use Illuminate\Database\Connection as BaseConnection;
8-
use Illuminate\Support\Arr;
98
use InvalidArgumentException;
109
use Jenssegers\Mongodb\Concerns\ManagesTransactions;
1110
use MongoDB\Client;
@@ -48,7 +47,7 @@ public function __construct(array $config)
4847
$dsn = $this->getDsn($config);
4948

5049
// You can pass options directly to the MongoDB constructor
51-
$options = Arr::get($config, 'options', []);
50+
$options = $config['options'] ?? [];
5251

5352
// Create the connection
5453
$this->connection = $this->createConnection($dsn, $config, $options);

src/Eloquent/Model.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getAttribute($key)
155155
}
156156

157157
// Dot notation support.
158-
if (Str::contains($key, '.') && Arr::has($this->attributes, $key)) {
158+
if (str_contains($key, '.') && Arr::has($this->attributes, $key)) {
159159
return $this->getAttributeValue($key);
160160
}
161161

@@ -177,7 +177,7 @@ public function getAttribute($key)
177177
protected function getAttributeFromArray($key)
178178
{
179179
// Support keys in dot notation.
180-
if (Str::contains($key, '.')) {
180+
if (str_contains($key, '.')) {
181181
return Arr::get($this->attributes, $key);
182182
}
183183

@@ -195,7 +195,7 @@ public function setAttribute($key, $value)
195195

196196
$value = $builder->convertKey($value);
197197
} // Support keys in dot notation.
198-
elseif (Str::contains($key, '.')) {
198+
elseif (str_contains($key, '.')) {
199199
// Store to a temporary key, then move data to the actual key
200200
$uniqueKey = uniqid($key);
201201
parent::setAttribute($uniqueKey, $value);

src/Query/Builder.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Illuminate\Support\Arr;
1111
use Illuminate\Support\Collection;
1212
use Illuminate\Support\LazyCollection;
13-
use Illuminate\Support\Str;
1413
use Jenssegers\Mongodb\Connection;
1514
use MongoDB\BSON\Binary;
1615
use MongoDB\BSON\ObjectID;
@@ -617,7 +616,7 @@ public function insertGetId(array $values, $sequence = null)
617616
public function update(array $values, array $options = [])
618617
{
619618
// Use $set as default operator.
620-
if (! Str::startsWith(key($values), '$')) {
619+
if (! str_starts_with(key($values), '$')) {
621620
$values = ['$set' => $values];
622621
}
623622

@@ -951,7 +950,7 @@ protected function compileWheres(): array
951950
}
952951

953952
// Convert id's.
954-
if (isset($where['column']) && ($where['column'] == '_id' || Str::endsWith($where['column'], '._id'))) {
953+
if (isset($where['column']) && ($where['column'] == '_id' || str_ends_with($where['column'], '._id'))) {
955954
// Multiple values.
956955
if (isset($where['values'])) {
957956
foreach ($where['values'] as &$value) {

src/Queue/MongoConnector.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Database\ConnectionResolverInterface;
66
use Illuminate\Queue\Connectors\ConnectorInterface;
7-
use Illuminate\Support\Arr;
87

98
class MongoConnector implements ConnectorInterface
109
{
@@ -34,10 +33,10 @@ public function __construct(ConnectionResolverInterface $connections)
3433
public function connect(array $config)
3534
{
3635
return new MongoQueue(
37-
$this->connections->connection(Arr::get($config, 'connection')),
36+
$this->connections->connection($config['connection'] ?? null),
3837
$config['table'],
3938
$config['queue'],
40-
Arr::get($config, 'expire', 60)
39+
$config['expire'] ?? 60
4140
);
4241
}
4342
}

0 commit comments

Comments
 (0)