Skip to content

Commit

Permalink
Improve phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Aug 30, 2023
1 parent 14fef1a commit 81a0fc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/Eloquent/EmbedsRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MongoDB\Laravel\Eloquent;

use Illuminate\Support\Str;
use MongoDB\Laravel\Eloquent\Model as MongoDBModel;
use MongoDB\Laravel\Relations\EmbedsMany;
use MongoDB\Laravel\Relations\EmbedsOne;
use ReflectionMethod;
Expand All @@ -21,11 +22,11 @@ trait EmbedsRelations
/**
* Define an embedded one-to-many relationship.
*
* @param string $related
* @param class-string<MongoDBModel> $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \MongoDB\Laravel\Relations\EmbedsMany
* @return EmbedsMany
*/
protected function embedsMany($related, $localKey = null, $foreignKey = null, $relation = null)
{
Expand Down Expand Up @@ -54,11 +55,11 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
/**
* Define an embedded one-to-many relationship.
*
* @param string $related
* @param class-string<MongoDBModel> $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \MongoDB\Laravel\Relations\EmbedsOne
* @return EmbedsOne
*/
protected function embedsOne($related, $localKey = null, $foreignKey = null, $relation = null)
{
Expand Down Expand Up @@ -103,7 +104,7 @@ private function hasEmbeddedRelation(string $key): bool

$returnType = (new ReflectionMethod($this, $method))->getReturnType();

return static::$embeddedCache[static::class][$key] = $returnType instanceof ReflectionNamedType
return self::$embeddedCache[static::class][$key] = $returnType instanceof ReflectionNamedType
&& in_array($returnType->getName(), [EmbedsOne::class, EmbedsMany::class], true);
}
}
28 changes: 15 additions & 13 deletions src/Eloquent/HybridRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace MongoDB\Laravel\Eloquent;

use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use MongoDB\Laravel\Eloquent\Model as MongoDBModel;
use MongoDB\Laravel\Helpers\EloquentBuilder;
use MongoDB\Laravel\Relations\BelongsTo;
use MongoDB\Laravel\Relations\BelongsToMany;
Expand All @@ -21,15 +23,15 @@ trait HybridRelations
/**
* Define a one-to-one relationship.
*
* @param string $related
* @param class-string<EloquentModel> $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function hasOne($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::hasOne($related, $foreignKey, $localKey);
}

Expand All @@ -45,7 +47,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
/**
* Define a polymorphic one-to-one relationship.
*
* @param string $related
* @param class-string<EloquentModel> $related
* @param string $name
* @param string $type
* @param string $id
Expand All @@ -55,7 +57,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::morphOne($related, $name, $type, $id, $localKey);
}

Expand All @@ -71,15 +73,15 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
/**
* Define a one-to-many relationship.
*
* @param string $related
* @param class-string<EloquentModel> $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function hasMany($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::hasMany($related, $foreignKey, $localKey);
}

Expand All @@ -95,7 +97,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param class-string<EloquentModel> $related
* @param string $name
* @param string $type
* @param string $id
Expand All @@ -105,7 +107,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::morphMany($related, $name, $type, $id, $localKey);
}

Expand All @@ -126,7 +128,7 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
/**
* Define an inverse one-to-one or many relationship.
*
* @param string $related
* @param class-string<EloquentModel> $related
* @param string $foreignKey
* @param string $otherKey
* @param string $relation
Expand All @@ -142,7 +144,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
}

// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
}

Expand Down Expand Up @@ -211,7 +213,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
/**
* Define a many-to-many relationship.
*
* @param class-string<\Illuminate\Database\Eloquent\Model> $related
* @param class-string<EloquentModel> $related
* @param string|null $collection
* @param string|null $foreignKey
* @param string|null $otherKey
Expand All @@ -237,7 +239,7 @@ public function belongsToMany(
}

// Check if it is a relation with an original model.
if (! is_subclass_of($related, Model::class)) {
if (! is_subclass_of($related, MongoDBModel::class)) {
return parent::belongsToMany(
$related,
$collection,
Expand Down Expand Up @@ -306,7 +308,7 @@ protected function guessBelongsToManyRelation()
*/
public function newEloquentBuilder($query)
{
if (is_subclass_of($this, Model::class)) {
if (is_subclass_of($this, MongoDBModel::class)) {
return new Builder($query);
}

Expand Down

0 comments on commit 81a0fc6

Please sign in to comment.