Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Remove calls to Str::contains and Arr::get when not necessary #27

Closed
wants to merge 2 commits into from

Conversation

GromNaN
Copy link
Owner

@GromNaN GromNaN commented Aug 21, 2023

No description provided.

@@ -48,7 +48,7 @@ public function __construct(array $config)
$dsn = $this->getDsn($config);

// You can pass options directly to the MongoDB constructor
$options = Arr::get($config, 'options', []);
$options = $config['options'] ?? [];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that we're not using dot notation here (per Arr::get() docs), so these changes seem sensible.

@@ -155,7 +155,7 @@ public function getAttribute($key)
}

// Dot notation support.
if (Str::contains($key, '.') && Arr::has($this->attributes, $key)) {
if (str_contains($key, '.') && Arr::has($this->attributes, $key)) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$key is a string.

Copy link
Collaborator

@jmikola jmikola Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://laravel.com/docs/10.x/helpers#method-str-contains, am I correct to assume that Str::contains() only differs in its handling of array parameters?

Is it feasible to use scalar type hints for the getAttribute() signature, or would that conflict with inheritance? Likewise for other str_contains() changes below.

Copy link
Collaborator

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question about adding string type hints but LGTM.

@@ -48,7 +48,7 @@ public function __construct(array $config)
$dsn = $this->getDsn($config);

// You can pass options directly to the MongoDB constructor
$options = Arr::get($config, 'options', []);
$options = $config['options'] ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that we're not using dot notation here (per Arr::get() docs), so these changes seem sensible.

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

$value = $builder->convertKey($value);
} // Support keys in dot notation.
elseif (Str::contains($key, '.')) {
elseif (str_contains($key, '.')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this package require PHP 8+? I don't see it in composer.json so I reckon it's an indirect dependency. I think it'd make sense to explicitly require it if we're going to be utilizing PHP 8+ functionality directly.

Hhappy to defer to a subsequent PHPORM ticket.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires laravel/framework: ^10.0 which requires PHP 8.1+.

@GromNaN
Copy link
Owner Author

GromNaN commented Aug 22, 2023

Moved to mongodb/laravel-mongodb#2571

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants