Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docblock and Strict Code updates #21517

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Illuminate/Contracts/Queue/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Illuminate\Contracts\Queue;

/**
* @mixin \Illuminate\Queue\Jobs\Job
*
* @method int getJobId()
*/
interface Job
{
/**
Expand Down
25 changes: 18 additions & 7 deletions src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ trait HasRelationships
/**
* The loaded relationships for the model.
*
* @var array
* @var Model[]
*/
protected $relations = [];

/**
* The relationships that should be touched on save.
*
* @var array
* @var string[]
*/
protected $touches = [];

/**
* The many to many relationship methods.
*
* @var array
* @var string[]
*/
public static $manyMethods = [
'belongsToMany', 'morphToMany', 'morphedByMany',
Expand All @@ -59,6 +59,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)

$localKey = $localKey ?: $this->getKeyName();

/* @var Model $this */
return new HasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey);
}

Expand All @@ -82,6 +83,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =

$localKey = $localKey ?: $this->getKeyName();

/* @var Model $this */
return new MorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
}

Expand Down Expand Up @@ -117,6 +119,7 @@ public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relat
// actually be responsible for retrieving and hydrating every relations.
$ownerKey = $ownerKey ?: $instance->getKeyName();

/* @var Model $this */
return new BelongsTo(
$instance->newQuery(), $this, $foreignKey, $ownerKey, $relation
);
Expand Down Expand Up @@ -159,6 +162,7 @@ public function morphTo($name = null, $type = null, $id = null)
*/
protected function morphEagerTo($name, $type, $id)
{
/* @var Model $this */
return new MorphTo(
$this->newQuery()->setEagerLoads([]), $this, $id, null, $type, $name
);
Expand All @@ -179,6 +183,7 @@ protected function morphInstanceTo($target, $name, $type, $id)
static::getActualClassNameForMorph($target)
);

/* @var Model $this */
return new MorphTo(
$instance->newQuery(), $this, $id, $instance->getKeyName(), $type, $name
);
Expand All @@ -202,9 +207,9 @@ public static function getActualClassNameForMorph($class)
*/
protected function guessBelongsToRelation()
{
list($one, $two, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
$calls = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);

return $caller['function'];
return $calls[2]['function'];
}

/**
Expand All @@ -223,6 +228,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)

$localKey = $localKey ?: $this->getKeyName();

/* @var Model $this */
return new HasMany(
$instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey
);
Expand All @@ -241,6 +247,8 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
*/
public function hasManyThrough($related, $through, $firstKey = null, $secondKey = null, $localKey = null, $secondLocalKey = null)
{
/* @var Model $through */
/* @var Model $this */
$through = new $through;

$firstKey = $firstKey ?: $this->getForeignKey();
Expand Down Expand Up @@ -268,6 +276,7 @@ public function hasManyThrough($related, $through, $firstKey = null, $secondKey
*/
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{
/* @var Model $this */
$instance = $this->newRelatedInstance($related);

// Here we will gather up the morph type and ID for the relationship so that we
Expand Down Expand Up @@ -297,6 +306,7 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
public function belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null,
$parentKey = null, $relatedKey = null, $relation = null)
{
/* @var Model $this */
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
Expand Down Expand Up @@ -344,6 +354,7 @@ public function morphToMany($related, $name, $table = null, $foreignPivotKey = n
$relatedPivotKey = null, $parentKey = null,
$relatedKey = null, $inverse = false)
{
/* @var Model $this */
$caller = $this->guessBelongsToManyRelation();

// First, we will need to determine the foreign key and "other key" for the
Expand Down Expand Up @@ -503,7 +514,7 @@ public function getMorphClass()
*/
protected function newRelatedInstance($class)
{
return tap(new $class, function ($instance) {
return tap(new $class, function (Model $instance) {
if (! $instance->getConnectionName()) {
$instance->setConnection($this->connection);
}
Expand Down Expand Up @@ -559,7 +570,7 @@ public function setRelation($relation, $value)
/**
* Set the entire relations array on the model.
*
* @param array $relations
* @param Model[] $relations
* @return $this
*/
public function setRelations(array $relations)
Expand Down
Loading