Skip to content

Commit

Permalink
Move to PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Aug 15, 2021
1 parent d2a046b commit 8e680c9
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We accept contributions via Pull Requests on [GitHub](https://github.com/stauden

## Pull Requests

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).
- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).

- **Add tests** - Your patch won't be accepted if it doesn't have tests.

Expand Down
10 changes: 5 additions & 5 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getModels($columns = ['*'])
}
}

$table = (new $this->model)->getTable();
$table = (new $this->model())->getTable();

$models = $this->model->hydrate($items)->each->setTable($table);

Expand Down Expand Up @@ -79,13 +79,13 @@ public function getExpressionGrammar()

switch ($driver) {
case 'mysql':
return $this->query->getConnection()->withTablePrefix(new MySqlGrammar);
return $this->query->getConnection()->withTablePrefix(new MySqlGrammar());
case 'pgsql':
return $this->query->getConnection()->withTablePrefix(new PostgresGrammar);
return $this->query->getConnection()->withTablePrefix(new PostgresGrammar());
case 'sqlite':
return $this->query->getConnection()->withTablePrefix(new SQLiteGrammar);
return $this->query->getConnection()->withTablePrefix(new SQLiteGrammar());
case 'sqlsrv':
return $this->query->getConnection()->withTablePrefix(new SqlServerGrammar);
return $this->query->getConnection()->withTablePrefix(new SqlServerGrammar());
}

throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/HasRecursiveRelationshipScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function scopeTreeOf(Builder $query, callable $constraint, $maxDepth = nu
*/
public function scopeHasChildren(Builder $query)
{
$keys = (new static)->newQuery()
$keys = (new static())->newQuery()
->select($this->getParentKeyName())
->hasParent();

Expand All @@ -70,7 +70,7 @@ public function scopeHasParent(Builder $query)
*/
public function scopeIsLeaf(Builder $query)
{
$keys = (new static)->newQuery()
$keys = (new static())->newQuery()
->select($this->getParentKeyName())
->hasParent();

Expand Down
21 changes: 11 additions & 10 deletions src/Eloquent/HasRecursiveRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

trait HasRecursiveRelationships
{
use HasRecursiveRelationshipScopes, QueriesExpressions;
use HasRecursiveRelationshipScopes;
use QueriesExpressions;

/**
* Get the name of the parent key column.
Expand All @@ -33,7 +34,7 @@ public function getParentKeyName()
*/
public function getQualifiedParentKeyName()
{
return (new static)->getTable().'.'.$this->getParentKeyName();
return (new static())->getTable().'.'.$this->getParentKeyName();
}

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public function getExpressionName()
{
return 'laravel_cte';
}

/**
* Get the model's ancestors.
*
Expand All @@ -114,7 +115,7 @@ public function getExpressionName()
public function ancestors()
{
return $this->newAncestors(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getLocalKeyName(),
Expand All @@ -130,7 +131,7 @@ public function ancestors()
public function ancestorsAndSelf()
{
return $this->newAncestors(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getLocalKeyName(),
Expand Down Expand Up @@ -181,7 +182,7 @@ public function childrenAndSelf()
public function descendants()
{
return $this->newDescendants(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getLocalKeyName(),
Expand All @@ -197,7 +198,7 @@ public function descendants()
public function descendantsAndSelf()
{
return $this->newDescendants(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getLocalKeyName(),
Expand Down Expand Up @@ -248,7 +249,7 @@ public function parentAndSelf()
public function rootAncestor()
{
return $this->newRootAncestor(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getLocalKeyName()
Expand Down Expand Up @@ -277,7 +278,7 @@ protected function newRootAncestor(Builder $query, Model $parent, $foreignKey, $
public function siblings()
{
return $this->newSiblings(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getParentKeyName(),
Expand All @@ -293,7 +294,7 @@ public function siblings()
public function siblingsAndSelf()
{
return $this->newSiblings(
(new static)->newQuery(),
(new static())->newQuery(),
$this,
$this->getQualifiedParentKeyName(),
$this->getParentKeyName(),
Expand Down
10 changes: 5 additions & 5 deletions src/Eloquent/Relations/HasManyOfDescendants.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function buildDictionary(Collection $results)
*/
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
{
$table = (new $this->parent)->getTable();
$table = (new $this->parent())->getTable();

if ($table === $parentQuery->getQuery()->from) {
$table = $alias = $this->getRelationCountHash();
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function addExpression(callable $constraint, Builder $query = null, $a
$query->withGlobalScope('HasManyOfDescendants', function (Builder $query) use ($name) {
$query->whereIn(
$this->foreignKey,
(new $this->parent)->setTable($name)->newQuery()->select($this->localKey)
(new $this->parent())->setTable($name)->newQuery()->select($this->localKey)
);
});

Expand All @@ -234,7 +234,7 @@ protected function addExpression(callable $constraint, Builder $query = null, $a
*/
protected function getInitialQuery(ExpressionGrammar $grammar, callable $constraint, $alias, $selectPath)
{
$model = new $this->parent;
$model = new $this->parent();
$query = $model->newModelQuery();

if ($alias) {
Expand Down Expand Up @@ -264,7 +264,7 @@ protected function getInitialQuery(ExpressionGrammar $grammar, callable $constra
*/
protected function getRecursiveQuery(ExpressionGrammar $grammar, $selectPath)
{
$model = new $this->parent;
$model = new $this->parent();
$name = $model->getExpressionName();
$query = $model->newModelQuery();

Expand Down Expand Up @@ -325,7 +325,7 @@ public function withTrashedDescendants()
$this->query->withoutGlobalScope('HasManyOfDescendants')
->whereIn(
$this->foreignKey,
(new $this->parent)->setTable($table)->newModelQuery()->select($this->localKey)
(new $this->parent())->setTable($table)->newModelQuery()->select($this->localKey)
);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/DescendantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testLazyLoadingAndSelf()

public function testLazyLoadingWithoutParentKey()
{
$descendants = (new User)->descendants()->get();
$descendants = (new User())->descendants()->get();

$this->assertEmpty($descendants);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/HasManyOfDescendantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testLazyLoadingAndSelf()

public function testLazyLoadingWithoutParentKey()
{
$posts = (new User)->posts()->get();
$posts = (new User())->posts()->get();

$this->assertEmpty($posts);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

class Post extends Model
{
use QueriesExpressions, SoftDeletes;
use QueriesExpressions;
use SoftDeletes;
}
3 changes: 2 additions & 1 deletion tests/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class User extends Model
{
use HasRecursiveRelationships, SoftDeletes;
use HasRecursiveRelationships;
use SoftDeletes;

public function getCustomPaths()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/SiblingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testLazyLoadingAndSelfWithRoot()

public function testLazyLoadingWithoutParentKey()
{
$siblings = (new User)->siblings;
$siblings = (new User())->siblings;

$this->assertEmpty($siblings);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function setUp(): void

$config = require __DIR__.'/config/database.php';

$db = new DB;
$db = new DB();
$db->addConnection($config[getenv('DATABASE') ?: 'sqlite']);
$db->setAsGlobal();
$db->bootEloquent();
Expand Down

0 comments on commit 8e680c9

Please sign in to comment.