Skip to content

Apply fixes produced by php-cs-fixer #2250

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

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
env:
PHP_CS_FIXER_VERSION: v2.18.7
strategy:
matrix:
php:
Expand All @@ -21,9 +23,9 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: curl,mbstring
tools: php-cs-fixer
tools: php-cs-fixer:${{ env.PHP_CS_FIXER_VERSION }}
coverage: none
- name: Run PHP-CS-Fixer Fix
- name: Run PHP-CS-Fixer Fix, version ${{ env.PHP_CS_FIXER_VERSION }}
run: php-cs-fixer fix --dry-run --diff --ansi

build:
Expand Down
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __call($method, $parameters)
}
}

$queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')';
$queryString = $this->collection->getCollectionName().'.'.$method.'('.implode(',', $query).')';

$this->connection->logQuery($queryString, [], $time);

Expand Down
28 changes: 14 additions & 14 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getDatabaseName()
}

/**
* Get the name of the default database based on db config or try to detect it from dsn
* Get the name of the default database based on db config or try to detect it from dsn.
* @param string $dsn
* @param array $config
* @return string
Expand All @@ -131,7 +131,7 @@ protected function getDefaultDatabaseName($dsn, $config)
if (preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) {
$config['database'] = $matches[1];
} else {
throw new InvalidArgumentException("Database is not properly configured.");
throw new InvalidArgumentException('Database is not properly configured.');
}
}

Expand All @@ -155,10 +155,10 @@ protected function createConnection($dsn, array $config, array $options)
}

// Check if the credentials are not already set in the options
if (!isset($options['username']) && !empty($config['username'])) {
if (! isset($options['username']) && ! empty($config['username'])) {
$options['username'] = $config['username'];
}
if (!isset($options['password']) && !empty($config['password'])) {
if (! isset($options['password']) && ! empty($config['password'])) {
$options['password'] = $config['password'];
}

Expand All @@ -180,7 +180,7 @@ public function disconnect()
*/
protected function hasDsnString(array $config)
{
return isset($config['dsn']) && !empty($config['dsn']);
return isset($config['dsn']) && ! empty($config['dsn']);
}

/**
Expand All @@ -205,14 +205,15 @@ protected function getHostDsn(array $config)

foreach ($hosts as &$host) {
// Check if we need to add a port to the host
if (strpos($host, ':') === false && !empty($config['port'])) {
$host = $host . ':' . $config['port'];
if (strpos($host, ':') === false && ! empty($config['port'])) {
$host = $host.':'.$config['port'];
}
}

// Check if we want to authenticate against a specific database.
$auth_database = isset($config['options']) && !empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : '');
$auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null;

return 'mongodb://'.implode(',', $hosts).($auth_database ? '/'.$auth_database : '');
}

/**
Expand Down Expand Up @@ -266,16 +267,15 @@ protected function getDefaultSchemaGrammar()
{
return new Schema\Grammar();
}

/**
* Set database.
* @param \MongoDB\Database $db
*/
public function setDatabase(\MongoDB\Database $db)
{
$this->db = $db;
}

{
$this->db = $db;
}

/**
* Dynamically pass methods to the connection.
Expand Down
6 changes: 3 additions & 3 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Builder extends EloquentBuilder
'push',
'raw',
'sum',
'toSql'
'toSql',
];

/**
Expand Down Expand Up @@ -190,13 +190,13 @@ public function raw($expression = null)
* Add the "updated at" column to an array of values.
* TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e
* wiil be reverted
* Issue in laravel frawework https://github.com/laravel/framework/issues/27791
* Issue in laravel frawework https://github.com/laravel/framework/issues/27791.
* @param array $values
* @return array
*/
protected function addUpdatedAtColumn(array $values)
{
if (!$this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) {
if (! $this->model->usesTimestamps() || $this->model->getUpdatedAtColumn() === null) {
return $values;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/EmbedsRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
list(, $caller) = debug_backtrace(false);
[, $caller] = debug_backtrace(false);

$relation = $caller['function'];
}
Expand Down Expand Up @@ -56,7 +56,7 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
list(, $caller) = debug_backtrace(false);
[, $caller] = debug_backtrace(false);

$relation = $caller['function'];
}
Expand Down
30 changes: 15 additions & 15 deletions src/Eloquent/HybridRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Jenssegers\Mongodb\Relations\BelongsToMany;
use Jenssegers\Mongodb\Relations\HasMany;
use Jenssegers\Mongodb\Relations\HasOne;
use Jenssegers\Mongodb\Relations\MorphTo;
use Jenssegers\Mongodb\Relations\MorphMany;
use Jenssegers\Mongodb\Relations\MorphTo;

trait HybridRelations
{
Expand All @@ -24,7 +24,7 @@ trait HybridRelations
public function hasOne($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::hasOne($related, $foreignKey, $localKey);
}

Expand All @@ -49,13 +49,13 @@ 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, \Jenssegers\Mongodb\Eloquent\Model::class)) {
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::morphOne($related, $name, $type, $id, $localKey);
}

$instance = new $related;

list($type, $id) = $this->getMorphs($name, $type, $id);
[$type, $id] = $this->getMorphs($name, $type, $id);

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

Expand All @@ -72,7 +72,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
public function hasMany($related, $foreignKey = null, $localKey = null)
{
// Check if it is a relation with an original model.
if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::hasMany($related, $foreignKey, $localKey);
}

Expand All @@ -97,7 +97,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, \Jenssegers\Mongodb\Eloquent\Model::class)) {
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::morphMany($related, $name, $type, $id, $localKey);
}

Expand All @@ -106,7 +106,7 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list($type, $id) = $this->getMorphs($name, $type, $id);
[$type, $id] = $this->getMorphs($name, $type, $id);

$table = $instance->getTable();

Expand All @@ -129,21 +129,21 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
list($current, $caller) = debug_backtrace(false, 2);
[$current, $caller] = debug_backtrace(false, 2);

$relation = $caller['function'];
}

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

// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if ($foreignKey === null) {
$foreignKey = Str::snake($relation) . '_id';
$foreignKey = Str::snake($relation).'_id';
}

$instance = new $related;
Expand Down Expand Up @@ -172,12 +172,12 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if ($name === null) {
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
[$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

$name = Str::snake($caller['function']);
}

list($type, $id) = $this->getMorphs($name, $type, $id);
[$type, $id] = $this->getMorphs($name, $type, $id);

// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
Expand Down Expand Up @@ -230,7 +230,7 @@ public function belongsToMany(
}

// Check if it is a relation with an original model.
if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::belongsToMany(
$related,
$collection,
Expand All @@ -245,11 +245,11 @@ public function belongsToMany(
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey() . 's';
$foreignKey = $foreignKey ?: $this->getForeignKey().'s';

$instance = new $related;

$otherKey = $otherKey ?: $instance->getForeignKey() . 's';
$otherKey = $otherKey ?: $instance->getForeignKey().'s';

// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
Expand Down
24 changes: 12 additions & 12 deletions src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getIdAttribute($value = null)
{
// If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way.
if (!$value && array_key_exists('_id', $this->attributes)) {
if (! $value && array_key_exists('_id', $this->attributes)) {
$value = $this->attributes['_id'];
}

Expand Down Expand Up @@ -85,7 +85,7 @@ public function fromDateTime($value)
}

// Let Eloquent convert the value to a DateTime instance.
if (!$value instanceof DateTimeInterface) {
if (! $value instanceof DateTimeInterface) {
$value = parent::asDateTime($value);
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public function getTable()
*/
public function getAttribute($key)
{
if (!$key) {
if (! $key) {
return;
}

Expand All @@ -150,7 +150,7 @@ public function getAttribute($key)
}

// This checks for embedded relation support.
if (method_exists($this, $key) && !method_exists(self::class, $key)) {
if (method_exists($this, $key) && ! method_exists(self::class, $key)) {
return $this->getRelationValue($key);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ public function getCasts()
*/
public function originalIsEquivalent($key)
{
if (!array_key_exists($key, $this->original)) {
if (! array_key_exists($key, $this->original)) {
return false;
}

Expand Down Expand Up @@ -294,9 +294,9 @@ public function push()
$unique = false;

if (count($parameters) === 3) {
list($column, $values, $unique) = $parameters;
[$column, $values, $unique] = $parameters;
} else {
list($column, $values) = $parameters;
[$column, $values] = $parameters;
}

// Do batch push by default.
Expand Down Expand Up @@ -342,7 +342,7 @@ protected function pushAttributeValues($column, array $values, $unique = false)

foreach ($values as $value) {
// Don't add duplicate values when we only want unique values.
if ($unique && (!is_array($current) || in_array($value, $current))) {
if ($unique && (! is_array($current) || in_array($value, $current))) {
continue;
}

Expand Down Expand Up @@ -383,7 +383,7 @@ protected function pullAttributeValues($column, array $values)
*/
public function getForeignKey()
{
return Str::snake(class_basename($this)) . '_' . ltrim($this->primaryKey, '_');
return Str::snake(class_basename($this)).'_'.ltrim($this->primaryKey, '_');
}

/**
Expand Down Expand Up @@ -445,13 +445,13 @@ public function getQueueableRelations()

if ($relation instanceof QueueableCollection) {
foreach ($relation->getQueueableRelations() as $collectionValue) {
$relations[] = $key . '.' . $collectionValue;
$relations[] = $key.'.'.$collectionValue;
}
}

if ($relation instanceof QueueableEntity) {
foreach ($relation->getQueueableRelations() as $entityKey => $entityValue) {
$relations[] = $key . '.' . $entityValue;
$relations[] = $key.'.'.$entityValue;
}
}
}
Expand All @@ -476,7 +476,7 @@ protected function getRelationsWithoutParent()

/**
* Checks if column exists on a table. As this is a document model, just return true. This also
* prevents calls to non-existent function Grammar::compileColumnListing()
* prevents calls to non-existent function Grammar::compileColumnListing().
* @param string $key
* @return bool
*/
Expand Down
Loading