Commit 285ebda7 authored by Jens Segers's avatar Jens Segers

PSR-2 conversion

parent 2ae9c4d5
......@@ -117,7 +117,6 @@ Note that we did not tell Eloquent which collection to use for the `User` model.
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $collection = 'users_collection';
}
......@@ -129,7 +128,6 @@ class User extends Eloquent {
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class MyModel extends Eloquent {
protected $connection = 'mongodb';
}
......@@ -238,7 +236,6 @@ To solve this, you will need to check two things. First check if your model is e
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $connection = 'mongodb';
}
......@@ -533,7 +530,6 @@ Example:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $dates = array('birthday');
}
......@@ -758,7 +754,6 @@ Example SQL-based User model:
use Jenssegers\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $connection = 'mysql';
public function messages()
......@@ -775,7 +770,6 @@ And the Mongodb-based Message model:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Message extends Eloquent {
protected $connection = 'mongodb';
public function user()
......
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\HybridRelations;
abstract class Model extends \Illuminate\Database\Eloquent\Model {
abstract class Model extends \Illuminate\Database\Eloquent\Model
{
use HybridRelations;
}
......@@ -3,8 +3,8 @@
use DateTime;
use MongoDate;
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository {
class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository
{
/**
* Build the record payload for the table.
*
......@@ -26,20 +26,16 @@ class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRe
protected function tokenExpired($token)
{
// Convert MongoDate to a date string.
if ($token['created_at'] instanceof MongoDate)
{
if ($token['created_at'] instanceof MongoDate) {
$date = new DateTime;
$date->setTimestamp($token['created_at']->sec);
$token['created_at'] = $date->format('Y-m-d H:i:s');
}
elseif (is_array($token['created_at']) and isset($token['created_at']['date']))
{
$token['created_at'] = $token['created_at']['date'];
} elseif (is_array($token['created_at']) and isset($token['created_at']['date'])) {
$token['created_at'] = $token['created_at']['date'];
}
return parent::tokenExpired($token);
}
}
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Auth\DatabaseTokenRepository as DbRepository;
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider {
class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordResetServiceProvider
{
/**
* Register the token repository implementation.
*
......@@ -11,8 +11,7 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
*/
protected function registerTokenRepository()
{
$this->app->singleton('auth.password.tokens', function ($app)
{
$this->app->singleton('auth.password.tokens', function ($app) {
$connection = $app['db']->connection();
// The database token repository is an implementation of the token repository
......@@ -25,5 +24,4 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
return new DbRepository($connection, $table, $key, $expire);
});
}
}
......@@ -3,8 +3,8 @@
use Exception;
use MongoCollection;
class Collection {
class Collection
{
/**
* The connection instance.
*
......@@ -41,8 +41,7 @@ class Collection {
$result = call_user_func_array([$this->collection, $method], $parameters);
if ($this->connection->logging())
{
if ($this->connection->logging()) {
// Once we have run the query we will calculate the time that it took to run and
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
......@@ -51,14 +50,10 @@ class Collection {
$query = [];
// Convert the query paramters to a json string.
foreach ($parameters as $parameter)
{
try
{
foreach ($parameters as $parameter) {
try {
$query[] = json_encode($parameter);
}
catch (Exception $e)
{
} catch (Exception $e) {
$query[] = '{...}';
}
}
......@@ -70,5 +65,4 @@ class Collection {
return $result;
}
}
......@@ -2,8 +2,8 @@
use MongoClient;
class Connection extends \Illuminate\Database\Connection {
class Connection extends \Illuminate\Database\Connection
{
/**
* The MongoDB database handler.
*
......@@ -131,21 +131,18 @@ class Connection extends \Illuminate\Database\Connection {
{
// Add credentials as options, this makes sure the connection will not fail if
// the username or password contains strange characters.
if ( ! empty($config['username']))
{
if (! empty($config['username'])) {
$options['username'] = $config['username'];
}
if ( ! empty($config['password']))
{
if (! empty($config['password'])) {
$options['password'] = $config['password'];
}
// By default driver options is an empty array.
$driverOptions = [];
if (isset($config['driver_options']) && is_array($config['driver_options']))
{
if (isset($config['driver_options']) && is_array($config['driver_options'])) {
$driverOptions = $config['driver_options'];
}
......@@ -174,19 +171,16 @@ class Connection extends \Illuminate\Database\Connection {
extract($config);
// Check if the user passed a complete dsn to the configuration.
if ( ! empty($dsn))
{
if (! empty($dsn)) {
return $dsn;
}
// Treat host option as array of hosts
$hosts = is_array($host) ? $host : [$host];
foreach ($hosts as &$host)
{
foreach ($hosts as &$host) {
// Check if we need to add a port to the host
if (strpos($host, ':') === false and isset($port))
{
if (strpos($host, ':') === false and isset($port)) {
$host = "{$host}:{$port}";
}
}
......@@ -228,5 +222,4 @@ class Connection extends \Illuminate\Database\Connection {
{
return call_user_func_array([$this->db, $method], $parameters);
}
}
......@@ -4,8 +4,8 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use MongoCursor;
class Builder extends EloquentBuilder {
class Builder extends EloquentBuilder
{
/**
* The methods that should be returned from query builder.
*
......@@ -26,8 +26,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$relation->performUpdate($this->model, $values);
return 1;
......@@ -46,8 +45,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$relation->performInsert($this->model, $values);
return true;
......@@ -67,8 +65,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$relation->performInsert($this->model, $values);
return $this->model->getKey();
......@@ -86,8 +83,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$relation->performDelete($this->model);
return $this->model->getKey();
......@@ -108,8 +104,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$value = $this->model->{$column};
// When doing increment and decrements, Eloquent will automatically
......@@ -139,8 +134,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if ($relation = $this->model->getParentRelation())
{
if ($relation = $this->model->getParentRelation()) {
$value = $this->model->{$column};
// When doing increment and decrements, Eloquent will automatically
......@@ -174,13 +168,13 @@ class Builder extends EloquentBuilder {
$relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator)
{
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
// If we are comparing to 0, we always need all results.
if ($count == 0) return true;
if ($count == 0) {
return true;
}
switch ($operator)
{
switch ($operator) {
case '>=':
case '<':
return $counted >= $count;
......@@ -197,7 +191,9 @@ class Builder extends EloquentBuilder {
$not = in_array($operator, ['<', '<=', '!=']);
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) $not = !$not;
if ($count == 0) {
$not = !$not;
}
// All related ids.
$relatedIds = array_keys($relationCount);
......@@ -218,16 +214,14 @@ class Builder extends EloquentBuilder {
$results = $this->query->raw($expression);
// Convert MongoCursor results to a collection of models.
if ($results instanceof MongoCursor)
{
if ($results instanceof MongoCursor) {
$results = iterator_to_array($results, false);
return $this->model->hydrate($results);
}
// The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results))
{
elseif (is_array($results) and array_key_exists('_id', $results)) {
$model = $this->model->newFromBuilder($results);
$model->setConnection($this->model->getConnection());
......@@ -237,5 +231,4 @@ class Builder extends EloquentBuilder {
return $results;
}
}
......@@ -2,8 +2,8 @@
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
class Collection extends EloquentCollection {
class Collection extends EloquentCollection
{
/**
* Simulate a get clause on the collection.
*
......@@ -13,8 +13,7 @@ class Collection extends EloquentCollection {
*/
public function get($key = null, $default = null)
{
if (is_null($key) and is_null($default))
{
if (is_null($key) and is_null($default)) {
return $this;
}
......@@ -35,17 +34,14 @@ class Collection extends EloquentCollection {
// Here we will make some assumptions about the operator. If only 2 values are
// passed to the method, we will assume that the operator is an equals sign
// and keep going.
if (func_num_args() == 2)
{
if (func_num_args() == 2) {
list($value, $operator) = [$operator, '='];
}
return $this->filter(function ($item) use ($key, $operator, $value)
{
return $this->filter(function ($item) use ($key, $operator, $value) {
$actual = $item->{$key};
switch ($operator)
{
switch ($operator) {
case '<>':
case '!=':
return $actual != $value;
......@@ -244,5 +240,4 @@ class Collection extends EloquentCollection {
{
return $this->take($value);
}
}
......@@ -3,15 +3,14 @@
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Relations\BelongsTo;
use Jenssegers\Mongodb\Relations\BelongsToMany;
use Jenssegers\Mongodb\Relations\HasMany;
use Jenssegers\Mongodb\Relations\HasOne;
use Jenssegers\Mongodb\Relations\MorphTo;
trait HybridRelations {
trait HybridRelations
{
/**
* Define a one-to-one relationship.
*
......@@ -23,8 +22,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'))
{
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
return parent::hasOne($related, $foreignKey, $localKey);
}
......@@ -50,9 +48,8 @@ trait HybridRelations {
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'))
{
return parent::morphOne($related, $name, $type, $id, $localKey );
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
return parent::morphOne($related, $name, $type, $id, $localKey);
}
$instance = new $related;
......@@ -77,8 +74,7 @@ trait HybridRelations {
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'))
{
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
return parent::hasMany($related, $foreignKey, $localKey);
}
......@@ -104,8 +100,7 @@ trait HybridRelations {
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'))
{
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
return parent::morphMany($related, $name, $type, $id, $localKey);
}
......@@ -137,24 +132,21 @@ trait HybridRelations {
// If no relation name was given, we will use this debug backtrace to extract
// 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 (is_null($relation))
{
if (is_null($relation)) {
list($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'))
{
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
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 (is_null($foreignKey))
{
if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation) . '_id';
}
......@@ -183,8 +175,7 @@ trait HybridRelations {
// If no name is provided, we will use the backtrace to get the function name
// 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 (is_null($name))
{
if (is_null($name)) {
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$name = Str::snake($caller['function']);
......@@ -195,8 +186,7 @@ trait HybridRelations {
// 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
// there are multiple types in the morph and we can't use single queries.
if (is_null($class = $this->$type))
{
if (is_null($class = $this->$type)) {
return new MorphTo(
$this->newQuery(), $this, $id, null, $type, $name
);
......@@ -205,8 +195,7 @@ trait HybridRelations {
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else
{
else {
$class = $this->getActualClassNameForMorph($class);
$instance = new $class;
......@@ -232,14 +221,12 @@ trait HybridRelations {
// 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.
if (is_null($relation))
{
if (is_null($relation)) {
$relation = $this->getBelongsToManyCaller();
}
// Check if it is a relation with an original model.
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model'))
{
if (! is_subclass_of($related, 'Jenssegers\Mongodb\Eloquent\Model')) {
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
}
......@@ -255,8 +242,7 @@ trait HybridRelations {
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($collection))
{
if (is_null($collection)) {
$collection = $instance->getTable();
}
......@@ -267,5 +253,4 @@ trait HybridRelations {
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation);
}
}
This diff is collapsed.
<?php namespace Jenssegers\Mongodb\Eloquent;
trait SoftDeletes {
trait SoftDeletes
{
use \Illuminate\Database\Eloquent\SoftDeletes;
/**
......@@ -13,5 +13,4 @@ trait SoftDeletes {
{
return $this->getDeletedAtColumn();
}
}
......@@ -2,6 +2,6 @@
use Jenssegers\Mongodb\Eloquent\Model as BaseModel;
abstract class Model extends BaseModel {
abstract class Model extends BaseModel
{
}
......@@ -2,8 +2,8 @@
use Illuminate\Support\ServiceProvider;
class MongodbServiceProvider extends ServiceProvider {
class MongodbServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*/
......@@ -19,13 +19,10 @@ class MongodbServiceProvider extends ServiceProvider {
*/
public function register()
{
$this->app->resolving('db', function ($db)
{
$db->extend('mongodb', function ($config)
{
$this->app->resolving('db', function ($db) {
$db->extend('mongodb', function ($config) {
return new Connection($config);
});
});
}
}
This diff is collapsed.
......@@ -2,6 +2,6 @@
use Illuminate\Database\Query\Processors\Processor as BaseProcessor;
class Processor extends BaseProcessor {
class Processor extends BaseProcessor
{
}
<?php namespace Jenssegers\Mongodb\Relations;
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
{
/**
* Set the base constraints on the relation query.
*/
public function addConstraints()
{
if (static::$constraints)
{
if (static::$constraints) {
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
......@@ -30,5 +29,4 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
$this->query->whereIn($key, $this->getEagerModelKeys($models));
}
}
......@@ -4,8 +4,8 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
class BelongsToMany extends EloquentBelongsToMany {
class BelongsToMany extends EloquentBelongsToMany
{
/**
* Hydrate the pivot table relationship on the models.
*
......@@ -32,7 +32,9 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
public function addConstraints()
{
if (static::$constraints) $this->setWhere();
if (static::$constraints) {
$this->setWhere();
}
}
/**
......@@ -101,7 +103,9 @@ class BelongsToMany extends EloquentBelongsToMany {
'attached' => [], 'detached' => [], 'updated' => [],
];
if ($ids instanceof Collection) $ids = $ids->modelKeys();
if ($ids instanceof Collection) {
$ids = $ids->modelKeys();
}
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
......@@ -109,7 +113,9 @@ class BelongsToMany extends EloquentBelongsToMany {
$current = $this->parent->{$this->otherKey} ?: [];
// See issue #256.
if ($current instanceof Collection) $current = $ids->modelKeys();
if ($current instanceof Collection) {
$current = $ids->modelKeys();
}
$records = $this->formatSyncList($ids);
......@@ -122,11 +128,10 @@ class BelongsToMany extends EloquentBelongsToMany {
// Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the
// the array of the IDs given to the method which will complete the sync.
if ($detaching and count($detach) > 0)
{
if ($detaching and count($detach) > 0) {
$this->detach($detach);
$changes['detached'] = (array) array_map(function ($v) {
$changes['detached'] = (array) array_map(function ($v) {
return is_numeric($v) ? (int) $v : (string) $v;
}, $detach);
}
......@@ -138,8 +143,7 @@ class BelongsToMany extends EloquentBelongsToMany {
$changes, $this->attachNew($records, $current, false)
);
if (count($changes['attached']) || count($changes['updated']))
{
if (count($changes['attached']) || count($changes['updated'])) {
$this->touchIfTouching();
}
......@@ -167,17 +171,14 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
public function attach($id, array $attributes = [], $touch = true)
{
if ($id instanceof Model)
{
if ($id instanceof Model) {
$model = $id;
$id = $model->getKey();
// Attach the new parent id to the related model.
$model->push($this->foreignKey, $this->parent->getKey(), true);
}
else
{
} else {
$query = $this->newRelatedQuery();
$query->whereIn($this->related->getKeyName(), (array) $id);
......@@ -189,7 +190,9 @@ class BelongsToMany extends EloquentBelongsToMany {
// Attach the new ids to the parent model.
$this->parent->push($this->otherKey, (array) $id, true);
if ($touch) $this->touchIfTouching();
if ($touch) {
$this->touchIfTouching();
}
}
/**
......@@ -201,7 +204,9 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
public function detach($ids = [], $touch = true)
{
if ($ids instanceof Model) $ids = (array) $ids->getKey();
if ($ids instanceof Model) {
$ids = (array) $ids->getKey();
}
$query = $this->newRelatedQuery();
......@@ -214,15 +219,16 @@ class BelongsToMany extends EloquentBelongsToMany {
$this->parent->pull($this->otherKey, $ids);
// Prepare the query to select all related objects.
if (count($ids) > 0)
{
if (count($ids) > 0) {
$query->whereIn($this->related->getKeyName(), $ids);
}
// Remove the relation to the parent.
$query->pull($this->foreignKey, $this->parent->getKey());
if ($touch) $this->touchIfTouching();
if ($touch) {
$this->touchIfTouching();
}
return count($ids);
}
......@@ -242,10 +248,8 @@ class BelongsToMany extends EloquentBelongsToMany {
// parents without having a possibly slow inner loops for every models.
$dictionary = [];
foreach ($results as $result)
{
foreach ($result->$foreign as $item)
{
foreach ($results as $result) {
foreach ($result->$foreign as $item) {
$dictionary[$item][] = $result;
}
}
......
......@@ -5,8 +5,8 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use MongoId;
class EmbedsMany extends EmbedsOneOrMany {
class EmbedsMany extends EmbedsOneOrMany
{
/**
* Get the results of the relationship.
*
......@@ -26,14 +26,12 @@ class EmbedsMany extends EmbedsOneOrMany {
public function performInsert(Model $model)
{
// Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey())
{
if ($model->getKeyName() == '_id' and ! $model->getKey()) {
$model->setAttribute('_id', new MongoId);
}
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested())
{
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
......@@ -43,7 +41,9 @@ class EmbedsMany extends EmbedsOneOrMany {
$result = $this->getBaseQuery()->push($this->localKey, $model->getAttributes(), true);
// Attach the model to its parent.
if ($result) $this->associate($model);
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
......@@ -57,8 +57,7 @@ class EmbedsMany extends EmbedsOneOrMany {
public function performUpdate(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested())
{
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
......@@ -75,7 +74,9 @@ class EmbedsMany extends EmbedsOneOrMany {
->update($values);
// Attach the model to its parent.
if ($result) $this->associate($model);
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
......@@ -89,8 +90,7 @@ class EmbedsMany extends EmbedsOneOrMany {
public function performDelete(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested())
{
if ($this->isNested()) {
$this->dissociate($model);
return $this->parent->save();
......@@ -101,7 +101,9 @@ class EmbedsMany extends EmbedsOneOrMany {
$result = $this->getBaseQuery()->pull($this->localKey, [$model->getKeyName() => $foreignKey]);
if ($result) $this->dissociate($model);
if ($result) {
$this->dissociate($model);
}
return $result;
}
......@@ -114,12 +116,9 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
public function associate(Model $model)
{
if ( ! $this->contains($model))
{
if (! $this->contains($model)) {
return $this->associateNew($model);
}
else
{
} else {
return $this->associateExisting($model);
}
}
......@@ -139,10 +138,8 @@ class EmbedsMany extends EmbedsOneOrMany {
$primaryKey = $this->related->getKeyName();
// Remove the document from the parent model.
foreach ($records as $i => $record)
{
if (in_array($record[$primaryKey], $ids))
{
foreach ($records as $i => $record) {
if (in_array($record[$primaryKey], $ids)) {
unset($records[$i]);
}
}
......@@ -171,9 +168,10 @@ class EmbedsMany extends EmbedsOneOrMany {
$models = $this->getResults()->only($ids);
// Pull the documents from the database.
foreach ($models as $model)
{
if ($model->delete()) $count++;
foreach ($models as $model) {
if ($model->delete()) {
$count++;
}
}
return $count;
......@@ -189,7 +187,9 @@ class EmbedsMany extends EmbedsOneOrMany {
// Overwrite the local key with an empty array.
$result = $this->query->update([$this->localKey => []]);
if ($result) $this->setEmbedded([]);
if ($result) {
$this->setEmbedded([]);
}
return $result;
}
......@@ -225,8 +225,7 @@ class EmbedsMany extends EmbedsOneOrMany {
protected function associateNew($model)
{
// Create a new key if needed.
if ( ! $model->getAttribute('_id'))
{
if (! $model->getAttribute('_id')) {
$model->setAttribute('_id', new MongoId);
}
......@@ -254,10 +253,8 @@ class EmbedsMany extends EmbedsOneOrMany {
$key = $model->getKey();
// Replace the document in the parent model.
foreach ($records as &$record)
{
if ($record[$primaryKey] == $key)
{
foreach ($records as &$record) {
if ($record[$primaryKey] == $key) {
$record = $model->getAttributes();
break;
}
......@@ -306,7 +303,9 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
protected function setEmbedded($models)
{
if ( ! is_array($models)) $models = [$models];
if (! is_array($models)) {
$models = [$models];
}
return parent::setEmbedded(array_values($models));
}
......@@ -321,12 +320,10 @@ class EmbedsMany extends EmbedsOneOrMany {
public function __call($method, $parameters)
{
// Collection methods
if (method_exists('Jenssegers\Mongodb\Eloquent\Collection', $method))
{
if (method_exists('Jenssegers\Mongodb\Eloquent\Collection', $method)) {
return call_user_func_array([$this->getResults(), $method], $parameters);
}
return parent::__call($method, $parameters);
}
}
......@@ -3,8 +3,8 @@
use Illuminate\Database\Eloquent\Model;
use MongoId;
class EmbedsOne extends EmbedsOneOrMany {
class EmbedsOne extends EmbedsOneOrMany
{
/**
* Get the results of the relationship.
*
......@@ -24,14 +24,12 @@ class EmbedsOne extends EmbedsOneOrMany {
public function performInsert(Model $model)
{
// Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey())
{
if ($model->getKeyName() == '_id' and ! $model->getKey()) {
$model->setAttribute('_id', new MongoId);
}
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested())
{
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
......@@ -40,7 +38,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]);
// Attach the model to its parent.
if ($result) $this->associate($model);
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
......@@ -53,8 +53,7 @@ class EmbedsOne extends EmbedsOneOrMany {
*/
public function performUpdate(Model $model)
{
if ($this->isNested())
{
if ($this->isNested()) {
$this->associate($model);
return $this->parent->save();
......@@ -66,7 +65,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result = $this->getBaseQuery()->update($values);
// Attach the model to its parent.
if ($result) $this->associate($model);
if ($result) {
$this->associate($model);
}
return $result ? $model : false;
}
......@@ -80,8 +81,7 @@ class EmbedsOne extends EmbedsOneOrMany {
public function performDelete(Model $model)
{
// For deeply nested documents, let the parent handle the changes.
if ($this->isNested())
{
if ($this->isNested()) {
$this->dissociate($model);
return $this->parent->save();
......@@ -91,7 +91,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result = $this->getBaseQuery()->update([$this->localKey => null]);
// Detach the model from its parent.
if ($result) $this->dissociate();
if ($result) {
$this->dissociate();
}
return $result;
}
......@@ -128,5 +130,4 @@ class EmbedsOne extends EmbedsOneOrMany {
return $this->performDelete($model);
}
}
......@@ -6,8 +6,8 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\Eloquent\Collection;
abstract class EmbedsOneOrMany extends Relation {
abstract class EmbedsOneOrMany extends Relation
{
/**
* The local key of the parent model.
*
......@@ -49,8 +49,7 @@ abstract class EmbedsOneOrMany extends Relation {
$this->relation = $relation;
// If this is a nested relation, we need to get the parent query instead.
if ($parentRelation = $this->getParentRelation())
{
if ($parentRelation = $this->getParentRelation()) {
$this->query = $parentRelation->getQuery();
}
......@@ -62,8 +61,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public function addConstraints()
{
if (static::$constraints)
{
if (static::$constraints) {
$this->query->where($this->getQualifiedParentKeyName(), '=', $this->getParentKey());
}
}
......@@ -86,8 +84,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public function initRelation(array $models, $relation)
{
foreach ($models as $model)
{
foreach ($models as $model) {
$model->setParentRelation($this);
$model->setRelation($relation, $this->related->newCollection());
......@@ -106,8 +103,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public function match(array $models, BaseCollection $results, $relation)
{
foreach ($models as $model)
{
foreach ($models as $model) {
$results = $model->$relation()->getResults();
$model->setParentRelation($this);
......@@ -196,8 +192,7 @@ abstract class EmbedsOneOrMany extends Relation {
{
$instances = [];
foreach ($records as $record)
{
foreach ($records as $record) {
$instances[] = $this->create($record);
}
......@@ -212,16 +207,18 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected function getIdsArrayFrom($ids)
{
if ($ids instanceof Collection)
{
if ($ids instanceof Collection) {
$ids = $ids->all();
}
if ( ! is_array($ids)) $ids = [$ids];
if (! is_array($ids)) {
$ids = [$ids];
}
foreach ($ids as &$id)
{
if ($id instanceof Model) $id = $id->getKey();
foreach ($ids as &$id) {
if ($id instanceof Model) {
$id = $id->getKey();
}
}
return $ids;
......@@ -267,8 +264,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected function getForeignKeyValue($id)
{
if ($id instanceof Model)
{
if ($id instanceof Model) {
$id = $id->getKey();
}
......@@ -286,13 +282,11 @@ abstract class EmbedsOneOrMany extends Relation {
{
$models = [];
foreach ($records as $attributes)
{
foreach ($records as $attributes) {
$models[] = $this->toModel($attributes);
}
if (count($models) > 0)
{
if (count($models) > 0) {
$models = $this->eagerLoadRelations($models);
}
......@@ -307,7 +301,9 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected function toModel($attributes = [])
{
if (is_null($attributes)) return;
if (is_null($attributes)) {
return;
}
$model = $this->related->newFromBuilder((array) $attributes);
......@@ -373,8 +369,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected function getPathHierarchy($glue = '.')
{
if ($parentRelation = $this->getParentRelation())
{
if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy($glue) . $glue . $this->localKey;
}
......@@ -388,8 +383,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public function getQualifiedParentKeyName()
{
if ($parentRelation = $this->getParentRelation())
{
if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy() . '.' . $this->parent->getKeyName();
}
......@@ -405,5 +399,4 @@ abstract class EmbedsOneOrMany extends Relation {
{
return $this->parent->getKey();
}
}
......@@ -3,8 +3,8 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
class HasMany extends EloquentHasMany {
class HasMany extends EloquentHasMany
{
/**
* Add the constraints for a relationship count query.
*
......@@ -28,5 +28,4 @@ class HasMany extends EloquentHasMany {
{
return $this->getForeignKey();
}
}
......@@ -3,8 +3,8 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
class HasOne extends EloquentHasOne {
class HasOne extends EloquentHasOne
{
/**
* Add the constraints for a relationship count query.
*
......@@ -28,5 +28,4 @@ class HasOne extends EloquentHasOne {
{
return $this->getForeignKey();
}
}
......@@ -2,15 +2,14 @@
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
class MorphTo extends EloquentMorphTo {
class MorphTo extends EloquentMorphTo
{
/**
* Set the base constraints on the relation query.
*/
public function addConstraints()
{
if (static::$constraints)
{
if (static::$constraints) {
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
......@@ -36,5 +35,4 @@ class MorphTo extends EloquentMorphTo {
return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
}
}
......@@ -3,8 +3,8 @@
use Closure;
use Illuminate\Database\Connection;
class Blueprint extends \Illuminate\Database\Schema\Blueprint {
class Blueprint extends \Illuminate\Database\Schema\Blueprint
{
/**
* The MongoConnection object for this blueprint.
*
......@@ -51,13 +51,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
$columns = $this->fluent($columns);
// Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns)))
{
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = [];
foreach ($columns as $column)
{
foreach ($columns as $column) {
$transform[$column] = 1;
}
......@@ -92,13 +90,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
$columns = $this->fluent($columns);
// Columns are passed as a default array.
if (is_array($columns) && is_int(key($columns)))
{
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = [];
foreach ($columns as $column)
{
foreach ($columns as $column) {
$transform[$column] = 1;
}
......@@ -226,16 +222,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
*/
protected function fluent($columns = null)
{
if (is_null($columns))
{
if (is_null($columns)) {
return $this->columns;
}
elseif (is_string($columns))
{
} elseif (is_string($columns)) {
return $this->columns = [$columns];
}
else
{
} else {
return $this->columns = $columns;
}
}
......@@ -250,5 +241,4 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
// Dummy.
return $this;
}
}
......@@ -3,8 +3,8 @@
use Closure;
use Jenssegers\Mongodb\Connection;
class Builder extends \Illuminate\Database\Schema\Builder {
class Builder extends \Illuminate\Database\Schema\Builder
{
/**
* Create a new database Schema manager.
*
......@@ -73,8 +73,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
$blueprint = $this->createBlueprint($collection);
if ($callback)
{
if ($callback) {
$callback($blueprint);
}
}
......@@ -104,8 +103,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
$blueprint->create();
if ($callback)
{
if ($callback) {
$callback($blueprint);
}
}
......@@ -133,5 +131,4 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
return new Blueprint($this->connection, $collection);
}
}
......@@ -2,7 +2,8 @@
use Illuminate\Auth\Passwords\PasswordBroker;
class AuthTest extends TestCase {
class AuthTest extends TestCase
{
public function tearDown()
{
......@@ -52,8 +53,7 @@ class AuthTest extends TestCase {
'token' => $reminder['token'],
];
$response = $broker->reset($credentials, function ($user, $password)
{
$response = $broker->reset($credentials, function ($user, $password) {
$user->password = bcrypt($password);
$user->save();
});
......@@ -61,5 +61,4 @@ class AuthTest extends TestCase {
$this->assertEquals('passwords.reset', $response);
$this->assertEquals(0, DB::collection('password_resets')->count());
}
}
<?php
class ConnectionTest extends TestCase {
class ConnectionTest extends TestCase
{
public function testConnection()
{
......@@ -129,5 +130,4 @@ class ConnectionTest extends TestCase {
$this->setExpectedException('MongoConnectionException', "Failed to connect to: " . $hosts[0] . ": Connection refused; Failed to connect to: " . $hosts[1] . ": Connection refused");
$connection = DB::connection('mongodb');
}
}
<?php
class EmbeddedRelationsTest extends TestCase {
class EmbeddedRelationsTest extends TestCase
{
public function tearDown()
{
......@@ -748,5 +749,4 @@ class EmbeddedRelationsTest extends TestCase {
$this->assertEquals(2, $results->count());
$this->assertEquals(3, $results->total());
}
}
<?php
class ModelTest extends TestCase {
class ModelTest extends TestCase
{
public function tearDown()
{
......@@ -331,7 +332,8 @@ class ModelTest extends TestCase {
$item = Item::create(['name' => 'fork', 'type' => 'sharp']);
$array = $item->toArray();
$keys = array_keys($array); sort($keys);
$keys = array_keys($array);
sort($keys);
$this->assertEquals(['_id', 'created_at', 'name', 'type', 'updated_at'], $keys);
$this->assertTrue(is_string($array['created_at']));
$this->assertTrue(is_string($array['updated_at']));
......@@ -449,27 +451,23 @@ class ModelTest extends TestCase {
User::create(['name' => 'Jane Doe', 'age' => 35]);
User::create(['name' => 'Harry Hoe', 'age' => 15]);
$users = User::raw(function ($collection)
{
$users = User::raw(function ($collection) {
return $collection->find(['age' => 35]);
});
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $users);
$this->assertInstanceOf('Jenssegers\Mongodb\Eloquent\Model', $users[0]);
$user = User::raw(function ($collection)
{
$user = User::raw(function ($collection) {
return $collection->findOne(['age' => 35]);
});
$this->assertInstanceOf('Jenssegers\Mongodb\Eloquent\Model', $user);
$count = User::raw(function ($collection)
{
$count = User::raw(function ($collection) {
return $collection->count();
});
$this->assertEquals(3, $count);
$result = User::raw(function ($collection)
{
$result = User::raw(function ($collection) {
return $collection->insert(['name' => 'Yvonne Yoe', 'age' => 35]);
});
$this->assertTrue(is_array($result));
......@@ -499,5 +497,4 @@ class ModelTest extends TestCase {
$user->birthday = new DateTime('19 august 1989');
$this->assertEmpty($user->getDirty());
}
}
<?php
class MysqlRelationsTest extends TestCase {
class MysqlRelationsTest extends TestCase
{
public function setUp()
{
......
<?php
class QueryBuilderTest extends TestCase {
class QueryBuilderTest extends TestCase
{
public function tearDown()
{
......@@ -179,8 +180,7 @@ class QueryBuilderTest extends TestCase {
['name' => 'John Doe', 'age' => 25],
]);
$cursor = DB::collection('users')->raw(function ($collection)
{
$cursor = DB::collection('users')->raw(function ($collection) {
return $collection->find(['age' => 20]);
});
......@@ -286,11 +286,13 @@ class QueryBuilderTest extends TestCase {
['name' => 'spoon', 'type' => 'round'],
]);
$items = DB::collection('items')->distinct('name')->get(); sort($items);
$items = DB::collection('items')->distinct('name')->get();
sort($items);
$this->assertEquals(3, count($items));
$this->assertEquals(['fork', 'knife', 'spoon'], $items);
$types = DB::collection('items')->distinct('type')->get(); sort($types);
$types = DB::collection('items')->distinct('type')->get();
sort($types);
$this->assertEquals(2, count($types));
$this->assertEquals(['round', 'sharp'], $types);
}
......@@ -635,10 +637,8 @@ class QueryBuilderTest extends TestCase {
$results = DB::collection('items')->project(['tags' => ['$slice' => 1]])->get();
foreach ($results as $result)
{
foreach ($results as $result) {
$this->assertEquals(1, count($result['tags']));
}
}
}
<?php
class QueryTest extends TestCase {
class QueryTest extends TestCase
{
protected static $started = false;
public function setUp()
......@@ -214,8 +214,7 @@ class QueryTest extends TestCase {
public function testSubquery()
{
$users = User::where('title', 'admin')->orWhere(function ($query)
{
$users = User::where('title', 'admin')->orWhere(function ($query) {
$query->where('name', 'Tommy Toe')
->orWhere('name', 'Error');
})
......@@ -223,8 +222,7 @@ class QueryTest extends TestCase {
$this->assertEquals(5, count($users));
$users = User::where('title', 'user')->where(function ($query)
{
$users = User::where('title', 'user')->where(function ($query) {
$query->where('age', 35)
->orWhere('name', 'like', '%harry%');
})
......@@ -232,8 +230,7 @@ class QueryTest extends TestCase {
$this->assertEquals(2, count($users));
$users = User::where('age', 35)->orWhere(function ($query)
{
$users = User::where('age', 35)->orWhere(function ($query) {
$query->where('title', 'admin')
->orWhere('name', 'Error');
})
......@@ -243,8 +240,7 @@ class QueryTest extends TestCase {
$users = User::whereNull('deleted_at')
->where('title', 'admin')
->where(function ($query)
{
->where(function ($query) {
$query->where('age', '>', 15)
->orWhere('name', 'Harry Hoe');
})
......@@ -253,11 +249,9 @@ class QueryTest extends TestCase {
$this->assertEquals(3, $users->count());
$users = User::whereNull('deleted_at')
->where(function ($query)
{
->where(function ($query) {
$query->where('name', 'Harry Hoe')
->orWhere(function ($query)
{
->orWhere(function ($query) {
$query->where('age', '>', 15)
->where('title', '<>', 'admin');
});
......@@ -283,23 +277,19 @@ class QueryTest extends TestCase {
public function testMultipleOr()
{
$users = User::where(function ($query)
{
$users = User::where(function ($query) {
$query->where('age', 35)->orWhere('age', 33);
})
->where(function ($query)
{
->where(function ($query) {
$query->where('name', 'John Doe')->orWhere('name', 'Jane Doe');
})->get();
$this->assertEquals(2, count($users));
$users = User::where(function ($query)
{
$users = User::where(function ($query) {
$query->orWhere('age', 35)->orWhere('age', 33);
})
->where(function ($query)
{
->where(function ($query) {
$query->orWhere('name', 'John Doe')->orWhere('name', 'Jane Doe');
})->get();
......@@ -319,5 +309,4 @@ class QueryTest extends TestCase {
$this->assertEquals(9, $results->total());
$this->assertEquals(1, $results->currentPage());
}
}
<?php
class RelationsTest extends TestCase {
class RelationsTest extends TestCase
{
public function tearDown()
{
......@@ -410,15 +411,13 @@ class RelationsTest extends TestCase {
$authors = User::has('books', '!=', 0)->get();
$this->assertCount(2, $authors);
$authors = User::whereHas('books', function ($query)
{
$authors = User::whereHas('books', function ($query) {
$query->where('rating', 5);
})->get();
$this->assertCount(1, $authors);
$authors = User::whereHas('books', function ($query)
{
$authors = User::whereHas('books', function ($query) {
$query->where('rating', '<', 5);
})->get();
......@@ -521,5 +520,4 @@ class RelationsTest extends TestCase {
$this->assertEquals([$user->_id], $client->user_ids);
$this->assertEquals([$client->_id], $user->client_ids);
}
}
<?php
class SchemaTest extends TestCase {
class SchemaTest extends TestCase
{
public function tearDown()
{
......@@ -18,8 +19,7 @@ class SchemaTest extends TestCase {
{
$instance = $this;
Schema::create('newcollection', function ($collection) use ($instance)
{
Schema::create('newcollection', function ($collection) use ($instance) {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
});
......@@ -37,37 +37,32 @@ class SchemaTest extends TestCase {
{
$instance = $this;
Schema::collection('newcollection', function ($collection) use ($instance)
{
Schema::collection('newcollection', function ($collection) use ($instance) {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
});
Schema::table('newcollection', function ($collection) use ($instance)
{
Schema::table('newcollection', function ($collection) use ($instance) {
$instance->assertInstanceOf('Jenssegers\Mongodb\Schema\Blueprint', $collection);
});
}
public function testIndex()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->index('mykey1');
});
$index = $this->getIndex('newcollection', 'mykey1');
$this->assertEquals(1, $index['key']['mykey1']);
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->index(['mykey2']);
});
$index = $this->getIndex('newcollection', 'mykey2');
$this->assertEquals(1, $index['key']['mykey2']);
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->string('mykey3')->index();
});
......@@ -77,8 +72,7 @@ class SchemaTest extends TestCase {
public function testPrimary()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->string('mykey', 100)->primary();
});
......@@ -88,8 +82,7 @@ class SchemaTest extends TestCase {
public function testUnique()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->unique('uniquekey');
});
......@@ -99,8 +92,7 @@ class SchemaTest extends TestCase {
public function testDropIndex()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->unique('uniquekey');
$collection->dropIndex('uniquekey');
});
......@@ -108,8 +100,7 @@ class SchemaTest extends TestCase {
$index = $this->getIndex('newcollection', 'uniquekey');
$this->assertEquals(null, $index);
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->unique('uniquekey');
$collection->dropIndex(['uniquekey']);
});
......@@ -120,8 +111,7 @@ class SchemaTest extends TestCase {
public function testBackground()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->background('backgroundkey');
});
......@@ -131,8 +121,7 @@ class SchemaTest extends TestCase {
public function testSparse()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->sparse('sparsekey');
});
......@@ -142,8 +131,7 @@ class SchemaTest extends TestCase {
public function testExpire()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->expire('expirekey', 60);
});
......@@ -153,13 +141,11 @@ class SchemaTest extends TestCase {
public function testSoftDeletes()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->softDeletes();
});
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->string('email')->nullable()->index();
});
......@@ -169,8 +155,7 @@ class SchemaTest extends TestCase {
public function testFluent()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->string('email')->index();
$collection->string('token')->index();
$collection->timestamp('created_at');
......@@ -185,8 +170,7 @@ class SchemaTest extends TestCase {
public function testDummies()
{
Schema::collection('newcollection', function ($collection)
{
Schema::collection('newcollection', function ($collection) {
$collection->boolean('activated')->default(0);
$collection->integer('user_id')->unsigned();
});
......@@ -196,12 +180,12 @@ class SchemaTest extends TestCase {
{
$collection = DB::getCollection($collection);
foreach ($collection->getIndexInfo() as $index)
{
if (isset($index['key'][$name])) return $index;
foreach ($collection->getIndexInfo() as $index) {
if (isset($index['key'][$name])) {
return $index;
}
}
return false;
}
}
<?php
class SeederTest extends TestCase {
class SeederTest extends TestCase
{
public function tearDown()
{
......@@ -23,5 +24,4 @@ class SeederTest extends TestCase {
$user = User::where('name', 'John Doe')->first();
$this->assertTrue($user->seed);
}
}
<?php
class TestCase extends Orchestra\Testbench\TestCase {
class TestCase extends Orchestra\Testbench\TestCase
{
/**
* Get package providers.
*
......@@ -36,5 +36,4 @@ class TestCase extends Orchestra\Testbench\TestCase {
$app['config']->set('auth.model', 'User');
$app['config']->set('cache.driver', 'array');
}
}
<?php
class ValidationTest extends TestCase {
class ValidationTest extends TestCase
{
public function tearDown()
{
......@@ -23,5 +24,4 @@ class ValidationTest extends TestCase {
);
$this->assertTrue($validator->fails());
}
}
......@@ -2,13 +2,12 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Address extends Eloquent {
class Address extends Eloquent
{
protected static $unguarded = true;
public function addresses()
{
return $this->embedsMany('Address');
}
}
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Book extends Eloquent {
class Book extends Eloquent
{
protected $collection = 'books';
protected static $unguarded = true;
protected $primaryKey = 'title';
......
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Client extends Eloquent {
class Client extends Eloquent
{
protected $collection = 'clients';
protected static $unguarded = true;
......
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Group extends Eloquent {
class Group extends Eloquent
{
protected $collection = 'groups';
protected static $unguarded = true;
......
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Item extends Eloquent {
class Item extends Eloquent
{
protected $collection = 'items';
protected static $unguarded = true;
......@@ -16,5 +16,4 @@ class Item extends Eloquent {
{
return $query->where('type', 'sharp');
}
}
......@@ -3,8 +3,8 @@
use \Illuminate\Support\Facades\Schema;
use Jenssegers\Eloquent\Model as Eloquent;
class MysqlBook extends Eloquent {
class MysqlBook extends Eloquent
{
protected $connection = 'mysql';
protected $table = 'books';
protected static $unguarded = true;
......@@ -23,15 +23,12 @@ class MysqlBook extends Eloquent {
{
$schema = Schema::connection('mysql');
if (!$schema->hasTable('books'))
{
Schema::connection('mysql')->create('books', function ($table)
{
if (!$schema->hasTable('books')) {
Schema::connection('mysql')->create('books', function ($table) {
$table->string('title');
$table->string('author_id');
$table->timestamps();
});
}
}
}
......@@ -3,8 +3,8 @@
use \Illuminate\Support\Facades\Schema;
use Jenssegers\Eloquent\Model as Eloquent;
class MysqlRole extends Eloquent {
class MysqlRole extends Eloquent
{
protected $connection = 'mysql';
protected $table = 'roles';
protected static $unguarded = true;
......@@ -27,15 +27,12 @@ class MysqlRole extends Eloquent {
{
$schema = Schema::connection('mysql');
if (!$schema->hasTable('roles'))
{
Schema::connection('mysql')->create('roles', function ($table)
{
if (!$schema->hasTable('roles')) {
Schema::connection('mysql')->create('roles', function ($table) {
$table->string('type');
$table->string('user_id');
$table->timestamps();
});
}
}
}
......@@ -3,8 +3,8 @@
use \Illuminate\Support\Facades\Schema;
use Jenssegers\Eloquent\Model as Eloquent;
class MysqlUser extends Eloquent {
class MysqlUser extends Eloquent
{
protected $connection = 'mysql';
protected $table = 'users';
protected static $unguarded = true;
......@@ -27,15 +27,12 @@ class MysqlUser extends Eloquent {
{
$schema = Schema::connection('mysql');
if (!$schema->hasTable('users'))
{
Schema::connection('mysql')->create('users', function ($table)
{
if (!$schema->hasTable('users')) {
Schema::connection('mysql')->create('users', function ($table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
}
}
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Photo extends Eloquent {
class Photo extends Eloquent
{
protected $collection = 'photos';
protected static $unguarded = true;
......@@ -11,5 +11,4 @@ class Photo extends Eloquent {
{
return $this->morphTo();
}
}
......@@ -2,8 +2,8 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Role extends Eloquent {
class Role extends Eloquent
{
protected $collection = 'roles';
protected static $unguarded = true;
......@@ -16,5 +16,4 @@ class Role extends Eloquent {
{
return $this->belongsTo('MysqlUser');
}
}
......@@ -3,12 +3,12 @@
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Soft extends Eloquent {
class Soft extends Eloquent
{
use SoftDeletes;
protected $collection = 'soft';
protected static $unguarded = true;
protected $dates = ['deleted_at'];
}
......@@ -6,7 +6,8 @@ use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract {
class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword;
......
......@@ -2,8 +2,8 @@
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
......
......@@ -3,7 +3,8 @@
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UserTableSeeder extends Seeder {
class UserTableSeeder extends Seeder
{
public function run()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment