From b940c284091c0e1139e3162f0df5440701904395 Mon Sep 17 00:00:00 2001 From: Maxim Kolokolnikov Date: Fri, 8 Jan 2016 15:37:49 +0600 Subject: [PATCH 1/9] more PSR-2 compatibility --- composer.json | 12 ++- src/Analogue.php | 9 ++- src/AnalogueFacade.php | 5 +- src/AnalogueServiceProvider.php | 5 +- src/Commands/Command.php | 1 - src/Commands/Delete.php | 7 +- src/Commands/Store.php | 16 +--- src/Drivers/CapsuleConnectionProvider.php | 5 +- src/Drivers/DBAdapter.php | 6 +- src/Drivers/DriverInterface.php | 1 - src/Drivers/IlluminateConnectionProvider.php | 5 +- src/Drivers/IlluminateDBAdapter.php | 5 +- src/Drivers/IlluminateDriver.php | 5 +- src/Drivers/IlluminateQueryAdapter.php | 7 +- src/Drivers/Manager.php | 5 +- src/Drivers/QueryAdapter.php | 4 +- src/Entity.php | 11 +-- src/EntityCollection.php | 7 +- src/EntityMap.php | 38 +++++----- src/Exceptions/EntityNotFoundException.php | 5 +- src/Exceptions/MappingException.php | 4 +- src/Mappable.php | 5 +- src/MappableTrait.php | 11 +-- src/Plugins/AnaloguePlugin.php | 5 +- src/Plugins/AnaloguePluginInterface.php | 5 +- src/Plugins/SoftDeletes/Restore.php | 1 - src/Plugins/SoftDeletes/SoftDeletesPlugin.php | 6 +- src/Plugins/SoftDeletes/SoftDeletingScope.php | 7 +- src/Plugins/Timestamps/TimestampsPlugin.php | 12 ++- src/Relationships/BelongsTo.php | 13 ++-- src/Relationships/BelongsToMany.php | 59 +++++++-------- src/Relationships/HasMany.php | 5 +- src/Relationships/HasManyThrough.php | 20 ++--- src/Relationships/HasOne.php | 5 +- src/Relationships/HasOneOrMany.php | 10 +-- src/Relationships/MorphMany.php | 5 +- src/Relationships/MorphOne.php | 7 +- src/Relationships/MorphOneOrMany.php | 5 +- src/Relationships/MorphPivot.php | 5 +- src/Relationships/MorphTo.php | 14 ++-- src/Relationships/MorphToMany.php | 7 +- src/Relationships/Pivot.php | 7 +- src/Relationships/Relationship.php | 14 ++-- src/Repository.php | 13 ++-- src/System/Aggregate.php | 13 ++-- src/System/CachedRelationship.php | 7 +- src/System/EntityBuilder.php | 7 +- src/System/EntityCache.php | 5 +- src/System/InternallyMappable.php | 5 +- src/System/Manager.php | 23 ++++-- src/System/Mapper.php | 20 ++--- src/System/MapperFactory.php | 5 +- src/System/Proxies/CollectionProxy.php | 3 +- src/System/Proxies/EntityProxy.php | 5 +- src/System/Proxies/Proxy.php | 3 +- src/System/Proxies/ProxyInterface.php | 4 +- src/System/Query.php | 74 +++++++++++-------- src/System/ScopeInterface.php | 5 +- src/System/Wrappers/EntityWrapper.php | 6 +- src/System/Wrappers/Factory.php | 5 +- src/System/Wrappers/PlainObjectWrapper.php | 6 +- src/System/Wrappers/Wrapper.php | 2 - src/ValueMap.php | 5 +- src/ValueObject.php | 4 +- tests/AnalogueTest/App/Avatar.php | 5 +- tests/AnalogueTest/App/AvatarMap.php | 5 +- tests/AnalogueTest/App/CustomCommand.php | 6 +- tests/AnalogueTest/App/External.php | 5 +- tests/AnalogueTest/App/ExternalMap.php | 5 +- tests/AnalogueTest/App/Image.php | 5 +- tests/AnalogueTest/App/ImageMap.php | 5 +- tests/AnalogueTest/App/Meta.php | 5 +- tests/AnalogueTest/App/MetaMap.php | 4 +- tests/AnalogueTest/App/Permission.php | 5 +- tests/AnalogueTest/App/PermissionMap.php | 5 +- tests/AnalogueTest/App/Popo.php | 5 +- tests/AnalogueTest/App/PopoMap.php | 5 +- tests/AnalogueTest/App/Register.php | 4 +- tests/AnalogueTest/App/Resource.php | 5 +- tests/AnalogueTest/App/ResourceMap.php | 5 +- tests/AnalogueTest/App/Role.php | 5 +- tests/AnalogueTest/App/RoleMap.php | 5 +- tests/AnalogueTest/App/User.php | 5 +- tests/AnalogueTest/App/UserMap.php | 5 +- tests/AnalogueTest/App/Uuid.php | 5 +- tests/AnalogueTest/App/UuidMap.php | 5 +- tests/AnalogueTest/App/V.php | 5 +- tests/AnalogueTest/App/VMap.php | 5 +- tests/AnalogueTest/DomainTest.php | 5 +- tests/AnalogueTest/EntityCollectionTest.php | 27 +++---- tests/AnalogueTest/EntityTest.php | 6 +- tests/AnalogueTest/ManagerTest.php | 5 +- tests/AnalogueTest/MapperTest.php | 7 +- tests/AnalogueTest/PlainObjectTest.php | 1 - tests/AnalogueTest/QueryTest.php | 17 +++-- tests/AnalogueTest/RepositoryTest.php | 9 ++- tests/AnalogueTest/ValueObjectTest.php | 6 +- tests/init.php | 2 +- 98 files changed, 437 insertions(+), 378 deletions(-) diff --git a/composer.json b/composer.json index af759ef..82804a2 100755 --- a/composer.json +++ b/composer.json @@ -1,8 +1,14 @@ { "name": "analogue/orm", "description": "An intuitive Data Mapper ORM for PHP and Laravel", - "keywords": ["orm", "datamapper", "laravel", - "entity", "repository", "mapper"], + "keywords": [ + "orm", + "datamapper", + "laravel", + "entity", + "repository", + "mapper" + ], "homepage": "http://github.com/analogueorm/analogue", "license": "MIT", "authors": [ @@ -29,5 +35,5 @@ } }, "minimum-stability": "stable", - "prefer-stable":true + "prefer-stable": true } diff --git a/src/Analogue.php b/src/Analogue.php index 818acfb..7be4969 100755 --- a/src/Analogue.php +++ b/src/Analogue.php @@ -1,4 +1,6 @@ -aggregate->getEntityId(); if (is_null($id)) { - throw new MappingException("Executed a delete command on an entity with 'null' as primary key"); + throw new MappingException('Executed a delete command on an entity with "null" as primary key'); } $this->query->where($keyName, '=', $id)->delete(); diff --git a/src/Commands/Store.php b/src/Commands/Store.php index 5f5128f..ddbf25c 100755 --- a/src/Commands/Store.php +++ b/src/Commands/Store.php @@ -3,15 +3,9 @@ namespace Analogue\ORM\Commands; use Analogue\ORM\Mappable; -use Analogue\ORM\System\Mapper; -use Analogue\ORM\System\Manager; use Analogue\ORM\EntityCollection; -use Analogue\ORM\Drivers\QueryAdapter; use Analogue\ORM\System\Aggregate; -use Analogue\ORM\System\InternallyMappable; use Analogue\ORM\System\Proxies\EntityProxy; -use Analogue\ORM\Exceptions\MappingException; -use Analogue\ORM\System\Proxies\ProxyInterface; use Analogue\ORM\System\Proxies\CollectionProxy; /** @@ -20,7 +14,6 @@ */ class Store extends Command { - /** * Persist the entity in the database * @@ -46,7 +39,7 @@ public function execute() if ($mapper->fireEvent('creating', $entity) === false) { return false; } - + $this->insert(); $mapper->fireEvent('created', $entity, false); @@ -70,7 +63,6 @@ public function execute() $mapper->fireEvent('stored', $entity, false); return $entity; - ; } /** @@ -83,7 +75,7 @@ protected function preStoreProcess() { // Create any related object that doesn't exist in the database. $localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships(); - + $this->createRelatedEntities($localRelationships); } @@ -96,7 +88,7 @@ protected function preStoreProcess() protected function createRelatedEntities($relations) { $entitiesToCreate = $this->aggregate->getNonExistingRelated($relations); - + foreach ($entitiesToCreate as $aggregate) { $this->createStoreCommand($aggregate)->execute(); } @@ -147,7 +139,7 @@ protected function postStoreProcess() // This should be move to the wrapper class // so it's the same code for the entity builder $aggregate->setProxies(); - + // Update Entity Cache $aggregate->getMapper()->getEntityCache()->refresh($aggregate); } diff --git a/src/Drivers/CapsuleConnectionProvider.php b/src/Drivers/CapsuleConnectionProvider.php index 7370735..761787c 100755 --- a/src/Drivers/CapsuleConnectionProvider.php +++ b/src/Drivers/CapsuleConnectionProvider.php @@ -1,10 +1,11 @@ -query, $method), $parameters); + return call_user_func_array([$this->query, $method], $parameters); } } diff --git a/src/Drivers/Manager.php b/src/Drivers/Manager.php index 5a6f24c..96ca2a1 100755 --- a/src/Drivers/Manager.php +++ b/src/Drivers/Manager.php @@ -1,8 +1,9 @@ -find($key)); + return !is_null($this->find($key)); } /** @@ -268,7 +265,7 @@ public function getDictionary($items = null) { $items = is_null($items) ? $this->items : $items; - $dictionary = array(); + $dictionary = []; foreach ($items as $value) { $dictionary[$this->getEntityKey($value)] = $value; diff --git a/src/EntityMap.php b/src/EntityMap.php index bcf2a13..2080324 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -5,7 +5,6 @@ use Exception; use ReflectionClass; use Analogue\ORM\System\Manager; -use Analogue\ORM\System\Mapper; use Analogue\ORM\System\Wrappers\Factory; use Analogue\ORM\Relationships\BelongsTo; use Analogue\ORM\Relationships\BelongsToMany; @@ -23,7 +22,6 @@ */ class EntityMap { - /** * The mapping driver to use with this entity */ @@ -199,8 +197,7 @@ class EntityMap * * @var array */ - protected static $manyClasses = ['BelongsToMany', 'HasMany', 'HasManyThrough', - 'MorphMany', 'MorphToMany']; + protected static $manyClasses = ['BelongsToMany', 'HasMany', 'HasManyThrough', 'MorphMany', 'MorphToMany']; /** * The 'Single' relationships classes, which related Entity attribute should be @@ -229,8 +226,15 @@ class EntityMap * * @var array */ - protected static $foreignClasses = ['BelongsToMany', 'HasMany', 'HasManyThrough', - 'MorphMany', 'MorphToMany', 'HasOne', 'MorphOne']; + protected static $foreignClasses = [ + 'BelongsToMany', + 'HasMany', + 'HasManyThrough', + 'MorphMany', + 'MorphToMany', + 'HasOne', + 'MorphOne', + ]; /** * The date format to use with the current database connection @@ -284,7 +288,7 @@ public function setAttributes(array $attributeNames) public function getCompiledAttributes() { $key = $this->getKeyName(); - + $embeddables = array_keys($this->getEmbeddables()); $relationships = $this->getRelationships(); @@ -361,7 +365,7 @@ public function getConnection() */ public function getTable() { - if (! is_null($this->table)) { + if (!is_null($this->table)) { return $this->table; } @@ -385,7 +389,7 @@ public function setTable($table) */ public function getSequence() { - if (! is_null($this->sequence)) { + if (!is_null($this->sequence)) { return $this->sequence; } else { return $this->getTable().'_id_seq'; @@ -405,12 +409,12 @@ public function getClass() /** * Set the custom entity class * - * @param string namespaced class name + * @param string namespaced class name */ public function setClass($class) { // Throw exception if class not exists - + $this->class = $class; } @@ -947,10 +951,10 @@ protected function getBelongsToManyCaller() $caller = array_first(debug_backtrace(false), function ($key, $trace) use ($self) { $caller = $trace['function']; - return (! in_array($caller, EntityMap::$manyMethods) && $caller != $self); + return (!in_array($caller, EntityMap::$manyMethods) && $caller != $self); }); - return ! is_null($caller) ? $caller['function'] : null; + return !is_null($caller) ? $caller['function'] : null; } /** @@ -968,7 +972,7 @@ public function joiningTable($relatedMap) $related = $relatedMap->getTable(); - $tables = array($related, $base); + $tables = [$related, $base]; // Now that we have the model names in an array we can just sort them and // use the implode function to join them together with an underscores, @@ -992,7 +996,7 @@ protected function getMorphs($name, $type, $id) $id = $id ?: $name.'_id'; - return array($type, $id); + return [$type, $id]; } /** @@ -1011,7 +1015,7 @@ public function getMorphClass() * @param array $entities * @return \Analogue\ORM\EntityCollection */ - public function newCollection(array $entities = array()) + public function newCollection(array $entities = []) { return new EntityCollection($entities, $this); } @@ -1160,6 +1164,6 @@ public function __call($method, $parameters) // Add $this to parameters so the closure can call relationship method on the map. $parameters[] = $this; - return call_user_func_array(array($this->dynamicRelationships[$method], $parameters)); + return call_user_func_array([$this->dynamicRelationships[$method], $parameters]); } } diff --git a/src/Exceptions/EntityNotFoundException.php b/src/Exceptions/EntityNotFoundException.php index 028a7ae..a2a72f9 100755 --- a/src/Exceptions/EntityNotFoundException.php +++ b/src/Exceptions/EntityNotFoundException.php @@ -1,10 +1,11 @@ -attributes)) - { + if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; + } else { + return null; } - else return null; } } diff --git a/src/Plugins/AnaloguePlugin.php b/src/Plugins/AnaloguePlugin.php index 4da59ac..ca51788 100755 --- a/src/Plugins/AnaloguePlugin.php +++ b/src/Plugins/AnaloguePlugin.php @@ -1,10 +1,11 @@ -aggregate; diff --git a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php index 20b7e16..2791c54 100755 --- a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php +++ b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php @@ -3,7 +3,6 @@ namespace Analogue\ORM\Plugins\SoftDeletes; use Carbon\Carbon; -use Analogue\ORM\System\Manager; use Analogue\ORM\System\Mapper; use Analogue\ORM\Plugins\AnaloguePlugin; use Analogue\ORM\System\Wrappers\Factory; @@ -14,7 +13,6 @@ */ class SoftDeletesPlugin extends AnaloguePlugin { - /** * Register the plugin * @@ -52,7 +50,7 @@ protected function registerSoftDelete(Mapper $mapper) $host = $this; // Register 'deleting' events - $mapper->registerEvent('deleting', function ($entity) use ($entityMap,$host) { + $mapper->registerEvent('deleting', function ($entity) use ($entityMap, $host) { // Convert Entity into an EntityWrapper $factory = new Factory; @@ -61,7 +59,7 @@ protected function registerSoftDelete(Mapper $mapper) $deletedAtField = $entityMap->getQualifiedDeletedAtColumn(); - if (! is_null($wrappedEntity->getEntityAttribute($deletedAtField))) { + if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) { return true; } else { $time= new Carbon; diff --git a/src/Plugins/SoftDeletes/SoftDeletingScope.php b/src/Plugins/SoftDeletes/SoftDeletingScope.php index c0d221e..62118d0 100755 --- a/src/Plugins/SoftDeletes/SoftDeletingScope.php +++ b/src/Plugins/SoftDeletes/SoftDeletingScope.php @@ -1,11 +1,12 @@ -getQuery(); - foreach ((array) $query->wheres as $key => $where) { + foreach ((array)$query->wheres as $key => $where) { // If the where clause is a soft delete date constraint, we will remove it from // the query and reset the keys on the wheres. This allows this developer to // include deleted model in a relationship result set that is lazy loaded. diff --git a/src/Plugins/Timestamps/TimestampsPlugin.php b/src/Plugins/Timestamps/TimestampsPlugin.php index 1a7d56f..069fc58 100755 --- a/src/Plugins/Timestamps/TimestampsPlugin.php +++ b/src/Plugins/Timestamps/TimestampsPlugin.php @@ -1,9 +1,8 @@ -getCreatedAtColumn(); $updatedAtField = $entityMap->getUpdatedAtColumn(); - $time= new Carbon; + $time = new Carbon; $wrappedEntity->setEntityAttribute($createdAtField, $time); $wrappedEntity->setEntityAttribute($updatedAtField, $time); @@ -46,7 +44,7 @@ public function register() $updatedAtField = $entityMap->getUpdatedAtColumn(); - $time= new Carbon; + $time = new Carbon; $wrappedEntity->setEntityAttribute($updatedAtField, $time); }); diff --git a/src/Relationships/BelongsTo.php b/src/Relationships/BelongsTo.php index 5299a1e..eab4710 100755 --- a/src/Relationships/BelongsTo.php +++ b/src/Relationships/BelongsTo.php @@ -9,7 +9,6 @@ class BelongsTo extends Relationship { - /** * The foreign key of the parent model. * @@ -55,7 +54,7 @@ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $re parent::__construct($mapper, $parent); } - + public function attachTo($related) { return $this->associate($related); @@ -65,7 +64,7 @@ public function detachFrom($related) { return $this->dissociate($related); } - + /** * Get the results of the relationship. * @@ -137,7 +136,7 @@ public function addEagerConstraints(array $entities) */ protected function getEagerModelKeys(array $entities) { - $keys = array(); + $keys = []; // First we need to gather all of the keys from the parent models so we know what // to query for via the eager loading query. We will add them to an array then @@ -154,7 +153,7 @@ protected function getEagerModelKeys(array $entities) // it so the query doesn't fail, but will not return any results, which should // be what this developer is expecting in a case where this happens to them. if (count($keys) == 0) { - return array(0); + return [0]; } return array_values(array_unique($keys)); @@ -229,7 +228,7 @@ public function associate($entity) //$this->parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey)); // // Instead, we'll just add the object to the Entity's attribute - + $this->parent->setEntityAttribute($this->relation, $entity); } @@ -244,7 +243,7 @@ public function dissociate() // the foreign key attribute inside the parent Entity. // //$this->parent->setEntityAttribute($this->foreignKey, null); - + $this->parent->setEntityAttribute($this->relation, null); } diff --git a/src/Relationships/BelongsToMany.php b/src/Relationships/BelongsToMany.php index e959d69..d31cf58 100755 --- a/src/Relationships/BelongsToMany.php +++ b/src/Relationships/BelongsToMany.php @@ -15,7 +15,6 @@ */ class BelongsToMany extends Relationship { - /** * The intermediate table for the relation. * @@ -49,7 +48,7 @@ class BelongsToMany extends Relationship * * @var array */ - protected $pivotColumns = array(); + protected $pivotColumns = []; /** * This relationship has pivot attributes @@ -165,7 +164,7 @@ public function getPivotAttributes() * @param array $columns * @return mixed */ - public function first($columns = array('*')) + public function first($columns = ['*']) { $results = $this->take(1)->get($columns); @@ -180,7 +179,7 @@ public function first($columns = array('*')) * * @throws Mappable|EntityNotFoundException */ - public function firstOrFail($columns = array('*')) + public function firstOrFail($columns = ['*']) { if (! is_null($entity = $this->first($columns))) { return $entity; @@ -195,12 +194,12 @@ public function firstOrFail($columns = array('*')) * @param array $columns * @return \Analogue\ORM\EntityCollection */ - public function get($columns = array('*')) + public function get($columns = ['*']) { // First we'll add the proper select columns onto the query so it is run with // the proper columns. Then, we will get the results and hydrate out pivot // models with the result of those columns as a separate model relation. - $columns = $this->query->getQuery()->columns ? array() : $columns; + $columns = $this->query->getQuery()->columns ? [] : $columns; $select = $this->getSelectColumns($columns); @@ -229,7 +228,7 @@ protected function hydratePivotRelation(array $entities) // To hydrate the pivot relationship, we will just gather the pivot attributes // and create a new Pivot model, which is basically a dynamic model that we // will set the attributes, table, and connections on so it they be used. - + foreach ($entities as $entity) { $entityWrapper = $this->factory->make($entity); @@ -247,7 +246,7 @@ protected function hydratePivotRelation(array $entities) */ protected function cleanPivotAttributes(InternallyMappable $entity) { - $values = array(); + $values = []; $attributes = $entity->getEntityAttributes(); @@ -336,10 +335,10 @@ public function getRelationCountHash() * @param array $columns * @return \Analogue\ORM\Relationships\BelongsToMany */ - protected function getSelectColumns(array $columns = array('*')) + protected function getSelectColumns(array $columns = ['*']) { - if ($columns == array('*')) { - $columns = array($this->relatedMap->getTable().'.*'); + if ($columns == ['*']) { + $columns = [$this->relatedMap->getTable().'.*']; } return array_merge($columns, $this->getAliasedPivotColumns()); @@ -352,12 +351,12 @@ protected function getSelectColumns(array $columns = array('*')) */ protected function getAliasedPivotColumns() { - $defaults = array($this->foreignKey, $this->otherKey); + $defaults = [$this->foreignKey, $this->otherKey]; // We need to alias all of the pivot columns with the "pivot_" prefix so we // can easily extract them out of the models and put them into the pivot // relationships when they are retrieved and hydrated into the models. - $columns = array(); + $columns = []; foreach (array_merge($defaults, $this->pivotColumns) as $column) { $columns[] = $this->table.'.'.$column.' as pivot_'.$column; @@ -480,7 +479,7 @@ protected function buildDictionary(EntityCollection $results) // First we will build a dictionary of child models keyed by the foreign key // of the relation so that we will easily and quickly match them to their // parents without having a possibly slow inner loops for every models. - $dictionary = array(); + $dictionary = []; foreach ($results as $entity) { $wrapper = $this->factory->make($entity); @@ -514,8 +513,8 @@ public function updatePivot($entity) $keyName = $this->relatedMap->getKeyName(); $this->updateExistingPivot( - $entity->getEntityAttribute($keyName), - $entity->getEntityAttribute('pivot')->getEntityAttributes() + $entity->getEntityAttribute($keyName), + $entity->getEntityAttribute('pivot')->getEntityAttributes() ); } @@ -568,9 +567,7 @@ public function updateExistingPivot($id, array $attributes) $attributes = $this->setTimestampsOnAttach($attributes, true); } - $updated = $this->newPivotStatementForId($id)->update($attributes); - - return $updated; + return $this->newPivotStatementForId($id)->update($attributes); } /** @@ -580,7 +577,7 @@ public function updateExistingPivot($id, array $attributes) * @param array $attributes * @return void */ - public function attach($id, array $attributes = array()) + public function attach($id, array $attributes = []) { $query = $this->newPivotStatement(); @@ -604,7 +601,7 @@ public function sync(array $entities) * @param array $entities * @return void */ - protected function detachExcept(array $entities = array()) + protected function detachExcept(array $entities = []) { $query = $this->newPivotQuery(); @@ -632,7 +629,7 @@ protected function detachExcept(array $entities = array()) */ protected function createAttachRecords($ids, array $attributes) { - $records = array(); + $records = []; $timed = in_array($this->createdAt(), $this->pivotColumns); @@ -678,10 +675,10 @@ protected function attacher($key, $value, $attributes, $timed) protected function getAttachId($key, $value, array $attributes) { if (is_array($value)) { - return array($key, array_merge($value, $attributes)); + return [$key, array_merge($value, $attributes)]; } - return array($value, $attributes); + return [$value, $attributes]; } /** @@ -744,10 +741,10 @@ protected function getModelKeysFromCollection(EntityCollection $entities) * @param int|array $ids * @return int */ - public function detach($ids = array()) + public function detach($ids = []) { if ($ids instanceof EntityCollection) { - $ids = (array) $ids->modelKeys(); + $ids = (array)$ids->modelKeys(); } $query = $this->newPivotQuery(); @@ -758,7 +755,7 @@ public function detach($ids = array()) $ids = (array) $ids; if (count($ids) > 0) { - $query->whereIn($this->otherKey, (array) $ids); + $query->whereIn($this->otherKey, (array)$ids); } // Once we have all of the conditions set on the statement, we are ready @@ -817,7 +814,7 @@ public function newPivotStatementForId($id) * @param bool $exists * @return \Analogue\ORM\Relationships\Pivot */ - public function newPivot(array $attributes = array(), $exists = false) + public function newPivot(array $attributes = [], $exists = false) { $pivot = new Pivot($this->parent, $this->parentMap, $attributes, $this->table, $exists); @@ -830,7 +827,7 @@ public function newPivot(array $attributes = array(), $exists = false) * @param array $attributes * @return \Analogue\ORM\Relationships\Pivot */ - public function newExistingPivot(array $attributes = array()) + public function newExistingPivot(array $attributes = []) { return $this->newPivot($attributes, true); } @@ -879,7 +876,7 @@ public function getHasCompareKey() */ public function getForeignKey() { - return $this->table.'.'.$this->foreignKey; + return $this->table . '.' . $this->foreignKey; } /** @@ -889,7 +886,7 @@ public function getForeignKey() */ public function getOtherKey() { - return $this->table.'.'.$this->otherKey; + return $this->table . '.' . $this->otherKey; } /** diff --git a/src/Relationships/HasMany.php b/src/Relationships/HasMany.php index f114dd9..d934e20 100755 --- a/src/Relationships/HasMany.php +++ b/src/Relationships/HasMany.php @@ -1,10 +1,11 @@ -firstKey; @@ -228,7 +228,7 @@ public function getResults($relation) * @param array $columns * @return \Analogue\ORM\EntityCollection */ - public function get($columns = array('*')) + public function get($columns = ['*']) { // First we'll add the proper select columns onto the query so it is run with // the proper columns. Then, we will get the results and hydrate out pivot @@ -253,13 +253,13 @@ public function get($columns = array('*')) * @param array $columns * @return \Analogue\ORM\Relationships\BelongsToMany */ - protected function getSelectColumns(array $columns = array('*')) + protected function getSelectColumns(array $columns = ['*']) { - if ($columns == array('*')) { - $columns = array($this->relatedMap->getTable().'.*'); + if ($columns == ['*']) { + $columns = [$this->relatedMap->getTable().'.*']; } - return array_merge($columns, array($this->parentMap->getTable().'.'.$this->firstKey)); + return array_merge($columns, [$this->parentMap->getTable().'.'.$this->firstKey]); } /** @@ -269,7 +269,7 @@ protected function getSelectColumns(array $columns = array('*')) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function paginate($perPage = null, $columns = array('*')) + public function paginate($perPage = null, $columns = ['*']) { $this->query->addSelect($this->getSelectColumns($columns)); diff --git a/src/Relationships/HasOne.php b/src/Relationships/HasOne.php index 3b006d3..6e80d79 100755 --- a/src/Relationships/HasOne.php +++ b/src/Relationships/HasOne.php @@ -1,10 +1,11 @@ -update([$this->getPlainForeignKey() => null]); } - public function detachMany(array $entityHashes) { $keys = []; @@ -228,7 +228,7 @@ protected function getRelationValue(array $dictionary, $key, $type) */ protected function buildDictionary(EntityCollection $results) { - $dictionary = array(); + $dictionary = []; $foreign = $this->getPlainForeignKey(); @@ -241,7 +241,7 @@ protected function buildDictionary(EntityCollection $results) return $dictionary; } - + /** * Get the key for comparing against the parent key in "has" query. * diff --git a/src/Relationships/MorphMany.php b/src/Relationships/MorphMany.php index a32c381..fcda869 100755 --- a/src/Relationships/MorphMany.php +++ b/src/Relationships/MorphMany.php @@ -1,10 +1,11 @@ -query->first(); - + $this->cacheRelation($result, $relation); return $result; diff --git a/src/Relationships/MorphOneOrMany.php b/src/Relationships/MorphOneOrMany.php index bf3be97..1266a05 100755 --- a/src/Relationships/MorphOneOrMany.php +++ b/src/Relationships/MorphOneOrMany.php @@ -1,11 +1,12 @@ -parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey)); // // Instead, we'll just add the object to the Entity's attribute - + $this->parent->setEntityAttribute($this->relation, $entity); } diff --git a/src/Relationships/MorphToMany.php b/src/Relationships/MorphToMany.php index 329900c..209b7a3 100755 --- a/src/Relationships/MorphToMany.php +++ b/src/Relationships/MorphToMany.php @@ -1,11 +1,12 @@ -parent, $this->parentMap, $attributes, $this->table, $exists); diff --git a/src/Relationships/Pivot.php b/src/Relationships/Pivot.php index ca01bc7..682767d 100755 --- a/src/Relationships/Pivot.php +++ b/src/Relationships/Pivot.php @@ -1,10 +1,11 @@ -getEntityMap()->getKeyName(); - + $hash = $class.'.'.$entity->getEntityAttribute($keyName); return $hash; @@ -440,7 +438,7 @@ public function sync(array $actualContent) */ public function __call($method, $parameters) { - $result = call_user_func_array(array($this->query, $method), $parameters); + $result = call_user_func_array([$this->query, $method], $parameters); if ($result === $this->query) { return $this; diff --git a/src/Repository.php b/src/Repository.php index 904c3e9..4cd70a1 100755 --- a/src/Repository.php +++ b/src/Repository.php @@ -1,15 +1,14 @@ -mapper = $mapper; } else { - new InvalidArgumentException('Repository class constuctor need a valid Mapper or Mappable object.'); + new InvalidArgumentException('Repository class constructor need a valid Mapper or Mappable object.'); } } @@ -125,7 +124,7 @@ public function store($entity) public function __call($method, $parameters) { if ($this->mapper->hasCustomCommand($method)) { - call_user_func_array(array($this->mapper, $method), $parameters); + call_user_func_array([$this->mapper, $method], $parameters); } else { throw new Exception("No method $method on ".get_class($this)); } diff --git a/src/System/Aggregate.php b/src/System/Aggregate.php index a4673c2..9ffa7c0 100755 --- a/src/System/Aggregate.php +++ b/src/System/Aggregate.php @@ -1,8 +1,9 @@ -createSubAggregate($value, $relation); - + // Even if it's a single entity, we'll store it as an array // just for consistency with other relationships $this->relationships[$relation] = [$subAggregate]; @@ -205,7 +205,6 @@ protected function isParentOrRoot($value) } } - if (! is_null($this->parent)) { $parentClass = get_class($this->parent->getEntityObject()); if ($parentClass == get_class($value)) { @@ -467,7 +466,7 @@ public function getMissingEntities($relation) { $cachedRelations = $this->getCachedAttribute($relation); - if (! is_null($cachedRelations)) { + if (!is_null($cachedRelations)) { $missing = []; foreach ($cachedRelations as $hash) { @@ -756,7 +755,7 @@ protected function updatePivotIfDirty($pivotHash, $relation) $actualPivotAttributes = array_only($pivot, array_keys($cachedPivotAttributes)); $dirty = $this->getDirtyAttributes($actualPivotAttributes, $cachedPivotAttributes); - + if (count($dirty) > 0) { $id = $aggregate->getEntityId(); diff --git a/src/System/CachedRelationship.php b/src/System/CachedRelationship.php index c0267f7..3b17a99 100755 --- a/src/System/CachedRelationship.php +++ b/src/System/CachedRelationship.php @@ -1,4 +1,6 @@ -pivotAttributes) > 0 ? true : false; + return count($this->pivotAttributes) > 0; } /** diff --git a/src/System/EntityBuilder.php b/src/System/EntityBuilder.php index 3382730..263fbc4 100755 --- a/src/System/EntityBuilder.php +++ b/src/System/EntityBuilder.php @@ -1,6 +1,7 @@ -getWrapperPrototype(); //$prototype = $this->mapper->newInstance(); diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index 1ce104c..ea55f3a 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -6,10 +6,8 @@ use Analogue\ORM\EntityMap; use Analogue\ORM\EntityCollection; use Analogue\ORM\System\Wrappers\Factory; -use Analogue\ORM\System\InternallyMappable; use Analogue\ORM\Relationships\Relationship; use Analogue\ORM\Exceptions\MappingException; -use Analogue\ORM\System\Proxies\ProxyInterface; /** * The EntityCache class is responsible for tracking entity's attribute states @@ -17,7 +15,6 @@ */ class EntityCache { - /** * Entity's raw attributes/relationships * @@ -265,7 +262,7 @@ protected function transform(Aggregate $aggregatedEntity) // First we'll handle each relationships that are a one to one // relation, and which will be saved as a CachedRelationship // object inside the cache. - + // NOTE : storing localRelationships maybe useless has we store // the foreign key in the attributes already. diff --git a/src/System/InternallyMappable.php b/src/System/InternallyMappable.php index c072016..b8c9e51 100755 --- a/src/System/InternallyMappable.php +++ b/src/System/InternallyMappable.php @@ -1,8 +1,9 @@ -getEntityMap()->boot(); return $mapper; @@ -232,7 +239,7 @@ public function register($entity, $entityMap = null) /** * Get the entity map instance for a custom entity * - * @param string $entity + * @param string $entity * @return Mappable */ protected function getEntityMapInstanceFor($entity) @@ -375,7 +382,7 @@ public function isRegisteredEntity($entity) */ public function registerGlobalEvent($event, $callback) { - if (! in_array($event, $this->events)) { + if (!in_array($event, $this->events)) { throw new \Exception("Analogue : Event $event doesn't exist"); } $this->eventDispatcher->listen("analogue.{$event}.*", $callback); diff --git a/src/System/Mapper.php b/src/System/Mapper.php index 9e121bf..b032278 100755 --- a/src/System/Mapper.php +++ b/src/System/Mapper.php @@ -1,4 +1,6 @@ -checkEntityType($entity); - + $store = new Store($this->aggregate($entity), $this->newQueryBuilder()); return $store->execute(); @@ -284,7 +284,7 @@ public function addGlobalScope(ScopeInterface $scope) */ public function hasGlobalScope($scope) { - return ! is_null($this->getGlobalScope($scope)); + return !is_null($this->getGlobalScope($scope)); } /** @@ -454,7 +454,7 @@ public function hasCustomCommand($command) * @param array $attributes * @return mixed */ - public function newInstance($attributes = array()) + public function newInstance($attributes = []) { $class = $this->entityMap->getClass(); @@ -484,11 +484,7 @@ protected function customClassInstance($className) throw new MappingException("Tried to instantiate a non-existing Entity class : $className"); } - $prototype = unserialize(sprintf('O:%d:"%s":0:{}', - strlen($className), - $className - ) - ); + $prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className)); return $prototype; } @@ -562,6 +558,6 @@ public function __call($method, $parameters) } // Redirect call on a new query instance - return call_user_func_array(array($this->query(), $method), $parameters); + return call_user_func_array([$this->query(), $method], $parameters); } } diff --git a/src/System/MapperFactory.php b/src/System/MapperFactory.php index 85eae8a..a06ccf1 100755 --- a/src/System/MapperFactory.php +++ b/src/System/MapperFactory.php @@ -1,4 +1,6 @@ -loadedCollection); + return !is_null($this->loadedCollection); } /** diff --git a/src/System/Proxies/EntityProxy.php b/src/System/Proxies/EntityProxy.php index a0e34ca..6eeba9b 100755 --- a/src/System/Proxies/EntityProxy.php +++ b/src/System/Proxies/EntityProxy.php @@ -1,8 +1,9 @@ -query($this->parentEntity, $this->relation)->getResults($this->relation); - + $this->loaded = true; return $entities; diff --git a/src/System/Proxies/ProxyInterface.php b/src/System/Proxies/ProxyInterface.php index d9c92fb..783636e 100755 --- a/src/System/Proxies/ProxyInterface.php +++ b/src/System/Proxies/ProxyInterface.php @@ -1,10 +1,10 @@ -getEntities($columns); // If we actually found models we will also eager load any relationships that // have been specified as needing to be eager loaded, which will solve the // n+1 query issue for the developers to avoid running a lot of queries. - + if (count($entities) > 0) { $entities = $this->eagerLoadRelations($entities); } @@ -127,7 +143,7 @@ public function get($columns = array('*')) * @param array $columns * @return \Analogue\ORM\Mappable */ - public function find($id, $columns = array('*')) + public function find($id, $columns = ['*']) { if (is_array($id)) { return $this->findMany($id, $columns); @@ -145,7 +161,7 @@ public function find($id, $columns = array('*')) * @param array $columns * @return EntityCollection */ - public function findMany($id, $columns = array('*')) + public function findMany($id, $columns = ['*']) { if (empty($id)) { return new EntityCollection; @@ -165,9 +181,9 @@ public function findMany($id, $columns = array('*')) * * @throws \Analogue\ORM\Exception\EntityNotFoundException */ - public function findOrFail($id, $columns = array('*')) + public function findOrFail($id, $columns = ['*']) { - if (! is_null($entity = $this->find($id, $columns))) { + if (!is_null($entity = $this->find($id, $columns))) { return $entity; } @@ -181,7 +197,7 @@ public function findOrFail($id, $columns = array('*')) * @param array $columns * @return \Analogue\ORM\Entity */ - public function first($columns = array('*')) + public function first($columns = ['*']) { return $this->take(1)->get($columns)->first(); } @@ -194,9 +210,9 @@ public function first($columns = array('*')) * * @throws EntityNotFoundException */ - public function firstOrFail($columns = array('*')) + public function firstOrFail($columns = ['*']) { - if (! is_null($entity = $this->first($columns))) { + if (!is_null($entity = $this->first($columns))) { return $entity; } @@ -211,7 +227,7 @@ public function firstOrFail($columns = array('*')) */ public function pluck($column) { - $result = $this->first(array($column)); + $result = $this->first([$column]); if ($result) { return $result->{$column}; @@ -260,7 +276,7 @@ public function lists($column, $key = null) * @param array $columns * @return \Illuminate\Pagination\Paginator */ - public function paginate($perPage = null, $columns = array('*')) + public function paginate($perPage = null, $columns = ['*']) { $total = $this->query->getCountForPagination(); @@ -349,7 +365,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' $this->query->addNestedWhereQuery($query->getQuery(), $boolean); } else { - call_user_func_array(array($this->query, 'where'), func_get_args()); + call_user_func_array([$this->query, 'where'], func_get_args()); } return $this; @@ -526,7 +542,7 @@ public function with($relations) */ protected function parseRelations(array $relations) { - $results = array(); + $results = []; foreach ($relations as $name => $constraints) { // If the "relation" value is actually a numeric key, we can assume that no @@ -535,7 +551,7 @@ protected function parseRelations(array $relations) if (is_numeric($name)) { $f = function () {}; - list($name, $constraints) = array($constraints, $f); + list($name, $constraints) = [$constraints, $f]; } // We need to separate out any nested includes. Which allows the developers @@ -559,7 +575,7 @@ protected function parseRelations(array $relations) */ protected function parseNested($name, $results) { - $progress = array(); + $progress = []; // If the relation has already been set on the result array, we will not set it // again, since that would override any constraints that were already placed @@ -640,7 +656,7 @@ protected function loadRelation(array $entities, $name, Closure $constraints) // Once we have the results, we just match those back up to their parent models // using the relationship instance. Then we just return the finished arrays // of models which have been eagerly hydrated and are readied for return. - + $results = $relation->getEager(); return $relation->match($entities, $results, $name); @@ -681,7 +697,7 @@ public function getRelation($relation) */ protected function nestedRelations($relation) { - $nested = array(); + $nested = []; // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations @@ -717,7 +733,7 @@ protected function isNested($name, $relation) */ protected function enforceIdColumn($columns) { - if (! in_array($this->entityMap->getKeyName(), $columns)) { + if (!in_array($this->entityMap->getKeyName(), $columns)) { $columns[] = $this->entityMap->getKeyName(); } return $columns; @@ -729,7 +745,7 @@ protected function enforceIdColumn($columns) * @param array $columns * @return Analogue\ORM\EntityCollection */ - public function getEntities($columns = array('*')) + public function getEntities($columns = ['*']) { // As we need the primary key to feed the // entity cache, we need it loaded on each @@ -750,7 +766,7 @@ public function getEntities($columns = array('*')) * @param array $attributes * @return Entity */ - public function getEntityInstance(array $attributes = array()) + public function getEntityInstance(array $attributes = []) { return $this->mapper->newInstance($attributes); } @@ -842,7 +858,7 @@ public function __call($method, $parameters) throw new Exception("Method $method doesn't exist"); } - $result = call_user_func_array(array($this->query, $method), $parameters); + $result = call_user_func_array([$this->query, $method], $parameters); return in_array($method, $this->passthru) ? $result : $this; } diff --git a/src/System/ScopeInterface.php b/src/System/ScopeInterface.php index 6e42321..29f091b 100755 --- a/src/System/ScopeInterface.php +++ b/src/System/ScopeInterface.php @@ -1,8 +1,9 @@ -name = $name; diff --git a/tests/AnalogueTest/App/AvatarMap.php b/tests/AnalogueTest/App/AvatarMap.php index 12b48d3..f18db7f 100755 --- a/tests/AnalogueTest/App/AvatarMap.php +++ b/tests/AnalogueTest/App/AvatarMap.php @@ -1,10 +1,11 @@ -name = $name; diff --git a/tests/AnalogueTest/App/ExternalMap.php b/tests/AnalogueTest/App/ExternalMap.php index bd379a0..8e3d5df 100755 --- a/tests/AnalogueTest/App/ExternalMap.php +++ b/tests/AnalogueTest/App/ExternalMap.php @@ -1,10 +1,11 @@ -path = $path; diff --git a/tests/AnalogueTest/App/ImageMap.php b/tests/AnalogueTest/App/ImageMap.php index 7136904..7d88f0f 100755 --- a/tests/AnalogueTest/App/ImageMap.php +++ b/tests/AnalogueTest/App/ImageMap.php @@ -1,10 +1,11 @@ -morphTo($image); diff --git a/tests/AnalogueTest/App/Meta.php b/tests/AnalogueTest/App/Meta.php index 5a3f03d..b1151ed 100755 --- a/tests/AnalogueTest/App/Meta.php +++ b/tests/AnalogueTest/App/Meta.php @@ -1,10 +1,11 @@ -label = $label; diff --git a/tests/AnalogueTest/App/PermissionMap.php b/tests/AnalogueTest/App/PermissionMap.php index 94d732d..f452fd3 100755 --- a/tests/AnalogueTest/App/PermissionMap.php +++ b/tests/AnalogueTest/App/PermissionMap.php @@ -1,10 +1,11 @@ -belongsToMany($permission, 'AnalogueTest\App\Role', 'role_permission'); diff --git a/tests/AnalogueTest/App/Popo.php b/tests/AnalogueTest/App/Popo.php index fcc7b00..da0c6a2 100755 --- a/tests/AnalogueTest/App/Popo.php +++ b/tests/AnalogueTest/App/Popo.php @@ -1,8 +1,9 @@ -label = $label; diff --git a/tests/AnalogueTest/App/RoleMap.php b/tests/AnalogueTest/App/RoleMap.php index c539865..3ac96ef 100755 --- a/tests/AnalogueTest/App/RoleMap.php +++ b/tests/AnalogueTest/App/RoleMap.php @@ -1,10 +1,11 @@ -hasMany($entity, 'AnalogueTest\App\User'); diff --git a/tests/AnalogueTest/App/User.php b/tests/AnalogueTest/App/User.php index 3a3b530..eaef1bb 100755 --- a/tests/AnalogueTest/App/User.php +++ b/tests/AnalogueTest/App/User.php @@ -1,10 +1,11 @@ -email = $email; diff --git a/tests/AnalogueTest/App/UserMap.php b/tests/AnalogueTest/App/UserMap.php index 710d7fc..f431bd1 100755 --- a/tests/AnalogueTest/App/UserMap.php +++ b/tests/AnalogueTest/App/UserMap.php @@ -1,10 +1,11 @@ -uuid = $uuid; diff --git a/tests/AnalogueTest/App/UuidMap.php b/tests/AnalogueTest/App/UuidMap.php index 4ac9d8f..89e3b7c 100755 --- a/tests/AnalogueTest/App/UuidMap.php +++ b/tests/AnalogueTest/App/UuidMap.php @@ -1,10 +1,11 @@ -field_1 = $a; diff --git a/tests/AnalogueTest/App/VMap.php b/tests/AnalogueTest/App/VMap.php index aa68226..a418728 100755 --- a/tests/AnalogueTest/App/VMap.php +++ b/tests/AnalogueTest/App/VMap.php @@ -1,9 +1,10 @@ -add($e)->add($f); - $this->assertEquals(array($e, $f), $c->all()); + $this->assertEquals([$e, $f], $c->all()); } /*public function testConstructorRejectNonMappableItems() @@ -86,7 +87,7 @@ public function testContainsIndicatesIfEntityInArray() $entity3 = new Entity; $entity3->id = 3; - $c = new Collection(array($entity1, $entity2)); + $c = new Collection([$entity1, $entity2]); $this->assertTrue($c->contains($entity1)); $this->assertTrue($c->contains($entity2)); @@ -116,9 +117,9 @@ public function testCollectionDictionaryReturnsEntityKeys() $entity3 = new Entity; $entity3->id = 3; - $c = new Collection(array($entity1, $entity2, $entity3)); + $c = new Collection([$entity1, $entity2, $entity3]); - $this->assertEquals(array(1, 2, 3), $c->getEntityKeys()); + $this->assertEquals([1, 2, 3], $c->getEntityKeys()); } @@ -134,7 +135,7 @@ public function testCollectionMergesWithGivenCollection() $c1 = new Collection([$e1, $e2]); $c2 = new Collection([$e2, $e3]); - $this->assertEquals(new Collection(array($e1, $e2, $e3)), $c1->merge($c2)); + $this->assertEquals(new Collection([$e1, $e2, $e3]), $c1->merge($c2)); } @@ -150,7 +151,7 @@ public function testCollectionDiffsWithGivenCollection() $c1 = new Collection([$e1, $e2]); $c2 = new Collection([$e2, $e3]); - $this->assertEquals(new Collection(array($e1)), $c1->diff($c2)); + $this->assertEquals(new Collection([$e1]), $c1->diff($c2)); } @@ -166,7 +167,7 @@ public function testCollectionIntersectsWithGivenCollection() $c1 = new Collection([$e1, $e2]); $c2 = new Collection([$e2, $e3]); - $this->assertEquals(new Collection(array($e2)), $c1->intersect($c2)); + $this->assertEquals(new Collection([$e2]), $c1->intersect($c2)); } @@ -177,9 +178,9 @@ public function testCollectionReturnsUniqueItems() $e2 = new Entity; $e2->id = 2; - $c = new Collection(array($e1, $e2, $e2)); + $c = new Collection([$e1, $e2, $e2]); - $this->assertEquals(new Collection(array($e1, $e2)), $c->unique()); + $this->assertEquals(new Collection([$e1, $e2]), $c->unique()); } @@ -225,7 +226,7 @@ public function testExceptReturnsCollectionWithoutGivenModelKeys() $c = new Collection([$e1, $e2, $e3]); - $this->assertEquals(new Collection(array($e1, $e3)), $c->except(2)); - $this->assertEquals(new Collection(array($e1)), $c->except(array(2, 3))); + $this->assertEquals(new Collection([$e1, $e3]), $c->except(2)); + $this->assertEquals(new Collection([$e1]), $c->except([2, 3])); } } diff --git a/tests/AnalogueTest/EntityTest.php b/tests/AnalogueTest/EntityTest.php index a1e5bf8..41f2b3a 100755 --- a/tests/AnalogueTest/EntityTest.php +++ b/tests/AnalogueTest/EntityTest.php @@ -1,12 +1,12 @@ - 1, - 'column2' => "2", + 'column2' => '2', ]; $entity = $mapper->newInstance($attributes); $this->assertEquals($entity->getEntityAttributes(), $attributes); diff --git a/tests/AnalogueTest/PlainObjectTest.php b/tests/AnalogueTest/PlainObjectTest.php index 290cb9c..8b387d0 100755 --- a/tests/AnalogueTest/PlainObjectTest.php +++ b/tests/AnalogueTest/PlainObjectTest.php @@ -6,7 +6,6 @@ class PlainObjectTest extends PHPUnit_Framework_TestCase { - public function testPopoStore() { diff --git a/tests/AnalogueTest/QueryTest.php b/tests/AnalogueTest/QueryTest.php index b075ad2..6314c78 100755 --- a/tests/AnalogueTest/QueryTest.php +++ b/tests/AnalogueTest/QueryTest.php @@ -1,9 +1,10 @@ -add(new Permission("P$x")); } $mapper->store($c); @@ -218,8 +219,8 @@ public function testPaginationWithCustomValue() { $mapper = get_mapper('AnalogueTest\App\Permission'); $c = new EntityCollection; - $y=0; - for ($x=0;$x<30;$x++) { + $y = 0; + for ($x = 0; $x < 30; $x++) { $c->add(new Permission("P$x")); } $mapper->store($c); @@ -231,8 +232,8 @@ public function testSimplePaginate() { $mapper = get_mapper('AnalogueTest\App\Permission'); $c = new EntityCollection; - $y=0; - for ($x=0;$x<30;$x++) { + $y = 0; + for ($x = 0; $x < 30; $x++) { $c->add(new Permission("P$x")); } $mapper->store($c); diff --git a/tests/AnalogueTest/RepositoryTest.php b/tests/AnalogueTest/RepositoryTest.php index 1cbd686..230b79c 100755 --- a/tests/AnalogueTest/RepositoryTest.php +++ b/tests/AnalogueTest/RepositoryTest.php @@ -1,4 +1,6 @@ -store([$p, $q]); $r = $repo->allMatching(['label' => 'Third']); - + $this->assertInstanceOf('Analogue\ORM\EntityCollection', $r); $this->assertEquals(2, $r->count()); } @@ -68,7 +69,7 @@ public function testPaginate() $p = new Permission('First'); $q = new Permission('Second'); $repo->store([$p, $q]); - + $s = $repo->paginate(1); $this->assertEquals(1, count($s)); } diff --git a/tests/AnalogueTest/ValueObjectTest.php b/tests/AnalogueTest/ValueObjectTest.php index 19c64c4..4b810e1 100755 --- a/tests/AnalogueTest/ValueObjectTest.php +++ b/tests/AnalogueTest/ValueObjectTest.php @@ -1,7 +1,8 @@ -add('AnalogueTest', __DIR__); // Date setup From 741465e58790ae5f92402babbfa48ce3c3e70327 Mon Sep 17 00:00:00 2001 From: Maxim Kolokolnikov Date: Fri, 8 Jan 2016 16:11:27 +0600 Subject: [PATCH 2/9] more PSR-2 compatibility --- src/Relationships/MorphToMany.php | 4 ++-- src/System/Manager.php | 6 +----- src/System/Wrappers/PlainObjectWrapper.php | 2 +- src/ValueObject.php | 7 +++---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Relationships/MorphToMany.php b/src/Relationships/MorphToMany.php index 209b7a3..71c296c 100755 --- a/src/Relationships/MorphToMany.php +++ b/src/Relationships/MorphToMany.php @@ -135,8 +135,8 @@ public function newPivot(array $attributes = [], $exists = false) $pivot = new MorphPivot($this->parent, $this->parentMap, $attributes, $this->table, $exists); $pivot->setPivotKeys($this->foreignKey, $this->otherKey) - ->setMorphType($this->morphType) - ->setMorphClass($this->morphClass); + ->setMorphType($this->morphType) + ->setMorphClass($this->morphClass); return $pivot; } diff --git a/src/System/Manager.php b/src/System/Manager.php index d7ca441..99481d6 100755 --- a/src/System/Manager.php +++ b/src/System/Manager.php @@ -334,11 +334,7 @@ public function getValueMap($valueObject) */ public function getValueObjectInstance($valueObject) { - $prototype = unserialize(sprintf('O:%d:"%s":0:{}', - strlen($valueObject), - $valueObject - ) - ); + $prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($valueObject), $valueObject)); return $prototype; } diff --git a/src/System/Wrappers/PlainObjectWrapper.php b/src/System/Wrappers/PlainObjectWrapper.php index 0d113ca..1c62865 100755 --- a/src/System/Wrappers/PlainObjectWrapper.php +++ b/src/System/Wrappers/PlainObjectWrapper.php @@ -120,7 +120,7 @@ protected function hydrate($attributes) } } - /** + /** * Method used by the mapper to set the object * attribute raw values (hydration) * diff --git a/src/ValueObject.php b/src/ValueObject.php index b0f681e..7654549 100755 --- a/src/ValueObject.php +++ b/src/ValueObject.php @@ -103,7 +103,7 @@ public function offsetUnset($offset) { unset($this->$offset); } - + /** * Convert the object into something JSON serializable. * @@ -113,7 +113,7 @@ public function jsonSerialize() { return $this->toArray(); } - + /** * Convert the entity instance to JSON. * @@ -125,7 +125,6 @@ public function toJson($options = 0) return json_encode($this->toArray(), $options); } - /** * Convert Mappable object to array; * @@ -136,7 +135,7 @@ public function toArray() return $this->attributesToArray($this->attributes); } - /** + /** * Transform the Object to array/json, * * @return array From 4ca93ad94a83bfac93a7e6c3588cd59a877e3d14 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 8 Jan 2016 10:15:10 +0000 Subject: [PATCH 3/9] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/EntityMap.php | 32 ++++++++++++++-------------- src/Relationships/BelongsTo.php | 12 +++++------ src/Relationships/BelongsToMany.php | 24 ++++++++++----------- src/Relationships/HasManyThrough.php | 12 +++++------ src/Relationships/HasOneOrMany.php | 2 +- src/Relationships/MorphTo.php | 2 +- src/Relationships/MorphToMany.php | 8 +++---- src/Relationships/Relationship.php | 6 +++--- src/ValueObject.php | 2 +- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/EntityMap.php b/src/EntityMap.php index 2080324..2a09af0 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -205,7 +205,7 @@ class EntityMap * * @var array */ - protected static $singleClasses = ['BelongsTo', 'HasOne', 'MorphOne','MorphTo']; + protected static $singleClasses = ['BelongsTo', 'HasOne', 'MorphOne', 'MorphTo']; /** * Relationships with a pivot record @@ -392,7 +392,7 @@ public function getSequence() if (!is_null($this->sequence)) { return $this->sequence; } else { - return $this->getTable().'_id_seq'; + return $this->getTable() . '_id_seq'; } } @@ -561,7 +561,7 @@ public function setKeyName($key) */ public function getQualifiedKeyName() { - return $this->getTable().'.'.$this->getKeyName(); + return $this->getTable() . '.' . $this->getKeyName(); } /** @@ -642,7 +642,7 @@ public function getQualifiedDeletedAtColumn() */ public function getForeignKey() { - return snake_case(class_basename($this->getClass())).'_id'; + return snake_case(class_basename($this->getClass())) . '_id'; } /** @@ -664,7 +664,7 @@ public function hasOne($entity, $relatedClass, $foreignKey = null, $localKey = n $localKey = $localKey ?: $this->getKeyName(); - return new HasOne($relatedMapper, $entity, $relatedMap->getTable().'.'.$foreignKey, $localKey); + return new HasOne($relatedMapper, $entity, $relatedMap->getTable() . '.' . $foreignKey, $localKey); } /** @@ -687,7 +687,7 @@ public function morphOne($entity, $related, $name, $type = null, $id = null, $lo $table = $relatedMapper->getEntityMap()->getTable(); - return new MorphOne($relatedMapper, $entity, $table.'.'.$type, $table.'.'.$id, $localKey); + return new MorphOne($relatedMapper, $entity, $table . '.' . $type, $table . '.' . $id, $localKey); } /** @@ -714,7 +714,7 @@ public function belongsTo($entity, $related, $foreignKey = null, $otherKey = nul // 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)) { - $foreignKey = snake_case($relation).'_id'; + $foreignKey = snake_case($relation) . '_id'; } $relatedMapper = $this->manager->mapper($related); @@ -787,7 +787,7 @@ public function hasMany($entity, $related, $foreignKey = null, $localKey = null) $relatedMapper = $this->manager->mapper($related); - $table = $relatedMapper->getEntityMap()->getTable().'.'.$foreignKey; + $table = $relatedMapper->getEntityMap()->getTable() . '.' . $foreignKey; $localKey = $localKey ?: $this->getKeyName(); @@ -842,7 +842,7 @@ public function morphMany($entity, $related, $name, $type = null, $id = null, $l $localKey = $localKey ?: $this->getKeyName(); - return new MorphMany($relatedMapper, $entity, $table.'.'.$type, $table.'.'.$id, $localKey); + return new MorphMany($relatedMapper, $entity, $table . '.' . $type, $table . '.' . $id, $localKey); } /** @@ -903,7 +903,7 @@ public function morphToMany($entity, $related, $name, $table = null, $foreignKey // First, we will need to determine the foreign key and "other key" for the // relationship. Once we have determined the keys we will make the query // instances, as well as the relationship instances we need for these. - $foreignKey = $foreignKey ?: $name.'_id'; + $foreignKey = $foreignKey ?: $name . '_id'; $relatedMapper = $this->manager->mapper($related); @@ -934,7 +934,7 @@ public function morphedByMany($entity, $related, $name, $table = null, $foreignK // For the inverse of the polymorphic many-to-many relations, we will change // the way we determine the foreign and other keys, as it is the opposite // of the morph-to-many method since we're figuring out these inverses. - $otherKey = $otherKey ?: $name.'_id'; + $otherKey = $otherKey ?: $name . '_id'; return $this->morphToMany($entity, $related, $name, $table, $foreignKey, $otherKey, true); } @@ -948,7 +948,7 @@ protected function getBelongsToManyCaller() { $self = __FUNCTION__; - $caller = array_first(debug_backtrace(false), function ($key, $trace) use ($self) { + $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self) { $caller = $trace['function']; return (!in_array($caller, EntityMap::$manyMethods) && $caller != $self); @@ -992,9 +992,9 @@ public function joiningTable($relatedMap) */ protected function getMorphs($name, $type, $id) { - $type = $type ?: $name.'_type'; + $type = $type ?: $name . '_type'; - $id = $id ?: $name.'_id'; + $id = $id ?: $name . '_id'; return [$type, $id]; } @@ -1157,8 +1157,8 @@ public function activator() */ public function __call($method, $parameters) { - if (! array_key_exists($method, $this->dynamicRelationships)) { - throw new Exception(get_class($this)." has no method $method"); + if (!array_key_exists($method, $this->dynamicRelationships)) { + throw new Exception(get_class($this) . " has no method $method"); } // Add $this to parameters so the closure can call relationship method on the map. diff --git a/src/Relationships/BelongsTo.php b/src/Relationships/BelongsTo.php index eab4710..b304272 100755 --- a/src/Relationships/BelongsTo.php +++ b/src/Relationships/BelongsTo.php @@ -92,7 +92,7 @@ public function addConstraints() // of the related models matching on the foreign key that's on a parent. $table = $this->relatedMap->getTable(); - $this->query->where($table.'.'.$this->otherKey, '=', $this->parent->getEntityAttribute($this->foreignKey)); + $this->query->where($table . '.' . $this->otherKey, '=', $this->parent->getEntityAttribute($this->foreignKey)); } } @@ -107,7 +107,7 @@ public function getRelationCountQuery(Query $query, Query $parent) { $query->select(new Expression('count(*)')); - $otherKey = $this->wrap($query->getTable().'.'.$this->otherKey); + $otherKey = $this->wrap($query->getTable() . '.' . $this->otherKey); return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); } @@ -123,7 +123,7 @@ public function addEagerConstraints(array $entities) // We'll grab the primary key name of the related models since it could be set to // a non-standard name and not "id". We will then construct the constraint for // our eagerly loading query so it returns the proper models from execution. - $key = $this->relatedMap->getTable().'.'.$this->otherKey; + $key = $this->relatedMap->getTable() . '.' . $this->otherKey; $this->query->whereIn($key, $this->getEagerModelKeys($entities)); } @@ -144,7 +144,7 @@ protected function getEagerModelKeys(array $entities) foreach ($entities as $entity) { $entity = $this->factory->make($entity); - if (! is_null($value = $entity->getEntityAttribute($this->foreignKey))) { + if (!is_null($value = $entity->getEntityAttribute($this->foreignKey))) { $keys[] = $value; } } @@ -286,7 +286,7 @@ public function getForeignKeyValuePair($related) */ public function getQualifiedForeignKey() { - return $this->parentMap->getTable().'.'.$this->foreignKey; + return $this->parentMap->getTable() . '.' . $this->foreignKey; } /** @@ -306,6 +306,6 @@ public function getOtherKey() */ public function getQualifiedOtherKeyName() { - return $this->relatedMap->getTable().'.'.$this->otherKey; + return $this->relatedMap->getTable() . '.' . $this->otherKey; } } diff --git a/src/Relationships/BelongsToMany.php b/src/Relationships/BelongsToMany.php index d31cf58..bb9860d 100755 --- a/src/Relationships/BelongsToMany.php +++ b/src/Relationships/BelongsToMany.php @@ -132,7 +132,7 @@ public function getResults($relation) */ public function wherePivot($column, $operator = null, $value = null, $boolean = 'and') { - return $this->where($this->table.'.'.$column, $operator, $value, $boolean); + return $this->where($this->table . '.' . $column, $operator, $value, $boolean); } /** @@ -181,7 +181,7 @@ public function first($columns = ['*']) */ public function firstOrFail($columns = ['*']) { - if (! is_null($entity = $this->first($columns))) { + if (!is_null($entity = $this->first($columns))) { return $entity; } @@ -312,11 +312,11 @@ public function getRelationCountQueryForSelfJoin(Query $query, Query $parent) $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); - $query->from($this->table.' as '.$tablePrefix.$hash = $this->getRelationCountHash()); + $query->from($this->table . ' as ' . $tablePrefix . $hash = $this->getRelationCountHash()); $key = $this->wrap($this->getQualifiedParentKeyName()); - return $query->where($hash.'.'.$this->foreignKey, '=', new Expression($key)); + return $query->where($hash . '.' . $this->foreignKey, '=', new Expression($key)); } /** @@ -326,7 +326,7 @@ public function getRelationCountQueryForSelfJoin(Query $query, Query $parent) */ public function getRelationCountHash() { - return 'self_'.md5(microtime(true)); + return 'self_' . md5(microtime(true)); } /** @@ -338,7 +338,7 @@ public function getRelationCountHash() protected function getSelectColumns(array $columns = ['*']) { if ($columns == ['*']) { - $columns = [$this->relatedMap->getTable().'.*']; + $columns = [$this->relatedMap->getTable() . '.*']; } return array_merge($columns, $this->getAliasedPivotColumns()); @@ -359,7 +359,7 @@ protected function getAliasedPivotColumns() $columns = []; foreach (array_merge($defaults, $this->pivotColumns) as $column) { - $columns[] = $this->table.'.'.$column.' as pivot_'.$column; + $columns[] = $this->table . '.' . $column . ' as pivot_' . $column; } return array_unique($columns); @@ -380,7 +380,7 @@ protected function setJoin($query = null) // model instance. Then we can set the "where" for the parent models. $baseTable = $this->relatedMap->getTable(); - $key = $baseTable.'.'.$this->relatedMap->getKeyName(); + $key = $baseTable . '.' . $this->relatedMap->getKeyName(); $query->join($this->table, $key, '=', $this->getOtherKey()); @@ -719,7 +719,7 @@ protected function setTimestampsOnAttach(array $record, $exists = false) { $fresh = $this->freshTimestamp(); - if (! $exists) { + if (!$exists) { $record[$this->createdAt()] = $fresh; } @@ -732,7 +732,7 @@ protected function getModelKeysFromCollection(EntityCollection $entities) { $keyName = $this->relatedMap->getKeyName(); - return array_map(function ($m) use ($keyName) { return $m->$keyName; }, $entities); + return array_map(function($m) use ($keyName) { return $m->$keyName; }, $entities); } /** @@ -744,7 +744,7 @@ protected function getModelKeysFromCollection(EntityCollection $entities) public function detach($ids = []) { if ($ids instanceof EntityCollection) { - $ids = (array)$ids->modelKeys(); + $ids = (array) $ids->modelKeys(); } $query = $this->newPivotQuery(); @@ -755,7 +755,7 @@ public function detach($ids = []) $ids = (array) $ids; if (count($ids) > 0) { - $query->whereIn($this->otherKey, (array)$ids); + $query->whereIn($this->otherKey, (array) $ids); } // Once we have all of the conditions set on the statement, we are ready diff --git a/src/Relationships/HasManyThrough.php b/src/Relationships/HasManyThrough.php index f62f6ac..f395c35 100755 --- a/src/Relationships/HasManyThrough.php +++ b/src/Relationships/HasManyThrough.php @@ -83,7 +83,7 @@ public function addConstraints() if (static::$constraints) { $farParentKeyName = $this->farParentMap->getKeyName(); - $this->query->where($parentTable.'.'.$this->firstKey, + $this->query->where($parentTable . '.' . $this->firstKey, '=', $this->farParent->getEntityAttribute($farParentKeyName)); } } @@ -103,7 +103,7 @@ public function getRelationCountQuery(Query $query, Query $parent) $query->select(new Expression('count(*)')); - $key = $this->wrap($parentTable.'.'.$this->firstKey); + $key = $this->wrap($parentTable . '.' . $this->firstKey); return $query->where($this->getHasCompareKey(), '=', new Expression($key)); } @@ -118,7 +118,7 @@ protected function setJoin(Query $query = null) { $query = $query ?: $this->query; - $foreignKey = $this->relatedMap->getTable().'.'.$this->secondKey; + $foreignKey = $this->relatedMap->getTable() . '.' . $this->secondKey; $query->join($this->parentMap->getTable(), $this->getQualifiedParentKeyName(), '=', $foreignKey); } @@ -133,7 +133,7 @@ public function addEagerConstraints(array $entities) { $table = $this->parentMap->getTable(); - $this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($entities)); + $this->query->whereIn($table . '.' . $this->firstKey, $this->getKeys($entities)); } /** @@ -256,10 +256,10 @@ public function get($columns = ['*']) protected function getSelectColumns(array $columns = ['*']) { if ($columns == ['*']) { - $columns = [$this->relatedMap->getTable().'.*']; + $columns = [$this->relatedMap->getTable() . '.*']; } - return array_merge($columns, [$this->parentMap->getTable().'.'.$this->firstKey]); + return array_merge($columns, [$this->parentMap->getTable() . '.' . $this->firstKey]); } /** diff --git a/src/Relationships/HasOneOrMany.php b/src/Relationships/HasOneOrMany.php index f8000af..91b7bfc 100755 --- a/src/Relationships/HasOneOrMany.php +++ b/src/Relationships/HasOneOrMany.php @@ -291,7 +291,7 @@ public function getParentKey() */ public function getQualifiedParentKeyName() { - return $this->parentMap->getTable().'.'.$this->localKey; + return $this->parentMap->getTable() . '.' . $this->localKey; } /** diff --git a/src/Relationships/MorphTo.php b/src/Relationships/MorphTo.php index 6c2e8a6..fb241d5 100755 --- a/src/Relationships/MorphTo.php +++ b/src/Relationships/MorphTo.php @@ -163,7 +163,7 @@ protected function gatherKeysByType($type) { $foreign = $this->foreignKey; - return BaseCollection::make($this->dictionary[$type])->map(function ($entities) use ($foreign) { + return BaseCollection::make($this->dictionary[$type])->map(function($entities) use ($foreign) { return head($entities)->{$foreign}; })->unique(); diff --git a/src/Relationships/MorphToMany.php b/src/Relationships/MorphToMany.php index 71c296c..1780a0d 100755 --- a/src/Relationships/MorphToMany.php +++ b/src/Relationships/MorphToMany.php @@ -49,7 +49,7 @@ public function __construct(Mapper $mapper, $parent, $name, $table, $foreignKey, { $this->inverse = $inverse; - $this->morphType = $name.'_type'; + $this->morphType = $name . '_type'; $this->morphClass = $inverse ? $mapper->getEntityMap()->getClass() : get_class($parent); @@ -65,7 +65,7 @@ protected function setWhere() { parent::setWhere(); - $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + $this->query->where($this->table . '.' . $this->morphType, $this->morphClass); return $this; } @@ -81,7 +81,7 @@ public function getRelationCountQuery(Query $query, Query $parent) { $query = parent::getRelationCountQuery($query, $parent); - return $query->where($this->table.'.'.$this->morphType, $this->morphClass); + return $query->where($this->table . '.' . $this->morphType, $this->morphClass); } /** @@ -94,7 +94,7 @@ public function addEagerConstraints(array $entities) { parent::addEagerConstraints($entities); - $this->query->where($this->table.'.'.$this->morphType, $this->morphClass); + $this->query->where($this->table . '.' . $this->morphType, $this->morphClass); } /** diff --git a/src/Relationships/Relationship.php b/src/Relationships/Relationship.php index 4a32548..3b51785 100755 --- a/src/Relationships/Relationship.php +++ b/src/Relationships/Relationship.php @@ -252,8 +252,8 @@ protected function getKeys(array $entities, $key = null) $host = $this; - return array_unique(array_values(array_map(function ($value) use ($key, $host) { - if (! $value instanceof InternallyMappable) { + return array_unique(array_values(array_map(function($value) use ($key, $host) { + if (!$value instanceof InternallyMappable) { $value = $host->factory->make($value); } @@ -412,7 +412,7 @@ protected function getEntityHash(Mappable $entity) $keyName = Mapper::getMapper($class)->getEntityMap()->getKeyName(); - $hash = $class.'.'.$entity->getEntityAttribute($keyName); + $hash = $class . '.' . $entity->getEntityAttribute($keyName); return $hash; } diff --git a/src/ValueObject.php b/src/ValueObject.php index 7654549..0f4abc1 100755 --- a/src/ValueObject.php +++ b/src/ValueObject.php @@ -147,7 +147,7 @@ protected function attributesToArray(array $sourceAttributes) foreach ($sourceAttributes as $key => $attribute) { // If the attribute is a proxy, and hasn't be loaded, we discard // it from the returned set. - if ($attribute instanceof ProxyInterface && ! $attribute->isLoaded()) { + if ($attribute instanceof ProxyInterface && !$attribute->isLoaded()) { continue; } From db1a64f382323224266c7a2bd52ae6ad7fbd0b7e Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 8 Jan 2016 14:40:22 +0000 Subject: [PATCH 4/9] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Analogue.php | 2 +- src/AnalogueServiceProvider.php | 2 +- src/Commands/Store.php | 10 ++-- src/Entity.php | 14 +++--- src/EntityCollection.php | 14 +++--- src/EntityMap.php | 7 +-- src/Plugins/SoftDeletes/SoftDeletesPlugin.php | 8 +-- src/Plugins/Timestamps/TimestampsPlugin.php | 6 +-- src/Relationships/BelongsToMany.php | 19 +++---- src/Relationships/HasManyThrough.php | 11 ++-- src/Relationships/HasOne.php | 4 +- src/Relationships/HasOneOrMany.php | 2 - src/Relationships/MorphOneOrMany.php | 1 - src/Relationships/MorphPivot.php | 2 +- src/Relationships/MorphToMany.php | 7 ++- src/Relationships/Pivot.php | 3 +- src/Relationships/Relationship.php | 2 +- src/Repository.php | 6 +-- src/System/Aggregate.php | 48 +++++++++--------- src/System/EntityBuilder.php | 12 ++--- src/System/EntityCache.php | 15 +++--- src/System/Manager.php | 50 +++++++++---------- src/System/Mapper.php | 21 ++++---- src/System/Proxies/CollectionProxy.php | 2 +- src/System/Proxies/EntityProxy.php | 8 +-- src/System/Query.php | 21 ++++---- src/System/Wrappers/PlainObjectWrapper.php | 21 ++++---- src/System/Wrappers/Wrapper.php | 2 +- 28 files changed, 156 insertions(+), 164 deletions(-) diff --git a/src/Analogue.php b/src/Analogue.php index 7be4969..15d87cf 100755 --- a/src/Analogue.php +++ b/src/Analogue.php @@ -25,7 +25,7 @@ class Analogue public function __construct(array $connection) { - if (! static::$booted) { + if (!static::$booted) { static::$capsule = new Capsule; $this->addConnection($connection); diff --git a/src/AnalogueServiceProvider.php b/src/AnalogueServiceProvider.php index c41d71d..2ebc711 100755 --- a/src/AnalogueServiceProvider.php +++ b/src/AnalogueServiceProvider.php @@ -35,7 +35,7 @@ public function boot() */ public function register() { - $this->app->singleton('analogue', function ($app) { + $this->app->singleton('analogue', function($app) { $db = $app['db']; diff --git a/src/Commands/Store.php b/src/Commands/Store.php index ddbf25c..a775eee 100755 --- a/src/Commands/Store.php +++ b/src/Commands/Store.php @@ -35,7 +35,7 @@ public function execute() * We will test the entity for existence * and run a creation if it doesn't exists */ - if (! $this->aggregate->exists()) { + if (!$this->aggregate->exists()) { if ($mapper->fireEvent('creating', $entity) === false) { return false; } @@ -98,7 +98,7 @@ protected function createRelatedEntities($relations) * Create a new store command * * @param Aggregate $aggregate - * @return void + * @return Store */ protected function createStoreCommand(Aggregate $aggregate) { @@ -156,7 +156,7 @@ protected function updateDirtyRelated() $attributes = $this->getAttributes(); foreach ($relations as $relation) { - if (! array_key_exists($relation, $attributes)) { + if (!array_key_exists($relation, $attributes)) { continue; } @@ -173,7 +173,7 @@ protected function updateDirtyRelated() if ($value instanceof CollectionProxy && $value->isLoaded()) { $value = $value->getUnderlyingCollection(); } - if ($value instanceof CollectionProxy && ! $value->isLoaded()) { + if ($value instanceof CollectionProxy && !$value->isLoaded()) { foreach ($value->getAddedItems() as $entity) { $this->updateEntityIfDirty($entity); } @@ -182,7 +182,7 @@ protected function updateDirtyRelated() if ($value instanceof EntityCollection) { foreach ($value as $entity) { - if (! $this->createEntityIfNotExists($entity)) { + if (!$this->createEntityIfNotExists($entity)) { $this->updateEntityIfDirty($entity); } } diff --git a/src/Entity.php b/src/Entity.php index d27c707..94f3e9f 100755 --- a/src/Entity.php +++ b/src/Entity.php @@ -23,7 +23,7 @@ class Entity extends ValueObject public function __get($key) { if ($this->hasGetMutator($key)) { - $method = 'get'.$this->getMutatorMethod($key); + $method = 'get' . $this->getMutatorMethod($key); $attribute = null; @@ -33,7 +33,7 @@ public function __get($key) return $this->$method($attribute); } - if (! array_key_exists($key, $this->attributes)) { + if (!array_key_exists($key, $this->attributes)) { return null; } if ($this->attributes[$key] instanceof EntityProxy) { @@ -52,7 +52,7 @@ public function __get($key) public function __set($key, $value) { if ($this->hasSetMutator($key)) { - $method = 'set'.$this->getMutatorMethod($key); + $method = 'set' . $this->getMutatorMethod($key); $this->$method($value); } else { @@ -68,7 +68,7 @@ public function __set($key, $value) */ protected function hasGetMutator($key) { - return method_exists($this, 'get'.$this->getMutatorMethod($key)) ? true : false; + return method_exists($this, 'get' . $this->getMutatorMethod($key)) ? true : false; } /** @@ -79,12 +79,12 @@ protected function hasGetMutator($key) */ protected function hasSetMutator($key) { - return method_exists($this, 'set'.$this->getMutatorMethod($key)) ? true : false; + return method_exists($this, 'set' . $this->getMutatorMethod($key)) ? true : false; } protected function getMutatorMethod($key) { - return ucfirst($key).'Attribute'; + return ucfirst($key) . 'Attribute'; } /** @@ -104,7 +104,7 @@ public function toArray() continue; } if ($this->hasGetMutator($key)) { - $method = 'get'.$this->getMutatorMethod($key); + $method = 'get' . $this->getMutatorMethod($key); $attributes[$key] = $this->$method($attribute); } } diff --git a/src/EntityCollection.php b/src/EntityCollection.php index bc43f66..6c0e781 100755 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -37,7 +37,7 @@ public function find($key, $default = null) $key = $this->getEntityKey($key); } - return array_first($this->items, function ($itemKey, $entity) use ($key) { + return array_first($this->items, function($itemKey, $entity) use ($key) { return $this->getEntityKey($entity) == $key; }, $default); } @@ -133,14 +133,14 @@ public function fetch($key) */ public function getEntityHashes() { - return array_map(function ($entity) { + return array_map(function($entity) { $class = get_class($entity); $mapper = Manager::getMapper($class); $keyName = $mapper->getEntityMap()->getKeyName(); - return $class.'.'.$entity->getEntityAttribute($keyName); + return $class . '.' . $entity->getEntityAttribute($keyName); }, $this->items); } @@ -162,7 +162,7 @@ public function getSubsetByHashes(array $hashes) $keyName = $mapper->getEntityMap()->getKeyName(); - if (in_array($class.'.'.$item->$keyName, $hashes)) { + if (in_array($class . '.' . $item->$keyName, $hashes)) { $subset[] = $item; } } @@ -200,7 +200,7 @@ public function diff($items) $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { - if (! isset($dictionary[$this->getEntityKey($item)])) { + if (!isset($dictionary[$this->getEntityKey($item)])) { $diff->add($item); } } @@ -296,7 +296,7 @@ protected function getEntityKey($entity) */ public function max($key = null) { - return $this->reduce(function ($result, $item) use ($key) { + return $this->reduce(function($result, $item) use ($key) { $wrapper = $this->factory->make($item); return (is_null($result) || $wrapper->getEntityAttribute($key) > $result) ? @@ -312,7 +312,7 @@ public function max($key = null) */ public function min($key = null) { - return $this->reduce(function ($result, $item) use ($key) { + return $this->reduce(function($result, $item) use ($key) { $wrapper = $this->factory->make($item); return (is_null($result) || $wrapper->getEntityAttribute($key) < $result) diff --git a/src/EntityMap.php b/src/EntityMap.php index 2a09af0..88daff3 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -410,6 +410,7 @@ public function getClass() * Set the custom entity class * * @param string namespaced class name + * @param string $class */ public function setClass($class) { @@ -649,7 +650,7 @@ public function getForeignKey() * Define a one-to-one relationship. * * @param $entity - * @param string $related entity class + * @param string $relatedClass entity class * @param string $foreignKey * @param string $localKey * @return \Analogue\ORM\Relationships\HasOne @@ -960,7 +961,7 @@ protected function getBelongsToManyCaller() /** * Get the joining table name for a many-to-many relation. * - * @param string $related + * @param EntityMap $relatedMap * @return string */ public function joiningTable($relatedMap) @@ -988,7 +989,7 @@ public function joiningTable($relatedMap) * @param string $name * @param string $type * @param string $id - * @return array + * @return string[] */ protected function getMorphs($name, $type, $id) { diff --git a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php index 2791c54..cefeaf6 100755 --- a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php +++ b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php @@ -23,7 +23,7 @@ public function register() $host = $this; // Hook any mapper init and check the mapping include soft deletes. - $this->manager->registerGlobalEvent('initialized', function ($mapper) use ($host) { + $this->manager->registerGlobalEvent('initialized', function($mapper) use ($host) { $entityMap = $mapper->getEntityMap(); if ($entityMap->usesSoftDeletes()) { @@ -50,7 +50,7 @@ protected function registerSoftDelete(Mapper $mapper) $host = $this; // Register 'deleting' events - $mapper->registerEvent('deleting', function ($entity) use ($entityMap, $host) { + $mapper->registerEvent('deleting', function($entity) use ($entityMap, $host) { // Convert Entity into an EntityWrapper $factory = new Factory; @@ -62,7 +62,7 @@ protected function registerSoftDelete(Mapper $mapper) if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) { return true; } else { - $time= new Carbon; + $time = new Carbon; $wrappedEntity->setEntityAttribute($deletedAtField, $time); @@ -81,7 +81,7 @@ protected function registerSoftDelete(Mapper $mapper) /** * Get custom events provided by the plugin * - * @return array + * @return string[] */ public function getCustomEvents() { diff --git a/src/Plugins/Timestamps/TimestampsPlugin.php b/src/Plugins/Timestamps/TimestampsPlugin.php index 069fc58..bcd18e9 100755 --- a/src/Plugins/Timestamps/TimestampsPlugin.php +++ b/src/Plugins/Timestamps/TimestampsPlugin.php @@ -18,11 +18,11 @@ class TimestampsPlugin extends AnaloguePlugin */ public function register() { - $this->manager->registerGlobalEvent('initialized', function ($mapper) { + $this->manager->registerGlobalEvent('initialized', function($mapper) { $entityMap = $mapper->getEntityMap(); if ($entityMap->usesTimestamps()) { - $mapper->registerEvent('creating', function ($entity) use ($entityMap) { + $mapper->registerEvent('creating', function($entity) use ($entityMap) { $factory = new Factory; $wrappedEntity = $factory->make($entity); @@ -37,7 +37,7 @@ public function register() }); - $mapper->registerEvent('updating', function ($entity) use ($entityMap) { + $mapper->registerEvent('updating', function($entity) use ($entityMap) { $factory = new Factory; $wrappedEntity = $factory->make($entity); diff --git a/src/Relationships/BelongsToMany.php b/src/Relationships/BelongsToMany.php index bb9860d..2e2eeef 100755 --- a/src/Relationships/BelongsToMany.php +++ b/src/Relationships/BelongsToMany.php @@ -110,7 +110,7 @@ protected function getIdsFromHashes(array $hashes) /** * Get the results of the relationship. * - * @return mixed + * @return EntityCollection */ public function getResults($relation) { @@ -284,9 +284,9 @@ public function addConstraints() /** * Add the constraints for a relationship count query. * - * @param \Analogue\ORM\Query $query - * @param \Analogue\ORM\Query $parent - * @return \Analogue\ORM\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { @@ -302,9 +302,9 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Add the constraints for a relationship count query on the same table. * - * @param \Analogue\ORM\Query $query - * @param \Analogue\ORM\Query $parent - * @return \Analogue\ORM\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQueryForSelfJoin(Query $query, Query $parent) { @@ -369,6 +369,7 @@ protected function getAliasedPivotColumns() * Set the join clause for the relation query. * * @param \Analogue\ORM\Query|null + * @param Query $query * @return $this */ protected function setJoin($query = null) @@ -559,7 +560,7 @@ public function createPivots($relatedEntities) * * @param mixed $id * @param array $attributes - * @return void + * @return integer */ public function updateExistingPivot($id, array $attributes) { @@ -667,7 +668,7 @@ protected function attacher($key, $value, $attributes, $timed) /** * Get the attach record ID and extra attributes. * - * @param mixed $key + * @param integer $key * @param mixed $value * @param array $attributes * @return array diff --git a/src/Relationships/HasManyThrough.php b/src/Relationships/HasManyThrough.php index f395c35..582ed15 100755 --- a/src/Relationships/HasManyThrough.php +++ b/src/Relationships/HasManyThrough.php @@ -40,8 +40,7 @@ class HasManyThrough extends Relationship /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\System\Query $query - * @param Mappable $parent + * @param \Analogue\ORM\EntityMap $parentMap * @param string $firstKey * @param string $secondKey * @return void @@ -91,9 +90,9 @@ public function addConstraints() /** * Add the constraints for a relationship count query. * - * @param \Analogue\ORM\Query $query - * @param \Analogue\ORM\Query $parent - * @return \Analogue\ORM\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { @@ -111,7 +110,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Set the join clause on the query. * - * @param \Analogue\ORM\Query|null $query + * @param null|Query $query * @return void */ protected function setJoin(Query $query = null) diff --git a/src/Relationships/HasOne.php b/src/Relationships/HasOne.php index 6e80d79..aafa6ec 100755 --- a/src/Relationships/HasOne.php +++ b/src/Relationships/HasOne.php @@ -34,7 +34,6 @@ public function fetch() /** * Initialize the relation on a set of entities. * - * @param array $models * @param string $relation * @return array */ @@ -50,8 +49,7 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $models - * @param Analogue\ORM\EntityCollection $results + * @param EntityCollection $results * @param string $relation * @return array */ diff --git a/src/Relationships/HasOneOrMany.php b/src/Relationships/HasOneOrMany.php index 91b7bfc..dc8143f 100755 --- a/src/Relationships/HasOneOrMany.php +++ b/src/Relationships/HasOneOrMany.php @@ -24,8 +24,6 @@ abstract class HasOneOrMany extends Relationship /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\System\Query $query - * @param Mappable $parent * @param string $foreignKey * @param string $localKey * @return void diff --git a/src/Relationships/MorphOneOrMany.php b/src/Relationships/MorphOneOrMany.php index 1266a05..15a372a 100755 --- a/src/Relationships/MorphOneOrMany.php +++ b/src/Relationships/MorphOneOrMany.php @@ -24,7 +24,6 @@ abstract class MorphOneOrMany extends HasOneOrMany /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\System\Query $query * @param Mappable $parent * @param string $type * @param string $id diff --git a/src/Relationships/MorphPivot.php b/src/Relationships/MorphPivot.php index 9dafb7c..e7ef88d 100755 --- a/src/Relationships/MorphPivot.php +++ b/src/Relationships/MorphPivot.php @@ -27,7 +27,7 @@ class MorphPivot extends Pivot /** * Set the keys for a save update query. * - * @param \Analogue\ORM\Query $query + * @param Query $query * @return \Analogue\ORM\Query */ protected function setKeysForSaveQuery(Query $query) diff --git a/src/Relationships/MorphToMany.php b/src/Relationships/MorphToMany.php index 1780a0d..74f60b6 100755 --- a/src/Relationships/MorphToMany.php +++ b/src/Relationships/MorphToMany.php @@ -35,7 +35,6 @@ class MorphToMany extends BelongsToMany /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\Query $query * @param \Analogue\ORM\Entityl $parent * @param string $name * @param string $table @@ -73,9 +72,9 @@ protected function setWhere() /** * Add the constraints for a relationship count query. * - * @param \Analogue\ORM\Query $query - * @param \Analogue\ORM\Query $parent - * @return \Analogue\ORM\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { diff --git a/src/Relationships/Pivot.php b/src/Relationships/Pivot.php index 682767d..82c4c23 100755 --- a/src/Relationships/Pivot.php +++ b/src/Relationships/Pivot.php @@ -68,10 +68,11 @@ class Pivot extends Entity /** * Create a new pivot model instance. * - * @param $parent + * @param \Analogue\ORM\System\InternallyMappable $parent * @param array $attributes * @param string $table * @param bool $exists + * @param \Analogue\ORM\EntityMap $parentMap * @return void */ public function __construct($parent, $parentMap, $attributes, $table, $exists = false) diff --git a/src/Relationships/Relationship.php b/src/Relationships/Relationship.php index 3b51785..ec01daa 100755 --- a/src/Relationships/Relationship.php +++ b/src/Relationships/Relationship.php @@ -285,7 +285,7 @@ public function getBaseQuery() /** * Get the parent model of the relation. * - * @return Mappable + * @return InternallyMappable */ public function getParent() { diff --git a/src/Repository.php b/src/Repository.php index 4cd70a1..9e2c863 100755 --- a/src/Repository.php +++ b/src/Repository.php @@ -23,7 +23,7 @@ class Repository * - Mappable object instance * - Instance of mapper * - * @param Mapper|Mappable|string $mapper + * @param Mapper $mapper * @param EntityMap $entityMap (optional) * * @throws \InvalidArgumentException @@ -96,7 +96,7 @@ public function paginate($perPage = null) * Delete an entity or an entity collection from the database * * @param Mappable|Collection $entity - * @return null + * @return \Illuminate\Support\Collection|null */ public function delete($entity) { @@ -126,7 +126,7 @@ public function __call($method, $parameters) if ($this->mapper->hasCustomCommand($method)) { call_user_func_array([$this->mapper, $method], $parameters); } else { - throw new Exception("No method $method on ".get_class($this)); + throw new Exception("No method $method on " . get_class($this)); } } } diff --git a/src/System/Aggregate.php b/src/System/Aggregate.php index 9ffa7c0..529c398 100755 --- a/src/System/Aggregate.php +++ b/src/System/Aggregate.php @@ -122,7 +122,7 @@ protected function parseRelationships() */ protected function parseForCommonValues($relation) { - if (! $this->hasAttribute($relation)) { + if (!$this->hasAttribute($relation)) { // If no attribute exists for this relationships // we'll make it a simple empty array. This will // save us from constantly checking for the attributes @@ -151,11 +151,11 @@ protected function parseForCommonValues($relation) * Parse a 'single' relationship * * @param string $relation - * @return void|boolean + * @return boolean */ protected function parseSingleRelationship($relation) { - if (! $value = $this->parseForCommonValues($relation)) { + if (!$value = $this->parseForCommonValues($relation)) { return true; } @@ -163,7 +163,7 @@ protected function parseSingleRelationship($relation) throw new MappingException("Entity's attribute $relation should not be array, or collection"); } - if ($value instanceof EntityProxy && ! $value->isLoaded()) { + if ($value instanceof EntityProxy && !$value->isLoaded()) { $this->relationships[$relation] = []; return true; } @@ -194,18 +194,18 @@ protected function parseSingleRelationship($relation) * Check if value isn't parent or root in the aggregate * * @param mixed - * @return boolean + * @return boolean|null */ protected function isParentOrRoot($value) { - if (! is_null($this->root)) { + if (!is_null($this->root)) { $rootClass = get_class($this->root->getEntityObject()); if ($rootClass == get_class($value)) { return true; } } - if (! is_null($this->parent)) { + if (!is_null($this->parent)) { $parentClass = get_class($this->parent->getEntityObject()); if ($parentClass == get_class($value)) { return true; @@ -221,7 +221,7 @@ protected function isParentOrRoot($value) */ protected function parseManyRelationship($relation) { - if (! $value = $this->parseForCommonValues($relation)) { + if (!$value = $this->parseForCommonValues($relation)) { return true; } @@ -236,13 +236,13 @@ protected function parseManyRelationship($relation) $value = $value->getUnderlyingCollection(); } - if ($value instanceof CollectionProxy && ! $value->isLoaded()) { + if ($value instanceof CollectionProxy && !$value->isLoaded()) { $value = $value->getAddedItems(); } // At this point $value should be either an array or an instance // of a collection class. - if (! is_array($value) && ! $value instanceof Collection) { + if (!is_array($value) && !$value instanceof Collection) { throw new MappingException("'$relation' attribute should be array() or Collection"); } @@ -273,6 +273,7 @@ protected function getRelationshipValue($relation) * Create a child, aggregated entity * * @param mixed $entities + * @param string $relation * @return */ protected function createSubAggregates($entities, $relation) @@ -343,7 +344,7 @@ public function getEntityMap() */ public function getEntityHash() { - return $this->getEntityClass().'.'.$this->getEntityId(); + return $this->getEntityClass() . '.' . $this->getEntityId(); } /** @@ -421,7 +422,7 @@ protected function getNonExistingFromRelation($relation) $nonExisting = []; foreach ($this->relationships[$relation] as $aggregate) { - if (! $aggregate->exists()) { + if (!$aggregate->exists()) { $nonExisting[] = $aggregate; } } @@ -470,7 +471,7 @@ public function getMissingEntities($relation) $missing = []; foreach ($cachedRelations as $hash) { - if (! $this->getRelatedAggregateFromHash($hash, $relation)) { + if (!$this->getRelatedAggregateFromHash($hash, $relation)) { $missing[] = $hash; } } @@ -492,7 +493,7 @@ public function getDirtyRelationships() foreach ($this->relationships as $relation) { foreach ($relation as $aggregate) { - if (! $aggregate->exists() || $aggregate->isDirty() || count($aggregate->getDirtyRelationships() > 0)) { + if (!$aggregate->exists() || $aggregate->isDirty() || count($aggregate->getDirtyRelationships() > 0)) { $dirtyAggregates[] = $aggregate; } } @@ -561,7 +562,7 @@ protected function flattenEmbeddables($attributes) $prefix = snake_case(class_basename($embed)); foreach ($valueObjectAttributes as $key=>$value) { - $valueObjectAttributes[$prefix.'_'.$key] = $value; + $valueObjectAttributes[$prefix . '_' . $key] = $value; unset($valueObjectAttributes[$key]); } @@ -597,7 +598,7 @@ protected function getCachedAttribute($key) { $cachedAttributes = $this->getCache()->get($this->getEntityId()); - if (! array_key_exists($key, $cachedAttributes)) { + if (!array_key_exists($key, $cachedAttributes)) { return null; } else { return $cachedAttributes[$key]; @@ -621,7 +622,7 @@ protected function getForeignKeyAttributes() } } - if (! is_null($this->parent)) { + if (!is_null($this->parent)) { $foreignKeys = $foreignKeys + $this->getForeignKeyAttributesFromParent(); } @@ -655,7 +656,6 @@ protected function getForeignKeyAttributesFromRelation($relation) * Get foreign key attribute(s) from a parent entity in this * aggregate context * - * @param string $relation * @return array */ protected function getForeignKeyAttributesFromParent() @@ -668,7 +668,7 @@ protected function getForeignKeyAttributesFromParent() $parentRelation = $this->parentRelationship; if (in_array($parentRelation, $parentForeignRelations) - && ! in_array($parentRelation, $parentPivotRelations)) { + && !in_array($parentRelation, $parentPivotRelations)) { $parentObject = $this->parent->getEntityObject(); // Call Relationship's method on parent map @@ -776,7 +776,7 @@ protected function getDirtyAttributes(array $actual, array $cached) $dirty = []; foreach ($actual as $key => $value) { - if (! $this->originalIsNumericallyEquivalent($value, $cached[$key])) { + if (!$this->originalIsNumericallyEquivalent($value, $cached[$key])) { $dirty[$key] = $actual[$key]; } } @@ -817,7 +817,7 @@ protected function getRelatedAggregatesFromHashes(array $hashes, $relation) foreach ($hashes as $hash) { $aggregate = $this->getRelatedAggregateFromHash($hash, $relation); - if (! is_null($aggregate)) { + if (!is_null($aggregate)) { $related[] = $aggregate; } } @@ -850,7 +850,7 @@ protected function getRelatedAggregateFromHash($hash, $relation) */ protected function getEntityHashesFromRelation($relation) { - return array_map(function ($aggregate) { + return array_map(function($aggregate) { return $aggregate->getEntityHash(); }, $this->relationships[$relation]); } @@ -895,10 +895,10 @@ public function getDirtyRawAttributes() continue; } - if (! array_key_exists($key, $cachedAttributes) && ! $value instanceof Pivot) { + if (!array_key_exists($key, $cachedAttributes) && !$value instanceof Pivot) { $dirty[$key] = $value; } elseif ($value !== $cachedAttributes[$key] && - ! $this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) { + !$this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) { $dirty[$key] = $value; } } diff --git a/src/System/EntityBuilder.php b/src/System/EntityBuilder.php index 263fbc4..585c391 100755 --- a/src/System/EntityBuilder.php +++ b/src/System/EntityBuilder.php @@ -84,7 +84,7 @@ public function build(array $results) $resultArray = (array) $result; - $tmpCache[$resultArray[$keyName] ] = $resultArray; + $tmpCache[$resultArray[$keyName]] = $resultArray; // Hydrate any embedded Value Object $this->hydrateValueObjects($resultArray); @@ -109,7 +109,7 @@ public function build(array $results) /** * Get the correct wrapper prototype corresponding to the object type * - * @return mixed + * @return InternallyMappable */ protected function getWrapperInstance() { @@ -148,13 +148,13 @@ protected function hydrateValueObject(& $attributes, $localKey, $valueClass) $valueObject = $this->mapper->getManager()->getValueObjectInstance($valueClass); foreach ($embeddedAttributes as $key) { - $prefix = snake_case(class_basename($valueClass)).'_'; + $prefix = snake_case(class_basename($valueClass)) . '_'; $voWrapper = $this->factory->make($valueObject); - $voWrapper->setEntityAttribute($key, $attributes[$prefix.$key]); + $voWrapper->setEntityAttribute($key, $attributes[$prefix . $key]); - unset($attributes[$prefix.$key]); + unset($attributes[$prefix . $key]); } $attributes[$localKey] = $valueObject; @@ -175,7 +175,7 @@ protected function prepareLazyLoading() /** * Build lazy loading proxies for the current entity * - * @param \Analogue\ORM\Mappable $entity + * @param InternallyMappable $entity * * @return array */ diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index ea55f3a..37627ce 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -127,7 +127,7 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation { $keyName = $this->entityMap->getKeyName(); - if (! $parent instanceof InternallyMappable) { + if (!$parent instanceof InternallyMappable) { $parent = $this->factory->make($parent); } @@ -157,7 +157,7 @@ protected function getCachedRelationship($parentKey, $relation, $result, Relatio { $pivotColumns = $relationship->getPivotAttributes(); - if (! array_key_exists($relation, $this->pivotAttributes)) { + if (!array_key_exists($relation, $this->pivotAttributes)) { $this->pivotAttributes[$relation] = $pivotColumns; } @@ -187,8 +187,8 @@ protected function getCachedRelationship($parentKey, $relation, $result, Relatio * Cache a many relationship * * @param [type] $parentKey [description] - * @param [type] $relation [description] - * @param [type] $results [description] + * @param string $relation [description] + * @param EntityCollection $results [description] * @param Relationship $relationship [description] * @return [type] [description] */ @@ -209,8 +209,8 @@ protected function cacheManyRelationResults($parentKey, $relation, $results, Rel * Cache a single relationship * * @param [type] $parentKey [description] - * @param [type] $relation [description] - * @param [type] $results [description] + * @param string $relation [description] + * @param Mappable $result [description] * @param Relationship $relationship [description] * @return [type] [description] */ @@ -233,7 +233,7 @@ protected function getEntityHash(InternallyMappable $entity) $keyName = $mapper->getEntityMap()->getKeyName(); - return $class.'.'.$entity->getEntityAttribute($keyName); + return $class . '.' . $entity->getEntityAttribute($keyName); } /** @@ -250,7 +250,6 @@ public function refresh(Aggregate $entity) /** * Transform an Aggregated Entity into a cache record * - * @param Aggregate $entity * @return array */ protected function transform(Aggregate $aggregatedEntity) diff --git a/src/System/Manager.php b/src/System/Manager.php index 99481d6..88571c4 100755 --- a/src/System/Manager.php +++ b/src/System/Manager.php @@ -118,7 +118,7 @@ public function mapper($entity, $entityMap = null) throw new MappingException('Tried to instantiate mapper on wrapped Entity'); } - if (! is_string($entity)) { + if (!is_string($entity)) { $entity = get_class($entity); } @@ -133,7 +133,7 @@ public function mapper($entity, $entityMap = null) /** * Build a new Mapper instance for a given Entity * - * @param mixed|string $entity + * @param string $entity * @param $entityMap * @return Mapper */ @@ -141,7 +141,7 @@ protected function buildMapper($entity, $entityMap) { // If an EntityMap hasn't been manually registered by the user // register it at runtime. - if (! $this->isRegisteredEntity($entity)) { + if (!$this->isRegisteredEntity($entity)) { $this->register($entity, $entityMap); } @@ -165,7 +165,7 @@ protected function buildMapper($entity, $entityMap) * Create a mapper for a given entity (static alias) * * @param \Analogue\ORM\Mappable|string $entity - * @param mixed $entityMap + * @param null|EntityMap $entityMap * @return Mapper */ public static function getMapper($entity, $entityMap = null) @@ -181,7 +181,7 @@ public static function getMapper($entity, $entityMap = null) */ public function repository($entity) { - if (! is_string($entity)) { + if (!is_string($entity)) { $entity = get_class($entity); } @@ -205,7 +205,7 @@ public function repository($entity) public function register($entity, $entityMap = null) { // If an object is provider, get the class name from it - if (! is_string($entity)) { + if (!is_string($entity)) { $entity = get_class($entity); } @@ -213,7 +213,7 @@ public function register($entity, $entityMap = null) throw new MappingException("Entity $entity is already registered."); } - if (! class_exists($entity)) { + if (!class_exists($entity)) { throw new MappingException("Class $entity does not exists"); } @@ -225,8 +225,8 @@ public function register($entity, $entityMap = null) $entityMap = new $entityMap; } - if (! $entityMap instanceof EntityMap) { - throw new MappingException(get_class($entityMap)." must be an instance of EntityMap."); + if (!$entityMap instanceof EntityMap) { + throw new MappingException(get_class($entityMap) . " must be an instance of EntityMap."); } $entityMap->setClass($entity); @@ -244,8 +244,8 @@ public function register($entity, $entityMap = null) */ protected function getEntityMapInstanceFor($entity) { - if (class_exists($entity.'Map')) { - $map = $entity.'Map'; + if (class_exists($entity . 'Map')) { + $map = $entity . 'Map'; $map = new $map; } else { // Generate an EntityMap obeject @@ -268,21 +268,21 @@ protected function getNewEntityMap() /** * Register a Value Object * - * @param string|ValueObject $valueObject + * @param string $valueObject * @param string $valueMap * @return void */ public function registerValueObject($valueObject, $valueMap = null) { - if (! is_string($valueObject)) { + if (!is_string($valueObject)) { $valueObject = get_class($valueObject); } if (is_null($valueMap)) { - $valueMap = $valueObject.'Map'; + $valueMap = $valueObject . 'Map'; } - if (! class_exists($valueMap)) { + if (!class_exists($valueMap)) { throw new MappingException("$valueMap doesn't exists"); } @@ -297,7 +297,7 @@ public function registerValueObject($valueObject, $valueMap = null) */ public function isValueObject($object) { - if (! is_string($object)) { + if (!is_string($object)) { $object = get_class($object); } @@ -312,11 +312,11 @@ public function isValueObject($object) */ public function getValueMap($valueObject) { - if (! is_string($valueObject)) { + if (!is_string($valueObject)) { $valueObject = get_class($valueObject); } - if (! array_key_exists($valueObject, $this->valueClasses)) { + if (!array_key_exists($valueObject, $this->valueClasses)) { $this->registerValueObject($valueObject); } $valueMap = new $this->valueClasses[$valueObject]; @@ -361,7 +361,7 @@ public function registerPlugin($plugin) */ public function isRegisteredEntity($entity) { - if (! is_string($entity)) { + if (!is_string($entity)) { $entity = get_class($entity); } @@ -373,7 +373,7 @@ public function isRegisteredEntity($entity) * of the entity. * * @param string $event - * @param closure|string $callback + * @param \Closure $callback * @return void */ public function registerGlobalEvent($event, $callback) @@ -399,7 +399,7 @@ public function store($entity) * Shortcut to Mapper delete * * @param mixed $entity - * @return mixed + * @return \Illuminate\Support\Collection|null */ public function delete($entity) { @@ -410,7 +410,7 @@ public function delete($entity) * Shortcut to Mapper query * * @param mixed $entity - * @return \Analogue\System\Query + * @return Query */ public function query($entity) { @@ -421,7 +421,7 @@ public function query($entity) * Shortcut to Mapper Global Query * * @param mixed $entity - * @return \Analogue\System\Query + * @return Query */ public function globalQuery($entity) { @@ -431,9 +431,7 @@ public function globalQuery($entity) /** * Return the Singleton instance of the manager * - * @param string $method - * @param array $parameters - * @return mixed + * @return Manager */ public static function getInstance() { diff --git a/src/System/Mapper.php b/src/System/Mapper.php index b032278..4bcd6a4 100755 --- a/src/System/Mapper.php +++ b/src/System/Mapper.php @@ -70,7 +70,7 @@ class Mapper protected $customCommands = []; /** - * @param EntityMap $entityMapper + * @param EntityMap $entityMap * @param DBAdapter $adapter * @param Dispatcher $dispatcher * @param Manager $manager @@ -165,7 +165,7 @@ protected function storeCollection($entities) * Delete an entity or an entity collection from the database * * @param mixed|Collection - * @return void + * @return Collection|null */ public function delete($entity) { @@ -244,7 +244,7 @@ public function fireEvent($event, $entity, $halt = true) throw new InvalidArgumentException("Fired Event with invalid Entity Object"); } - $event = "analogue.{$event}.".$this->entityMap->getClass(); + $event = "analogue.{$event}." . $this->entityMap->getClass(); $method = $halt ? 'until' : 'fire'; @@ -255,7 +255,7 @@ public function fireEvent($event, $entity, $halt = true) * Register an entity event with the dispatcher. * * @param string $event - * @param \Closure|string $callback + * @param \Closure $callback * @return void */ public function registerEvent($event, $callback) @@ -295,7 +295,7 @@ public function hasGlobalScope($scope) */ public function getGlobalScope($scope) { - return array_first($this->globalScopes, function ($key, $value) use ($scope) { + return array_first($this->globalScopes, function($key, $value) use ($scope) { return $scope instanceof $value; }); } @@ -313,7 +313,7 @@ public function getGlobalScopes() /** * Apply all of the global scopes to an Analogue Query builder. * - * @param \Analogue\ORM\System\Query $builder + * @param Query $query * @return \Analogue\ORM\System\Query */ public function applyGlobalScopes($query) @@ -328,7 +328,7 @@ public function applyGlobalScopes($query) /** * Remove all of the global scopes from an Analogue Query builder. * - * @param \Analogue\ORM\System\Query $builder + * @param Query $query * @return \Analogue\ORM\System\Query */ public function removeGlobalScopes($query) @@ -356,7 +356,7 @@ public function newQueryWithoutScope($scope) /** * Get a new query builder that doesn't have any global scopes. * - * @return Analogue\ORM\System\Query|static + * @return Query */ public function newQueryWithoutScopes() { @@ -398,7 +398,7 @@ public function executeCustomCommand($command, $entity) /** * Execute a single command instance * - * @param string $command + * @param string $commandClass * @param mixed $entity * @return mixed */ @@ -476,11 +476,12 @@ public function newInstance($attributes = []) * Use a trick to generate a class prototype that we * can instantiate without calling the constructor. * + * @param string|null $className * @return mixed */ protected function customClassInstance($className) { - if (! class_exists($className)) { + if (!class_exists($className)) { throw new MappingException("Tried to instantiate a non-existing Entity class : $className"); } diff --git a/src/System/Proxies/CollectionProxy.php b/src/System/Proxies/CollectionProxy.php index 8e113c9..675d9c7 100755 --- a/src/System/Proxies/CollectionProxy.php +++ b/src/System/Proxies/CollectionProxy.php @@ -222,7 +222,7 @@ public function getIterator() */ public function __call($method, $parameters) { - if (! $this->isLoaded()) { + if (!$this->isLoaded()) { $this->loadOnce(); } diff --git a/src/System/Proxies/EntityProxy.php b/src/System/Proxies/EntityProxy.php index 6eeba9b..6ae35d9 100755 --- a/src/System/Proxies/EntityProxy.php +++ b/src/System/Proxies/EntityProxy.php @@ -28,7 +28,7 @@ protected function loadOnce() */ public function getUnderlyingObject() { - if (! $this->isLoaded()) { + if (!$this->isLoaded()) { $this->loadOnce(); } @@ -43,7 +43,7 @@ public function getUnderlyingObject() */ public function __get($attribute) { - if (! $this->isLoaded()) { + if (!$this->isLoaded()) { $this->loadOnce(); } @@ -59,7 +59,7 @@ public function __get($attribute) */ public function __set($attribute, $value) { - if (! $this->isLoaded()) { + if (!$this->isLoaded()) { $this->loadOnce(); } @@ -75,7 +75,7 @@ public function __set($attribute, $value) */ public function __call($method, $parameters) { - if (! $this->isLoaded()) { + if (!$this->isLoaded()) { $this->loadOnce(); } diff --git a/src/System/Query.php b/src/System/Query.php index 41b9794..55d7e81 100755 --- a/src/System/Query.php +++ b/src/System/Query.php @@ -97,7 +97,6 @@ class Query /** * Create a new Analogue Query Builder instance. * - * @param \Analogue\ORM\Drivers\QueryAdapter $query * @param \Analogue\ORM\System\Mapper $mapper * @return void */ @@ -206,7 +205,7 @@ public function first($columns = ['*']) * Execute the query and get the first result or throw an exception. * * @param array $columns - * @return Mappable + * @return \Analogue\ORM\Entity * * @throws EntityNotFoundException */ @@ -274,7 +273,7 @@ public function lists($column, $key = null) * * @param int $perPage * @param array $columns - * @return \Illuminate\Pagination\Paginator + * @return LengthAwarePaginator */ public function paginate($perPage = null, $columns = ['*']) { @@ -468,7 +467,7 @@ protected function addHasWhere(Query $hasQuery, Relationship $relation, $operato $count = new Expression($count); } - return $this->where(new Expression('('.$hasQuery->toSql().')'), $operator, $count, $boolean); + return $this->where(new Expression('(' . $hasQuery->toSql() . ')'), $operator, $count, $boolean); } /** @@ -500,7 +499,7 @@ protected function mergeWheresToHas(Query $hasQuery, Relationship $relation) */ protected function getHasRelationQuery($relation, $entity) { - return Relationship::noConstraints(function () use ($relation, $entity) { + return Relationship::noConstraints(function() use ($relation, $entity) { return $this->entityMap->$relation($entity); }); } @@ -549,7 +548,7 @@ protected function parseRelations(array $relations) // constraints have been specified for the eager load and we'll just put // an empty Closure with the loader so that we can treat all the same. if (is_numeric($name)) { - $f = function () {}; + $f = function() {}; list($name, $constraints) = [$constraints, $f]; } @@ -583,8 +582,8 @@ protected function parseNested($name, $results) foreach (explode('.', $name) as $segment) { $progress[] = $segment; - if (! isset($results[$last = implode('.', $progress)])) { - $results[$last] = function () {}; + if (!isset($results[$last = implode('.', $progress)])) { + $results[$last] = function() {}; } } @@ -673,7 +672,7 @@ public function getRelation($relation) // We want to run a relationship query without any constrains so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. - $query = Relationship::noConstraints(function () use ($relation) { + $query = Relationship::noConstraints(function() use ($relation) { return $this->entityMap->$relation($this->getEntityInstance()); }); @@ -704,7 +703,7 @@ protected function nestedRelations($relation) // that start with the given top relations and adds them to our arrays. foreach ($this->eagerLoad as $name => $constraints) { if ($this->isNested($name, $relation)) { - $nested[substr($name, strlen($relation.'.'))] = $constraints; + $nested[substr($name, strlen($relation . '.'))] = $constraints; } } @@ -722,7 +721,7 @@ protected function isNested($name, $relation) { $dots = str_contains($name, '.'); - return $dots && starts_with($name, $relation.'.'); + return $dots && starts_with($name, $relation . '.'); } /** diff --git a/src/System/Wrappers/PlainObjectWrapper.php b/src/System/Wrappers/PlainObjectWrapper.php index 1c62865..ba54b17 100755 --- a/src/System/Wrappers/PlainObjectWrapper.php +++ b/src/System/Wrappers/PlainObjectWrapper.php @@ -47,8 +47,6 @@ protected function getAttributeList() /** * Extract Attributes from a Plain Php Object * - * @param mixed $entity - * @param array $attributeList * @return array $attributes */ protected function extract() @@ -74,8 +72,6 @@ protected function extract() /** * [getMappedProperties description] - * @param [type] $entity [description] - * @param array $attributeList [description] * @return [type] [description] */ protected function getMappedProperties() @@ -86,13 +82,16 @@ protected function getMappedProperties() // We need to filter out properties that could belong to the object // and which are not intended to be handled by the ORM - return array_filter($objectProperties, function ($item) use ($attributeList) { + return array_filter($objectProperties, function($item) use ($attributeList) { if (in_array($item->getName(), $attributeList)) { return true; } }); } + /** + * @param string $name + */ protected function getMappedProperty($name) { return $this->reflection->getProperty($name); @@ -189,12 +188,12 @@ public function getEntityAttribute($key) return $value; } - /** - * Test if a given attribute exists - * - * @param string $key - * @return boolean - */ + /** + * Test if a given attribute exists + * + * @param string $key + * @return boolean + */ public function hasAttribute($key) { $attributes = $this->entity->getEntityAttributes(); diff --git a/src/System/Wrappers/Wrapper.php b/src/System/Wrappers/Wrapper.php index cb03704..b7eb7ef 100755 --- a/src/System/Wrappers/Wrapper.php +++ b/src/System/Wrappers/Wrapper.php @@ -65,7 +65,7 @@ public function setProxies() $proxies = []; foreach ($this->entityMap->getRelationships() as $relation) { - if (! array_key_exists($relation, $attributes) || is_null($attributes[$relation])) { + if (!array_key_exists($relation, $attributes) || is_null($attributes[$relation])) { if (in_array($relation, $singleRelations)) { $proxies[$relation] = new EntityProxy($this->getObject(), $relation); } From 83915a3832c66c9b196836df97ee1fac78156ed2 Mon Sep 17 00:00:00 2001 From: Maxim Kolokolnikov Date: Fri, 8 Jan 2016 23:00:11 +0600 Subject: [PATCH 5/9] phpdoc fixes --- src/Analogue.php | 32 +++- src/Commands/Command.php | 5 + src/Commands/Delete.php | 4 +- src/Commands/Store.php | 6 +- src/Drivers/CapsuleConnectionProvider.php | 7 + src/Drivers/DriverInterface.php | 2 +- src/Drivers/IlluminateConnectionProvider.php | 7 + src/Drivers/IlluminateDBAdapter.php | 9 +- src/Drivers/IlluminateDriver.php | 10 +- src/Drivers/IlluminateQueryAdapter.php | 18 ++ src/Drivers/Manager.php | 11 +- src/Entity.php | 12 +- src/EntityCollection.php | 89 +++++---- src/EntityMap.php | 152 ++++++++------- src/Exceptions/EntityNotFoundException.php | 2 +- src/Mappable.php | 14 -- src/Plugins/SoftDeletes/Restore.php | 5 + src/Plugins/SoftDeletes/SoftDeletesPlugin.php | 8 +- src/Plugins/SoftDeletes/SoftDeletingScope.php | 14 +- src/Plugins/Timestamps/TimestampsPlugin.php | 9 +- src/Relationships/BelongsTo.php | 46 +++-- src/Relationships/BelongsToMany.php | 165 ++++++++++------- src/Relationships/HasMany.php | 12 +- src/Relationships/HasManyThrough.php | 61 +++--- src/Relationships/HasOne.php | 9 +- src/Relationships/HasOneOrMany.php | 74 +++++--- src/Relationships/MorphMany.php | 11 +- src/Relationships/MorphOne.php | 11 +- src/Relationships/MorphOneOrMany.php | 24 +-- src/Relationships/MorphPivot.php | 12 +- src/Relationships/MorphTo.php | 53 ++---- src/Relationships/MorphToMany.php | 35 ++-- src/Relationships/Pivot.php | 18 +- src/Relationships/Relationship.php | 79 ++++---- src/Repository.php | 27 ++- src/System/Aggregate.php | 57 +++--- src/System/CachedRelationship.php | 5 + src/System/EntityBuilder.php | 13 +- src/System/EntityCache.php | 63 ++++--- src/System/Manager.php | 42 +++-- src/System/Mapper.php | 89 +++++---- src/System/MapperFactory.php | 10 +- src/System/Proxies/CollectionProxy.php | 41 +++-- src/System/Proxies/Proxy.php | 10 +- src/System/Proxies/ProxyInterface.php | 2 +- src/System/Query.php | 174 +++++++++--------- src/System/ScopeInterface.php | 4 +- src/System/Wrappers/EntityWrapper.php | 2 +- src/System/Wrappers/PlainObjectWrapper.php | 21 +-- src/System/Wrappers/Wrapper.php | 25 +++ src/ValueMap.php | 27 +++ src/ValueObject.php | 23 +-- 52 files changed, 962 insertions(+), 699 deletions(-) diff --git a/src/Analogue.php b/src/Analogue.php index 15d87cf..5aa56b8 100755 --- a/src/Analogue.php +++ b/src/Analogue.php @@ -12,17 +12,35 @@ /** * This class is a proxy to the Manager class, which allows * using Analogue outside of the Laravel framework. + * + * @mixin Manager */ class Analogue { + /** + * @var self + */ protected static $instance; + /** + * @var Manager + */ protected static $manager; + /** + * @var Capsule + */ protected static $capsule; + /** + * @var bool + */ protected static $booted = false; + /** + * Analogue constructor. + * @param array $connection + */ public function __construct(array $connection) { if (!static::$booted) { @@ -67,12 +85,12 @@ public function boot() /** * Add a connection array to Capsule * - * @param array $config - * @param string $name + * @param array $config + * @param string $name */ public function addConnection($config, $name = 'default') { - return static::$capsule->addConnection($config, $name); + static::$capsule->addConnection($config, $name); } /** @@ -89,8 +107,8 @@ public function connection($name = null) /** * Dynamically handle static calls to the instance, Facade Style. * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters * @return mixed */ public static function __callStatic($method, $parameters) @@ -101,8 +119,8 @@ public static function __callStatic($method, $parameters) /** * Dynamically handle calls to the Analogue Manager instance. * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters * @return mixed */ public function __call($method, $parameters) diff --git a/src/Commands/Command.php b/src/Commands/Command.php index a1d28a6..de6ca89 100755 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -21,6 +21,11 @@ abstract class Command */ protected $query; + /** + * Command constructor. + * @param Aggregate $aggregate + * @param QueryAdapter $query + */ public function __construct(Aggregate $aggregate, QueryAdapter $query) { $this->aggregate = $aggregate; diff --git a/src/Commands/Delete.php b/src/Commands/Delete.php index 332171e..ec78304 100755 --- a/src/Commands/Delete.php +++ b/src/Commands/Delete.php @@ -9,7 +9,9 @@ class Delete extends Command /** * Execute the Delete Statement * - * @return void + * @throws MappingException + * @throws \InvalidArgumentException + * @return false|void */ public function execute() { diff --git a/src/Commands/Store.php b/src/Commands/Store.php index a775eee..d705958 100755 --- a/src/Commands/Store.php +++ b/src/Commands/Store.php @@ -17,7 +17,7 @@ class Store extends Command /** * Persist the entity in the database * - * @return void + * @return false|mixed */ public function execute() { @@ -223,6 +223,8 @@ protected function insert() /** * Run an update statement on the entity * + * @throws \InvalidArgumentException + * * @return void */ protected function update() @@ -234,7 +236,7 @@ protected function update() $query = $query->where($keyName, '=', $this->aggregate->getEntityId()); $dirtyAttributes = $this->aggregate->getDirtyRawAttributes(); - + if (count($dirtyAttributes) > 0) { $query->update($dirtyAttributes); } diff --git a/src/Drivers/CapsuleConnectionProvider.php b/src/Drivers/CapsuleConnectionProvider.php index 761787c..f2b58f0 100755 --- a/src/Drivers/CapsuleConnectionProvider.php +++ b/src/Drivers/CapsuleConnectionProvider.php @@ -6,8 +6,15 @@ class CapsuleConnectionProvider { + /** + * @var Capsule + */ protected $capsule; + /** + * CapsuleConnectionProvider constructor. + * @param Capsule $capsule + */ public function __construct(Capsule $capsule) { $this->capsule = $capsule; diff --git a/src/Drivers/DriverInterface.php b/src/Drivers/DriverInterface.php index f9568a5..40e22a6 100755 --- a/src/Drivers/DriverInterface.php +++ b/src/Drivers/DriverInterface.php @@ -12,7 +12,7 @@ public function getName(); /** * Get Analogue DB Adapter - * @param string $connection connection name for drivers supporting multiple connections + * @param string $connection connection name for drivers supporting multiple connections * @return \Analogue\ORM\Drivers\DBAdapter */ public function getAdapter($connection = null); diff --git a/src/Drivers/IlluminateConnectionProvider.php b/src/Drivers/IlluminateConnectionProvider.php index 3a7481c..c35efdc 100755 --- a/src/Drivers/IlluminateConnectionProvider.php +++ b/src/Drivers/IlluminateConnectionProvider.php @@ -6,8 +6,15 @@ class IlluminateConnectionProvider { + /** + * @var DatabaseManager + */ protected $db; + /** + * IlluminateConnectionProvider constructor. + * @param DatabaseManager $db + */ public function __construct(DatabaseManager $db) { $this->db = $db; diff --git a/src/Drivers/IlluminateDBAdapter.php b/src/Drivers/IlluminateDBAdapter.php index 82ba2ed..b2fee07 100755 --- a/src/Drivers/IlluminateDBAdapter.php +++ b/src/Drivers/IlluminateDBAdapter.php @@ -11,8 +11,15 @@ */ class IlluminateDBAdapter implements DBAdapter { + /** + * @var Connection + */ protected $connection; + /** + * IlluminateDBAdapter constructor. + * @param Connection $connection + */ public function __construct(Connection $connection) { $this->connection = $connection; @@ -68,6 +75,6 @@ public function commit() */ public function rollback() { - $this->connection->rollback(); + $this->connection->rollBack(); } } diff --git a/src/Drivers/IlluminateDriver.php b/src/Drivers/IlluminateDriver.php index a7a9fd0..40dd650 100755 --- a/src/Drivers/IlluminateDriver.php +++ b/src/Drivers/IlluminateDriver.php @@ -7,10 +7,14 @@ class IlluminateDriver implements DriverInterface /** * The Illuminate Connection Provider * - * @var CapsuleConnectionProvider | IlluminateConnectionProvider + * @var CapsuleConnectionProvider|IlluminateConnectionProvider */ protected $connectionProvider; + /** + * IlluminateDriver constructor. + * @param $connectionProvider + */ public function __construct($connectionProvider) { $this->connectionProvider = $connectionProvider; @@ -29,8 +33,8 @@ public function getName() /** * Get Analogue DBAdapter * - * @param string $connection - * @return \Analogue\ORM\DBAdater + * @param string|null $connection + * @return IlluminateDBAdapter */ public function getAdapter($connection = null) { diff --git a/src/Drivers/IlluminateQueryAdapter.php b/src/Drivers/IlluminateQueryAdapter.php index 680a738..2d2870d 100755 --- a/src/Drivers/IlluminateQueryAdapter.php +++ b/src/Drivers/IlluminateQueryAdapter.php @@ -4,15 +4,33 @@ use Illuminate\Database\Query\Builder; +/** + * Class IlluminateQueryAdapter + * @package Analogue\ORM\Drivers + * + * @mixin Builder + */ class IlluminateQueryAdapter implements QueryAdapter { + /** + * @var Builder + */ protected $query; + /** + * IlluminateQueryAdapter constructor. + * @param Builder $query + */ public function __construct(Builder $query) { $this->query = $query; } + /** + * @param $method + * @param $parameters + * @return mixed + */ public function __call($method, $parameters) { return call_user_func_array([$this->query, $method], $parameters); diff --git a/src/Drivers/Manager.php b/src/Drivers/Manager.php index 96ca2a1..b14d50b 100755 --- a/src/Drivers/Manager.php +++ b/src/Drivers/Manager.php @@ -4,12 +4,15 @@ class Manager { + /** + * @var DriverInterface[] + */ protected $drivers = []; /** * Add a Mapping Driver * - * @param \Analogue\ORM\Drivers\DriverInterface $driver + * @param DriverInterface $driver */ public function addDriver(DriverInterface $driver) { @@ -19,9 +22,9 @@ public function addDriver(DriverInterface $driver) /** * Get the DBAdapter * - * @param string $driver - * @param string $connection connection name for drivers suporting multiple connection. - * @return DriverInterface + * @param string $driver + * @param string $connection connection name for drivers supporting multiple connection. + * @return DriverInterface|void */ public function getAdapter($driver, $connection = null) { diff --git a/src/Entity.php b/src/Entity.php index 94f3e9f..23a7270 100755 --- a/src/Entity.php +++ b/src/Entity.php @@ -45,8 +45,8 @@ public function __get($key) /** * Dynamically set attributes on the entity. * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @return void */ public function __set($key, $value) @@ -63,7 +63,7 @@ public function __set($key, $value) /** * Is a getter method defined ? * - * @param string $key + * @param string $key * @return boolean */ protected function hasGetMutator($key) @@ -74,7 +74,7 @@ protected function hasGetMutator($key) /** * Is a setter method defined ? * - * @param string $key + * @param string $key * @return boolean */ protected function hasSetMutator($key) @@ -82,6 +82,10 @@ protected function hasSetMutator($key) return method_exists($this, 'set' . $this->getMutatorMethod($key)) ? true : false; } + /** + * @param $key + * @return string + */ protected function getMutatorMethod($key) { return ucfirst($key) . 'Attribute'; diff --git a/src/EntityCollection.php b/src/EntityCollection.php index 6c0e781..0c3a4a5 100755 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -2,6 +2,7 @@ namespace Analogue\ORM; +use Analogue\ORM\Exceptions\MappingException; use Analogue\ORM\System\Manager; use Analogue\ORM\System\Wrappers\Factory; use Illuminate\Support\Collection; @@ -16,6 +17,10 @@ class EntityCollection extends Collection */ protected $factory; + /** + * EntityCollection constructor. + * @param array|null $entities + */ public function __construct(array $entities = null) { $this->factory = new Factory; @@ -26,9 +31,8 @@ public function __construct(array $entities = null) /** * Find an entity in the collection by key. * - * @param mixed $key - * @param mixed $default - * + * @param mixed $key + * @param mixed $default * @return \Analogue\ORM\Entity */ public function find($key, $default = null) @@ -37,7 +41,7 @@ public function find($key, $default = null) $key = $this->getEntityKey($key); } - return array_first($this->items, function($itemKey, $entity) use ($key) { + return array_first($this->items, function ($itemKey, $entity) use ($key) { return $this->getEntityKey($entity) == $key; }, $default); } @@ -45,7 +49,7 @@ public function find($key, $default = null) /** * Add an entity to the collection. * - * @param Mappable $entity + * @param Mappable $entity * @return $this */ public function add($entity) @@ -57,6 +61,9 @@ public function add($entity) /** * Remove an entity from the collection + * + * @param $entity + * @return mixed */ public function remove($entity) { @@ -68,7 +75,7 @@ public function remove($entity) /** * Push an item onto the end of the collection. * - * @param mixed $value + * @param mixed $value * @return void */ public function push($value) @@ -79,8 +86,8 @@ public function push($value) /** * Put an item in the collection by key. * - * @param mixed $key - * @param mixed $value + * @param mixed $key + * @param mixed $value * @return void */ public function put($key, $value) @@ -91,8 +98,8 @@ public function put($key, $value) /** * Set the item at a given offset. * - * @param mixed $key - * @param mixed $value + * @param mixed $key + * @param mixed $value * @return void */ public function offsetSet($key, $value) @@ -107,7 +114,8 @@ public function offsetSet($key, $value) /** * Determine if a key exists in the collection. * - * @param mixed $key + * @param mixed $key + * @param mixed|null $value * @return bool */ public function contains($key, $value = null) @@ -118,8 +126,8 @@ public function contains($key, $value = null) /** * Fetch a nested element of the collection. * - * @param string $key - * @return static + * @param string $key + * @return self */ public function fetch($key) { @@ -129,6 +137,7 @@ public function fetch($key) /** * Generic function for returning class.key value pairs * + * @throws MappingException * @return string */ public function getEntityHashes() @@ -148,8 +157,9 @@ public function getEntityHashes() /** * Get a subset of the collection from entity hashes * - * @param array $hashes - * @return + * @param array $hashes + * @throws MappingException + * @return array */ public function getSubsetByHashes(array $hashes) { @@ -173,8 +183,8 @@ public function getSubsetByHashes(array $hashes) /** * Merge the collection with the given items. * - * @param array $items - * @return static + * @param array $items + * @return self */ public function merge($items) { @@ -190,8 +200,8 @@ public function merge($items) /** * Diff the collection with the given items. * - * @param \ArrayAccess|array $items - * @return static + * @param \ArrayAccess|array $items + * @return self */ public function diff($items) { @@ -211,8 +221,8 @@ public function diff($items) /** * Intersect the collection with the given items. * - * @param \ArrayAccess|array $items - * @return static + * @param \ArrayAccess|array $items + * @return self */ public function intersect($items) { @@ -232,8 +242,8 @@ public function intersect($items) /** * Returns only the models from the collection with the specified keys. * - * @param mixed $keys - * @return static + * @param mixed $keys + * @return self */ public function only($keys) { @@ -245,8 +255,8 @@ public function only($keys) /** * Returns all models in the collection except the models with specified keys. * - * @param mixed $keys - * @return static + * @param mixed $keys + * @return self */ public function except($keys) { @@ -258,7 +268,7 @@ public function except($keys) /** * Get a dictionary keyed by primary keys. * - * @param \ArrayAccess|array $items + * @param \ArrayAccess|array $items * @return array */ public function getDictionary($items = null) @@ -274,11 +284,19 @@ public function getDictionary($items = null) return $dictionary; } + /** + * @return array + */ public function getEntityKeys() { return array_keys($this->getDictionary()); } + /** + * @param $entity + * @throws MappingException + * @return mixed + */ protected function getEntityKey($entity) { $keyName = Manager::getMapper($entity)->getEntityMap()->getKeyName(); @@ -291,7 +309,7 @@ protected function getEntityKey($entity) /** * Get the max value of a given key. * - * @param string $key + * @param string|null $key * @return mixed */ public function max($key = null) @@ -307,7 +325,7 @@ public function max($key = null) /** * Get the min value of a given key. * - * @param string $key + * @param string|null $key * @return mixed */ public function min($key = null) @@ -323,9 +341,9 @@ public function min($key = null) /** * Get an array with the values of a given key. * - * @param string $value - * @param string $key - * @return static + * @param string $value + * @param string|null $key + * @return self */ public function pluck($value, $key = null) { @@ -335,9 +353,9 @@ public function pluck($value, $key = null) /** * Alias for the "pluck" method. * - * @param string $value - * @param string $key - * @return static + * @param string $value + * @param string|null $key + * @return self */ public function lists($value, $key = null) { @@ -347,7 +365,8 @@ public function lists($value, $key = null) /** * Return only unique items from the collection. * - * @return static + * @param string|null $key + * @return self */ public function unique($key = null) { diff --git a/src/EntityMap.php b/src/EntityMap.php index 88daff3..0e5600a 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -2,6 +2,7 @@ namespace Analogue\ORM; +use Analogue\ORM\Exceptions\MappingException; use Exception; use ReflectionClass; use Analogue\ORM\System\Manager; @@ -37,7 +38,7 @@ class EntityMap /** * The table associated with the entity. * - * @var string + * @var string|null */ protected $table = null; @@ -59,7 +60,7 @@ class EntityMap /** * The Custom Domain Class to use with this mapping * - * @var string + * @var string|null */ protected $class = null; @@ -145,7 +146,7 @@ class EntityMap * Sequence name, to be used with postgreSql * defaults to %table_name%_id_seq * - * @var string + * @var string|null */ protected $sequence = null; @@ -283,7 +284,7 @@ public function setAttributes(array $attributeNames) /** * Get all the attribute names for the class, including relationships, embeddables and primary key. * - * @return [type] [description] + * @return array */ public function getCompiledAttributes() { @@ -341,7 +342,7 @@ public function getDriver() /** * Set the db connection to use on the table * - * @param [type] $connection [description] + * @param $connection */ public function setConnection($connection) { @@ -409,8 +410,7 @@ public function getClass() /** * Set the custom entity class * - * @param string namespaced class name - * @param string $class + * @param string $class namespaced class name */ public function setClass($class) { @@ -505,11 +505,11 @@ public function getPivotRelationships() * by hooking the 'initializing' event, before entityMap is initialized. * * @param string $name Relation name - * @param Closure $relationship + * @param \Closure $relationship * * @return void */ - public function addRelationshipMethod($name, Closure $relationship) + public function addRelationshipMethod($name, \Closure $relationship) { $this->dynamicRelationships[$name] = $relationship; } @@ -548,6 +548,7 @@ public function getKeyName() /** * Set the primary key for the entity. * + * @param $key * @return void */ public function setKeyName($key) @@ -578,7 +579,7 @@ public function getPerPage() /** * Set the number of models to return per page. * - * @param int $perPage + * @param int $perPage * @return void */ public function setPerPage($perPage) @@ -649,10 +650,11 @@ public function getForeignKey() /** * Define a one-to-one relationship. * - * @param $entity - * @param string $relatedClass entity class - * @param string $foreignKey - * @param string $localKey + * @param $entity + * @param string $relatedClass entity class + * @param string $foreignKey + * @param string $localKey + * @throws MappingException * @return \Analogue\ORM\Relationships\HasOne */ public function hasOne($entity, $relatedClass, $foreignKey = null, $localKey = null) @@ -671,11 +673,13 @@ public function hasOne($entity, $relatedClass, $foreignKey = null, $localKey = n /** * Define a polymorphic one-to-one relationship. * - * @param string $related - * @param string $name - * @param string $type - * @param string $id - * @param string $localKey + * @param mixed $entity + * @param string $related + * @param string $name + * @param string|null $type + * @param string|null $id + * @param string|null $localKey + * @throws MappingException * @return \Analogue\ORM\Relationships\MorphOne */ public function morphOne($entity, $related, $name, $type = null, $id = null, $localKey = null) @@ -694,10 +698,12 @@ public function morphOne($entity, $related, $name, $type = null, $id = null, $lo /** * Define an inverse one-to-one or many relationship. * - * @param string $related - * @param string $foreignKey - * @param string $otherKey - * @param string $relation + * @param mixed $entity + * @param string $related + * @param string|null $foreignKey + * @param string|null $otherKey + * @param string|null $relation + * @throws MappingException * @return \Analogue\ORM\Relationships\BelongsTo */ public function belongsTo($entity, $related, $foreignKey = null, $otherKey = null, $relation = null) @@ -728,9 +734,11 @@ public function belongsTo($entity, $related, $foreignKey = null, $otherKey = nul /** * Define a polymorphic, inverse one-to-one or many relationship. * - * @param string $name - * @param string $type - * @param string $id + * @param mixed $entity + * @param string|null $name + * @param string|null $type + * @param string|null $id + * @throws MappingException * @return \Analogue\ORM\Relationships\MorphTo */ public function morphTo($entity, $name = null, $type = null, $id = null) @@ -777,9 +785,11 @@ public function morphTo($entity, $name = null, $type = null, $id = null) /** * Define a one-to-many relationship. * - * @param string $related - * @param string $foreignKey - * @param string $localKey + * @param mixed $entity + * @param string $related + * @param string|null $foreignKey + * @param string|null $localKey + * @throws MappingException * @return \Analogue\ORM\Relationships\HasMany */ public function hasMany($entity, $related, $foreignKey = null, $localKey = null) @@ -798,10 +808,12 @@ public function hasMany($entity, $related, $foreignKey = null, $localKey = null) /** * Define a has-many-through relationship. * - * @param string $related - * @param string $through - * @param string|null $firstKey - * @param string|null $secondKey + * @param mixed $entity + * @param string $related + * @param string $through + * @param string|null $firstKey + * @param string|null $secondKey + * @throws MappingException * @return \Analogue\ORM\Relationships\HasManyThrough */ public function hasManyThrough($entity, $related, $through, $firstKey = null, $secondKey = null) @@ -823,11 +835,12 @@ public function hasManyThrough($entity, $related, $through, $firstKey = null, $s /** * Define a polymorphic one-to-many relationship. * - * @param string $related - * @param string $name - * @param string $type - * @param string $id - * @param string $localKey + * @param mixed $entity + * @param string $related + * @param string $name + * @param string|null $type + * @param string|null $id + * @param string|null $localKey * @return \Analogue\ORM\Relationships\MorphMany */ public function morphMany($entity, $related, $name, $type = null, $id = null, $localKey = null) @@ -849,11 +862,13 @@ public function morphMany($entity, $related, $name, $type = null, $id = null, $l /** * Define a many-to-many relationship. * - * @param string $related - * @param string $table - * @param string $foreignKey - * @param string $otherKey - * @param string $relation + * @param mixed $entity + * @param string $related + * @param string|null $table + * @param string|null $foreignKey + * @param string|null $otherKey + * @param string|null $relation + * @throws MappingException * @return \Analogue\ORM\Relationships\BelongsToMany */ public function belongsToMany($entity, $related, $table = null, $foreignKey = null, $otherKey = null, $relation = null) @@ -889,12 +904,14 @@ public function belongsToMany($entity, $related, $table = null, $foreignKey = nu /** * Define a polymorphic many-to-many relationship. * - * @param string $related - * @param string $name - * @param string $table - * @param string $foreignKey - * @param string $otherKey - * @param bool $inverse + * @param mixed $entity + * @param string $related + * @param string $name + * @param string|null $table + * @param string|null $foreignKey + * @param string|null $otherKey + * @param bool $inverse + * @throws MappingException * @return \Analogue\ORM\Relationships\MorphToMany */ public function morphToMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false) @@ -921,11 +938,13 @@ public function morphToMany($entity, $related, $name, $table = null, $foreignKey /** * Define a polymorphic, inverse many-to-many relationship. * - * @param string $related - * @param string $name - * @param string $table - * @param string $foreignKey - * @param string $otherKey + * @param mixed $entity + * @param string $related + * @param string $name + * @param string|null $table + * @param string|null $foreignKey + * @param string|null $otherKey + * @throws MappingException * @return \Analogue\ORM\Relationships\MorphToMany */ public function morphedByMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null) @@ -943,13 +962,13 @@ public function morphedByMany($entity, $related, $name, $table = null, $foreignK /** * Get the relationship name of the belongs to many. * - * @return string + * @return string */ protected function getBelongsToManyCaller() { $self = __FUNCTION__; - $caller = array_first(debug_backtrace(false), function($key, $trace) use ($self) { + $caller = array_first(debug_backtrace(false), function ($key, $trace) use ($self) { $caller = $trace['function']; return (!in_array($caller, EntityMap::$manyMethods) && $caller != $self); @@ -961,7 +980,7 @@ protected function getBelongsToManyCaller() /** * Get the joining table name for a many-to-many relation. * - * @param EntityMap $relatedMap + * @param EntityMap $relatedMap * @return string */ public function joiningTable($relatedMap) @@ -986,9 +1005,9 @@ public function joiningTable($relatedMap) /** * Get the polymorphic relationship columns. * - * @param string $name - * @param string $type - * @param string $id + * @param string $name + * @param string $type + * @param string $id * @return string[] */ protected function getMorphs($name, $type, $id) @@ -1013,7 +1032,7 @@ public function getMorphClass() /** * Create a new Entity Collection instance. * - * @param array $entities + * @param array $entities * @return \Analogue\ORM\EntityCollection */ public function newCollection(array $entities = []) @@ -1071,8 +1090,8 @@ protected function getCustomMethods() /** * Parse user's class methods for relationships * - * @param array $customMethods - * @return + * @param array $customMethods + * @return array */ protected function parseMethodsForRelationship(array $customMethods) { @@ -1142,7 +1161,7 @@ protected function sortRelationshipsByType() /** * Override this method for custom entity instantiation * - * @return mixed + * @return null */ public function activator() { @@ -1152,8 +1171,9 @@ public function activator() /** * Call dynamic relationship, if it exists * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters + * @throws Exception * @return mixed */ public function __call($method, $parameters) diff --git a/src/Exceptions/EntityNotFoundException.php b/src/Exceptions/EntityNotFoundException.php index a2a72f9..21dc367 100755 --- a/src/Exceptions/EntityNotFoundException.php +++ b/src/Exceptions/EntityNotFoundException.php @@ -33,7 +33,7 @@ public function setEntity($entity) * * @return string */ - public function getEnity() + public function getEntity() { return $this->entity; } diff --git a/src/Mappable.php b/src/Mappable.php index b8a1741..f5e5310 100755 --- a/src/Mappable.php +++ b/src/Mappable.php @@ -17,18 +17,4 @@ public function setEntityAttributes(array $attributes); * @return array */ public function getEntityAttributes(); - - /** - * Set the raw entity attributes - * @param string $key - * @param string $value - */ - //public function setEntityAttribute($key, $value); - - /** - * Return the entity's attribute - * @param string $key - * @return mixed - */ - //public function getEntityAttribute($key); } diff --git a/src/Plugins/SoftDeletes/Restore.php b/src/Plugins/SoftDeletes/Restore.php index 574af88..f274f02 100755 --- a/src/Plugins/SoftDeletes/Restore.php +++ b/src/Plugins/SoftDeletes/Restore.php @@ -6,6 +6,11 @@ class Restore extends Command { + /** + * @throws \InvalidArgumentException + * + * @return false|mixed + */ public function execute() { $aggregate = $this->aggregate; diff --git a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php index cefeaf6..c6ef36e 100755 --- a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php +++ b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php @@ -23,7 +23,7 @@ public function register() $host = $this; // Hook any mapper init and check the mapping include soft deletes. - $this->manager->registerGlobalEvent('initialized', function($mapper) use ($host) { + $this->manager->registerGlobalEvent('initialized', function (Mapper $mapper) use ($host) { $entityMap = $mapper->getEntityMap(); if ($entityMap->usesSoftDeletes()) { @@ -37,8 +37,8 @@ public function register() * By hooking to the mapper initialization event, we can extend it * with the softDelete capacity. * - * @param \Analogue\ORM\System\Mapper $mapper - * @return void + * @param \Analogue\ORM\System\Mapper $mapper + * @return bool|void */ protected function registerSoftDelete(Mapper $mapper) { @@ -50,7 +50,7 @@ protected function registerSoftDelete(Mapper $mapper) $host = $this; // Register 'deleting' events - $mapper->registerEvent('deleting', function($entity) use ($entityMap, $host) { + $mapper->registerEvent('deleting', function ($entity) use ($entityMap, $host) { // Convert Entity into an EntityWrapper $factory = new Factory; diff --git a/src/Plugins/SoftDeletes/SoftDeletingScope.php b/src/Plugins/SoftDeletes/SoftDeletingScope.php index 62118d0..e20a753 100755 --- a/src/Plugins/SoftDeletes/SoftDeletingScope.php +++ b/src/Plugins/SoftDeletes/SoftDeletingScope.php @@ -17,7 +17,7 @@ class SoftDeletingScope implements ScopeInterface /** * Apply the scope to a given Analogue query builder. * - * @param \Analogue\ORM\System\Query $query + * @param \Analogue\ORM\System\Query $query * @return void */ public function apply(Query $query) @@ -32,7 +32,7 @@ public function apply(Query $query) /** * Remove the scope from the given Analogue query builder. * - * @param \Analogue\ORM\System\Query $query + * @param \Analogue\ORM\System\Query $query * @return void */ public function remove(Query $query) @@ -56,7 +56,7 @@ public function remove(Query $query) /** * Extend the query builder with the needed functions. * - * @param \Analogue\ORM\System\Query $query + * @param \Analogue\ORM\System\Query $query * @return void */ public function extend(Query $query) @@ -69,7 +69,7 @@ public function extend(Query $query) /** * Add the with-trashed extension to the builder. * - * @param \Analogue\ORM\System\Query $query + * @param \Analogue\ORM\System\Query $query * @return void */ protected function addWithTrashed(Query $query) @@ -84,7 +84,7 @@ protected function addWithTrashed(Query $query) /** * Add the only-trashed extension to the builder. * - * @param \Analogue\ORM\System\Query $query + * @param \Analogue\ORM\System\Query $query * @return void */ protected function addOnlyTrashed(Query $query) @@ -101,8 +101,8 @@ protected function addOnlyTrashed(Query $query) /** * Determine if the given where clause is a soft delete constraint. * - * @param array $where - * @param string $column + * @param array $where + * @param string $column * @return bool */ protected function isSoftDeleteConstraint(array $where, $column) diff --git a/src/Plugins/Timestamps/TimestampsPlugin.php b/src/Plugins/Timestamps/TimestampsPlugin.php index bcd18e9..17edfd3 100755 --- a/src/Plugins/Timestamps/TimestampsPlugin.php +++ b/src/Plugins/Timestamps/TimestampsPlugin.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\Plugins\Timestamps; +use Analogue\ORM\System\Mapper; use Carbon\Carbon; use Analogue\ORM\Plugins\AnaloguePlugin; use Analogue\ORM\System\Wrappers\Factory; @@ -18,12 +19,12 @@ class TimestampsPlugin extends AnaloguePlugin */ public function register() { - $this->manager->registerGlobalEvent('initialized', function($mapper) { + $this->manager->registerGlobalEvent('initialized', function (Mapper $mapper) { $entityMap = $mapper->getEntityMap(); if ($entityMap->usesTimestamps()) { - $mapper->registerEvent('creating', function($entity) use ($entityMap) { - + $mapper->registerEvent('creating', function ($entity) use ($entityMap) { + $factory = new Factory; $wrappedEntity = $factory->make($entity); @@ -37,7 +38,7 @@ public function register() }); - $mapper->registerEvent('updating', function($entity) use ($entityMap) { + $mapper->registerEvent('updating', function ($entity) use ($entityMap) { $factory = new Factory; $wrappedEntity = $factory->make($entity); diff --git a/src/Relationships/BelongsTo.php b/src/Relationships/BelongsTo.php index b304272..e95b925 100755 --- a/src/Relationships/BelongsTo.php +++ b/src/Relationships/BelongsTo.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\Relationships; +use Analogue\ORM\Mappable; use Analogue\ORM\System\Query; use Analogue\ORM\System\Mapper; use Analogue\ORM\EntityCollection; @@ -40,11 +41,11 @@ class BelongsTo extends Relationship /** * Create a new belongs to relationship instance. * - * @param \Analogue\ORM\System\Mapper $mapper - * @param Mappable $parent - * @param string $foreignKey - * @param string $otherKey - * @param string $relation + * @param Mapper $mapper + * @param Mappable $parent + * @param string $foreignKey + * @param string $otherKey + * @param string $relation */ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $relation) { @@ -55,19 +56,28 @@ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $re parent::__construct($mapper, $parent); } + /** + * @param $related + */ public function attachTo($related) { - return $this->associate($related); + $this->associate($related); } + /** + * @param $related + * @return Mappable + */ public function detachFrom($related) { - return $this->dissociate($related); + return $this->dissociate($related);//todo } /** * Get the results of the relationship. * + * @param $relation + * * @return mixed */ public function getResults($relation) @@ -99,9 +109,9 @@ public function addConstraints() /** * Add the constraints for a relationship count query. * - * @param \Analogue\ORM\System\Query $query - * @param \Analogue\ORM\System\Query $parent - * @return \Analogue\ORM\System\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { @@ -115,7 +125,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -131,7 +141,7 @@ public function addEagerConstraints(array $entities) /** * Gather the keys from an array of related models. * - * @param array $entities + * @param array $entities * @return array */ protected function getEagerModelKeys(array $entities) @@ -162,8 +172,8 @@ protected function getEagerModelKeys(array $entities) /** * Initialize the relation on a set of models. * - * @param array $entities - * @param string $relation + * @param array $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -179,9 +189,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) @@ -260,7 +270,7 @@ public function getForeignKey() /** * Get the foreign key value pair for a related object * - * @var mixed $related + * @param mixed $related * * @return array */ diff --git a/src/Relationships/BelongsToMany.php b/src/Relationships/BelongsToMany.php index 2e2eeef..f5208b4 100755 --- a/src/Relationships/BelongsToMany.php +++ b/src/Relationships/BelongsToMany.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\Relationships; +use Analogue\ORM\Mappable; use Analogue\ORM\System\Query; use Analogue\ORM\System\Mapper; use Analogue\ORM\EntityCollection; @@ -60,12 +61,12 @@ class BelongsToMany extends Relationship /** * Create a new has many relationship instance. * - * @param Mapper $mapper - * @param Mappable $parent - * @param string $table - * @param string $foreignKey - * @param string $otherKey - * @param string $relationName + * @param Mapper $mapper + * @param Mappable $parent + * @param string $table + * @param string $foreignKey + * @param string $otherKey + * @param string $relationName */ public function __construct(Mapper $mapper, $parent, $table, $foreignKey, $otherKey, $relationName = null) { @@ -77,11 +78,16 @@ public function __construct(Mapper $mapper, $parent, $table, $foreignKey, $other parent::__construct($mapper, $parent); } - + /** + * @param $related + */ public function attachTo($related) { } + /** + * @param $related + */ public function detachFrom($related) { $ids = $this->getIdsFromHashes([$related]); @@ -89,6 +95,9 @@ public function detachFrom($related) $this->detach($ids); } + /** + * @param $related + */ public function detachMany($related) { $ids = $this->getIdsFromHashes($related); @@ -96,6 +105,10 @@ public function detachMany($related) $this->detach($ids); } + /** + * @param array $hashes + * @return array + */ protected function getIdsFromHashes(array $hashes) { $ids = []; @@ -110,6 +123,8 @@ protected function getIdsFromHashes(array $hashes) /** * Get the results of the relationship. * + * @param $relation + * * @return EntityCollection */ public function getResults($relation) @@ -124,11 +139,11 @@ public function getResults($relation) /** * Set a where clause for a pivot table column. * - * @param string $column - * @param string $operator - * @param mixed $value - * @param string $boolean - * @return \Analogue\ORM\Relationships\BelongsToMany + * @param string $column + * @param string $operator + * @param mixed $value + * @param string $boolean + * @return self */ public function wherePivot($column, $operator = null, $value = null, $boolean = 'and') { @@ -138,10 +153,10 @@ public function wherePivot($column, $operator = null, $value = null, $boolean = /** * Set an or where clause for a pivot table column. * - * @param string $column - * @param string $operator - * @param mixed $value - * @return \Analogue\ORM\Relationships\BelongsToMany + * @param string $column + * @param string $operator + * @param mixed $value + * @return self */ public function orWherePivot($column, $operator = null, $value = null) { @@ -161,7 +176,7 @@ public function getPivotAttributes() /** * Execute the query and get the first result. * - * @param array $columns + * @param array $columns * @return mixed */ public function first($columns = ['*']) @@ -174,10 +189,11 @@ public function first($columns = ['*']) /** * Execute the query and get the first result or throw an exception. * - * @param array $columns - * @return Mappable|static + * @param array $columns * - * @throws Mappable|EntityNotFoundException + * @throws EntityNotFoundException + * + * @return Mappable|self */ public function firstOrFail($columns = ['*']) { @@ -191,7 +207,7 @@ public function firstOrFail($columns = ['*']) /** * Execute the query as a "select" statement. * - * @param array $columns + * @param array $columns * @return \Analogue\ORM\EntityCollection */ public function get($columns = ['*']) @@ -220,7 +236,7 @@ public function get($columns = ['*']) /** * Hydrate the pivot table relationship on the models. * - * @param array $entities + * @param array $entities * @return void */ protected function hydratePivotRelation(array $entities) @@ -284,8 +300,8 @@ public function addConstraints() /** * Add the constraints for a relationship count query. * - * @param Query $query - * @param Query $parent + * @param Query $query + * @param Query $parent * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) @@ -302,8 +318,8 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Add the constraints for a relationship count query on the same table. * - * @param Query $query - * @param Query $parent + * @param Query $query + * @param Query $parent * @return Query */ public function getRelationCountQueryForSelfJoin(Query $query, Query $parent) @@ -332,7 +348,7 @@ public function getRelationCountHash() /** * Set the select clause for the relation query. * - * @param array $columns + * @param array $columns * @return \Analogue\ORM\Relationships\BelongsToMany */ protected function getSelectColumns(array $columns = ['*']) @@ -369,7 +385,6 @@ protected function getAliasedPivotColumns() * Set the join clause for the relation query. * * @param \Analogue\ORM\Query|null - * @param Query $query * @return $this */ protected function setJoin($query = null) @@ -407,7 +422,7 @@ protected function setWhere() /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -418,8 +433,8 @@ public function addEagerConstraints(array $entities) /** * Initialize the relation on a set of eneities. * - * @param array $entities - * @param string $relation + * @param array $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -436,9 +451,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) @@ -470,7 +485,7 @@ public function match(array $entities, EntityCollection $results, $relation) /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Analogue\ORM\EntityCollection $results + * @param EntityCollection $results * @return array */ protected function buildDictionary(EntityCollection $results) @@ -506,7 +521,7 @@ public function getRelatedIds() /** * Update Pivot * - * @param $entity + * @param \Analogue\ORM\Entity $entity * @return void */ public function updatePivot($entity) @@ -535,7 +550,7 @@ public function updatePivots($relatedEntities) /** * Create Pivot Records * - * @param $relatedEntities + * @param \Analogue\ORM\Entity[] $relatedEntities * @return void */ public function createPivots($relatedEntities) @@ -547,7 +562,6 @@ public function createPivots($relatedEntities) foreach ($relatedEntities as $entity) { $keys[] = $entity->getEntityAttribute($keyName); - //$attributes = $entity->getPivotEntity()->getEntityAttributes(); } $records = $this->createAttachRecords($keys, $attributes); @@ -558,8 +572,8 @@ public function createPivots($relatedEntities) /** * Update an existing pivot record on the table. * - * @param mixed $id - * @param array $attributes + * @param mixed $id + * @param array $attributes * @return integer */ public function updateExistingPivot($id, array $attributes) @@ -574,8 +588,8 @@ public function updateExistingPivot($id, array $attributes) /** * Attach a model to the parent. * - * @param mixed $id - * @param array $attributes + * @param mixed $id + * @param array $attributes * @return void */ public function attach($id, array $attributes = []) @@ -586,10 +600,9 @@ public function attach($id, array $attributes = []) } /** - * Synchronize Relationship + * @param array $entities * - * @param mixed $entities - * @return [type] [description] + * @throws \InvalidArgumentException */ public function sync(array $entities) { @@ -600,6 +613,9 @@ public function sync(array $entities) * Detach related entities that are not in $id * * @param array $entities + * + * @throws \InvalidArgumentException + * * @return void */ protected function detachExcept(array $entities = []) @@ -624,8 +640,8 @@ protected function detachExcept(array $entities = []) /** * Create an array of records to insert into the pivot table. * - * @param array $ids - * @param array $attributes + * @param array $ids + * @param array $attributes * @return array */ protected function createAttachRecords($ids, array $attributes) @@ -647,10 +663,10 @@ protected function createAttachRecords($ids, array $attributes) /** * Create a full attachment record payload. * - * @param int $key - * @param mixed $value - * @param array $attributes - * @param bool $timed + * @param int $key + * @param mixed $value + * @param array $attributes + * @param bool $timed * @return array */ protected function attacher($key, $value, $attributes, $timed) @@ -668,9 +684,9 @@ protected function attacher($key, $value, $attributes, $timed) /** * Get the attach record ID and extra attributes. * - * @param integer $key - * @param mixed $value - * @param array $attributes + * @param int $key + * @param mixed $value + * @param array $attributes * @return array */ protected function getAttachId($key, $value, array $attributes) @@ -685,8 +701,8 @@ protected function getAttachId($key, $value, array $attributes) /** * Create a new pivot attachment record. * - * @param int $id - * @param bool $timed + * @param int $id + * @param bool $timed * @return array */ protected function createAttachRecord($id, $timed) @@ -712,8 +728,8 @@ protected function createAttachRecord($id, $timed) /** * Set the creation and update timestamps on an attach record. * - * @param array $record - * @param bool $exists + * @param array $record + * @param bool $exists * @return array */ protected function setTimestampsOnAttach(array $record, $exists = false) @@ -729,17 +745,23 @@ protected function setTimestampsOnAttach(array $record, $exists = false) return $record; } + /** + * @param EntityCollection $entities + * @return array + */ protected function getModelKeysFromCollection(EntityCollection $entities) { $keyName = $this->relatedMap->getKeyName(); - return array_map(function($m) use ($keyName) { return $m->$keyName; }, $entities); + return array_map(function ($m) use ($keyName) { + return $m->$keyName; + }, $entities); } /** * Detach models from the relationship. * - * @param int|array $ids + * @param int|array $ids * @return int */ public function detach($ids = []) @@ -762,14 +784,14 @@ public function detach($ids = []) // Once we have all of the conditions set on the statement, we are ready // to run the delete on the pivot table. Then, if the touch parameter // is true, we will go ahead and touch all related models to sync. - $results = $query->delete(); - - return $results; + return $query->delete(); } /** * Create a new query builder for the pivot table. * + * @throws \InvalidArgumentException + * * @return \Illuminate\Database\Query\Builder */ protected function newPivotQuery() @@ -794,7 +816,10 @@ public function newPivotStatement() /** * Get a new pivot statement for a given "other" ID. * - * @param mixed $id + * @param mixed $id + * + * @throws \InvalidArgumentException + * * @return \Illuminate\Database\Query\Builder */ public function newPivotStatementForId($id) @@ -811,8 +836,8 @@ public function newPivotStatementForId($id) /** * Create a new pivot model instance. * - * @param array $attributes - * @param bool $exists + * @param array $attributes + * @param bool $exists * @return \Analogue\ORM\Relationships\Pivot */ public function newPivot(array $attributes = [], $exists = false) @@ -825,7 +850,7 @@ public function newPivot(array $attributes = [], $exists = false) /** * Create a new existing pivot model instance. * - * @param array $attributes + * @param array $attributes * @return \Analogue\ORM\Relationships\Pivot */ public function newExistingPivot(array $attributes = []) @@ -836,7 +861,7 @@ public function newExistingPivot(array $attributes = []) /** * Set the columns on the pivot table to retrieve. * - * @param array $columns + * @param array $columns * @return $this */ public function withPivot($columns) @@ -851,8 +876,8 @@ public function withPivot($columns) /** * Specify that the pivot table has creation and update timestamps. * - * @param mixed $createdAt - * @param mixed $updatedAt + * @param mixed $createdAt + * @param mixed $updatedAt * @return \Analogue\ORM\Relationships\BelongsToMany */ public function withTimestamps($createdAt = null, $updatedAt = null) diff --git a/src/Relationships/HasMany.php b/src/Relationships/HasMany.php index d934e20..59500c4 100755 --- a/src/Relationships/HasMany.php +++ b/src/Relationships/HasMany.php @@ -9,6 +9,8 @@ class HasMany extends HasOneOrMany /** * Get the results of the relationship. * + * @param $relation + * * @return mixed */ public function getResults($relation) @@ -23,8 +25,8 @@ public function getResults($relation) /** * Initialize the relation on a set of entities. * - * @param array $entities - * @param string $relation + * @param array $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -41,9 +43,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) diff --git a/src/Relationships/HasManyThrough.php b/src/Relationships/HasManyThrough.php index 582ed15..20e85b0 100755 --- a/src/Relationships/HasManyThrough.php +++ b/src/Relationships/HasManyThrough.php @@ -40,10 +40,11 @@ class HasManyThrough extends Relationship /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\EntityMap $parentMap - * @param string $firstKey - * @param string $secondKey - * @return void + * @param Mapper $mapper + * @param \Analogue\ORM\Mappable $farParent + * @param \Analogue\ORM\EntityMap $parentMap + * @param string $firstKey + * @param string $secondKey */ public function __construct(Mapper $mapper, $farParent, $parentMap, $firstKey, $secondKey) { @@ -58,11 +59,17 @@ public function __construct(Mapper $mapper, $farParent, $parentMap, $firstKey, $ parent::__construct($mapper, $parentInstance); } + /** + * @param $related + */ public function attachTo($related) { // N/A } + /** + * @param $related + */ public function detachFrom($related) { // N/A @@ -82,16 +89,19 @@ public function addConstraints() if (static::$constraints) { $farParentKeyName = $this->farParentMap->getKeyName(); - $this->query->where($parentTable . '.' . $this->firstKey, - '=', $this->farParent->getEntityAttribute($farParentKeyName)); + $this->query->where( + $parentTable . '.' . $this->firstKey, + '=', + $this->farParent->getEntityAttribute($farParentKeyName) + ); } } /** * Add the constraints for a relationship count query. * - * @param Query $query - * @param Query $parent + * @param Query $query + * @param Query $parent * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) @@ -110,7 +120,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Set the join clause on the query. * - * @param null|Query $query + * @param null|Query $query * @return void */ protected function setJoin(Query $query = null) @@ -125,7 +135,7 @@ protected function setJoin(Query $query = null) /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -138,8 +148,8 @@ public function addEagerConstraints(array $entities) /** * Initialize the relation on a set of entities. * - * @param array $entities - * @param string $relation + * @param \Analogue\ORM\Entity[] $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -154,9 +164,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param \Analogue\ORM\Entity[] $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) @@ -185,10 +195,10 @@ public function match(array $entities, EntityCollection $results, $relation) return $entities; } - /* + /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Analogue\ORM\EntityCollection $results + * @param EntityCollection $results * @return array */ protected function buildDictionary(EntityCollection $results) @@ -210,6 +220,7 @@ protected function buildDictionary(EntityCollection $results) /** * Get the results of the relationship. * + * @param $relation * @return mixed */ public function getResults($relation) @@ -224,8 +235,8 @@ public function getResults($relation) /** * Execute the query as a "select" statement. * - * @param array $columns - * @return \Analogue\ORM\EntityCollection + * @param array $columns + * @return EntityCollection */ public function get($columns = ['*']) { @@ -249,8 +260,8 @@ public function get($columns = ['*']) /** * Set the select clause for the relation query. * - * @param array $columns - * @return \Analogue\ORM\Relationships\BelongsToMany + * @param array $columns + * @return BelongsToMany */ protected function getSelectColumns(array $columns = ['*']) { @@ -264,17 +275,15 @@ protected function getSelectColumns(array $columns = ['*']) /** * Get a paginator for the "select" statement. * - * @param int $perPage - * @param array $columns + * @param int $perPage + * @param array $columns * @return \Illuminate\Pagination\Paginator */ public function paginate($perPage = null, $columns = ['*']) { $this->query->addSelect($this->getSelectColumns($columns)); - $pager = $this->query->paginate($perPage, $columns); - - return $pager; + return $this->query->paginate($perPage, $columns); } /** diff --git a/src/Relationships/HasOne.php b/src/Relationships/HasOne.php index aafa6ec..6043d7b 100755 --- a/src/Relationships/HasOne.php +++ b/src/Relationships/HasOne.php @@ -9,6 +9,7 @@ class HasOne extends HasOneOrMany /** * Get the results of the relationship. * + * @param $relation * @return mixed */ public function getResults($relation) @@ -34,7 +35,8 @@ public function fetch() /** * Initialize the relation on a set of entities. * - * @param string $relation + * @param \Analogue\ORM\Entity[] $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -49,8 +51,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param EntityCollection $results - * @param string $relation + * @param \Analogue\ORM\Entity[] $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) diff --git a/src/Relationships/HasOneOrMany.php b/src/Relationships/HasOneOrMany.php index dc8143f..e0038a5 100755 --- a/src/Relationships/HasOneOrMany.php +++ b/src/Relationships/HasOneOrMany.php @@ -24,9 +24,10 @@ abstract class HasOneOrMany extends Relationship /** * Create a new has many relationship instance. * - * @param string $foreignKey - * @param string $localKey - * @return void + * @param Mapper $mapper + * @param \Analogue\ORM\Mappable $parentEntity + * @param string $foreignKey + * @param string $localKey */ public function __construct(Mapper $mapper, $parentEntity, $foreignKey, $localKey) { @@ -36,22 +37,33 @@ public function __construct(Mapper $mapper, $parentEntity, $foreignKey, $localKe parent::__construct($mapper, $parentEntity); } + /** + * @param \Analogue\ORM\Entity|EntityCollection $entity + */ public function attachTo($entity) { if ($entity instanceof EntityCollection) { - return $this->attachMany($entity); + $this->attachMany($entity); } - return $this->attachOne($entity); + $this->attachOne($entity); } + /** + * @param $entityHash + * @return void + */ public function detachFrom($entityHash) { if (is_array($entityHash)) { - return $this->detachMany($entityHash); + $this->detachMany($entityHash); + return; } - return $this->detachMany([$entityHash]); + $this->detachMany([$entityHash]); } + /** + * @param \Analogue\ORM\Entity $entity + */ public function attachOne($entity) { $wrapper = $this->factory->make($entity); @@ -63,6 +75,9 @@ public function attachOne($entity) $wrapper->setEntityAttribute($this->getPlainForeignKey(), $this->getParentKey()); } + /** + * @param EntityCollection $entities + */ public function attachMany(EntityCollection $entities) { foreach ($entities as $entity) { @@ -70,6 +85,9 @@ public function attachMany(EntityCollection $entities) } } + /** + * @param $entityHash + */ protected function detachOne($entityHash) { $this->detachMany([$entityHash]); @@ -77,7 +95,7 @@ protected function detachOne($entityHash) /** * Attach ids that are passed as arguments, and detach any other - * @param mixed $entities + * @param mixed $entities * @return void */ public function sync(array $entities) @@ -85,6 +103,9 @@ public function sync(array $entities) $this->detachExcept($entities); } + /** + * @param $entities + */ protected function detachExcept($entities) { $query = $this->query->getQuery()->from($this->relatedMap->getTable()); @@ -100,6 +121,9 @@ protected function detachExcept($entities) ->update([$this->getPlainForeignKey() => null]); } + /** + * @param array $entityHashes + */ public function detachMany(array $entityHashes) { $keys = []; @@ -130,7 +154,7 @@ public function addConstraints() /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -141,9 +165,9 @@ public function addEagerConstraints(array $entities) /** * Match the eagerly loaded results to their single parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function matchOne(array $entities, EntityCollection $results, $relation) @@ -154,9 +178,9 @@ public function matchOne(array $entities, EntityCollection $results, $relation) /** * Match the eagerly loaded results to their many parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function matchMany(array $entities, EntityCollection $results, $relation) @@ -167,10 +191,10 @@ public function matchMany(array $entities, EntityCollection $results, $relation) /** * Match the eagerly loaded results to their many parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation - * @param string $type + * @param array $entities + * @param EntityCollection $results + * @param string $relation + * @param string $type * @return array */ protected function matchOneOrMany(array $entities, EntityCollection $results, $relation, $type) @@ -179,10 +203,6 @@ protected function matchOneOrMany(array $entities, EntityCollection $results, $r $cache = $this->parentMapper->getEntityCache(); - // As our cache will hold polymorphic relations, we'll key - // them by entity.key as a standard. - $foreignKey = $this->relatedMap->getKeyName(); - // Once we have the dictionary we can simply spin through the parent models to // link them up with their children using the keyed dictionary to make the // matching very convenient and easy work. Then we'll just return them. @@ -206,9 +226,9 @@ protected function matchOneOrMany(array $entities, EntityCollection $results, $r /** * Get the value of a relationship by one or many type. * - * @param array $dictionary - * @param string $key - * @param string $type + * @param array $dictionary + * @param string $key + * @param string $type * @return mixed */ protected function getRelationValue(array $dictionary, $key, $type) @@ -221,7 +241,7 @@ protected function getRelationValue(array $dictionary, $key, $type) /** * Build model dictionary keyed by the relation's foreign key. * - * @param \Analogue\ORM\EntityCollection $results + * @param EntityCollection $results * @return array */ protected function buildDictionary(EntityCollection $results) diff --git a/src/Relationships/MorphMany.php b/src/Relationships/MorphMany.php index fcda869..41aea63 100755 --- a/src/Relationships/MorphMany.php +++ b/src/Relationships/MorphMany.php @@ -9,6 +9,7 @@ class MorphMany extends MorphOneOrMany /** * Get the results of the relationship. * + * @param $relation * @return mixed */ public function getResults($relation) @@ -23,8 +24,8 @@ public function getResults($relation) /** * Initialize the relation on a set of models. * - * @param array $entities - * @param string $relation + * @param array $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -41,9 +42,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) diff --git a/src/Relationships/MorphOne.php b/src/Relationships/MorphOne.php index 7c32dca..f16ad54 100755 --- a/src/Relationships/MorphOne.php +++ b/src/Relationships/MorphOne.php @@ -9,6 +9,7 @@ class MorphOne extends MorphOneOrMany /** * Get the results of the relationship. * + * @param $relation * @return mixed */ public function getResults($relation) @@ -23,8 +24,8 @@ public function getResults($relation) /** * Initialize the relation on a set of models. * - * @param array $entities - * @param string $relation + * @param array $entities + * @param string $relation * @return array */ public function initRelation(array $entities, $relation) @@ -41,9 +42,9 @@ public function initRelation(array $entities, $relation) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\Collection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) diff --git a/src/Relationships/MorphOneOrMany.php b/src/Relationships/MorphOneOrMany.php index 15a372a..fff114b 100755 --- a/src/Relationships/MorphOneOrMany.php +++ b/src/Relationships/MorphOneOrMany.php @@ -24,11 +24,11 @@ abstract class MorphOneOrMany extends HasOneOrMany /** * Create a new has many relationship instance. * - * @param Mappable $parent - * @param string $type - * @param string $id - * @param string $localKey - * @return void + * @param Mapper $mapper + * @param \Analogue\ORM\Mappable $parent + * @param string $type + * @param string $id + * @param string $localKey */ public function __construct(Mapper $mapper, $parent, $type, $id, $localKey) { @@ -38,12 +38,6 @@ public function __construct(Mapper $mapper, $parent, $type, $id, $localKey) parent::__construct($mapper, $parent, $id, $localKey); } - /*public function attachOne($entity) - { - $entity->setEntityAttribute($this->getPlainMorphType(), get_class($this->parent)); - $entity->setEntityAttribute($this->getPlainForeignKey(), $this->getParentKey()); - }*/ - /** * Set the base constraints on the relation query. * @@ -61,9 +55,9 @@ public function addConstraints() /** * Get the relationship count query. * - * @param \Analogue\ORM\System\Query $query - * @param \Analogue\ORM\System\Query $parent - * @return \Analogue\ORM\System\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { @@ -75,7 +69,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) diff --git a/src/Relationships/MorphPivot.php b/src/Relationships/MorphPivot.php index e7ef88d..c0a5eb5 100755 --- a/src/Relationships/MorphPivot.php +++ b/src/Relationships/MorphPivot.php @@ -27,8 +27,8 @@ class MorphPivot extends Pivot /** * Set the keys for a save update query. * - * @param Query $query - * @return \Analogue\ORM\Query + * @param Query $query + * @return Query */ protected function setKeysForSaveQuery(Query $query) { @@ -40,8 +40,8 @@ protected function setKeysForSaveQuery(Query $query) /** * Set the morph type for the pivot. * - * @param string $morphType - * @return $this + * @param string $morphType + * @return self */ public function setMorphType($morphType) { @@ -53,8 +53,8 @@ public function setMorphType($morphType) /** * Set the morph class for the pivot. * - * @param string $morphClass - * @return \Analogue\ORM\Relationships\MorphPivot + * @param string $morphClass + * @return self */ public function setMorphClass($morphClass) { diff --git a/src/Relationships/MorphTo.php b/src/Relationships/MorphTo.php index fb241d5..96a1949 100755 --- a/src/Relationships/MorphTo.php +++ b/src/Relationships/MorphTo.php @@ -18,7 +18,7 @@ class MorphTo extends BelongsTo /** * The entities whose relations are being eager loaded. * - * @var \Analogue\ORM\EntityCollection + * @var EntityCollection */ protected $entities; @@ -46,13 +46,12 @@ class MorphTo extends BelongsTo /** * Create a new belongs to relationship instance. * - * @param \Analogue\ORM\System\Query $query - * @param Mappable $parent - * @param string $foreignKey - * @param string $otherKey - * @param string $type - * @param string $relation - * @return void + * @param Mapper $mapper + * @param \Analogue\ORM\Mappable $parent + * @param string $foreignKey + * @param string $otherKey + * @param string $type + * @param string $relation */ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $type, $relation) { @@ -64,7 +63,7 @@ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $ty /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -75,7 +74,7 @@ public function addEagerConstraints(array $entities) /** * Build a dictionary with the entities * - * @param \Analogue\ORM\EntityCollection $entities + * @param EntityCollection $entities * @return void */ protected function buildDictionary(EntityCollection $entities) @@ -90,9 +89,9 @@ protected function buildDictionary(EntityCollection $entities) /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ public function match(array $entities, EntityCollection $results, $relation) @@ -117,8 +116,8 @@ public function getEager() /** * Match the results for a given type to their parents. * - * @param string $type - * @param \Analogue\ORM\EntityCollection $results + * @param string $type + * @param EntityCollection $results * @return void */ protected function matchToMorphParents($type, EntityCollection $results) @@ -135,50 +134,36 @@ protected function matchToMorphParents($type, EntityCollection $results) /** * Get all of the relation results for a type. * - * @param string $type - * @return \Analogue\ORM\EntityCollection + * @param string $type + * @return EntityCollection */ protected function getResultsByType($type) { $mapper = $this->relatedMapper->getManager()->mapper($type); - $map = $mapper->getEntityMap(); - - $key = $map->getKeyName(); + $key = $mapper->getEntityMap()->getKeyName(); $query = $mapper->getQuery(); - //$query = $this->useWithTrashed($query); - return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get(); } /** * Gather all of the foreign keys for a given type. * - * @param string $type + * @param string $type * @return array */ protected function gatherKeysByType($type) { $foreign = $this->foreignKey; - return BaseCollection::make($this->dictionary[$type])->map(function($entities) use ($foreign) { + return BaseCollection::make($this->dictionary[$type])->map(function ($entities) use ($foreign) { return head($entities)->{$foreign}; })->unique(); } - /** - * Get the foreign key of the relationship. - * - * @return string - */ - /*public function getForeignKey() - { - return $this->foreignKey; - }*/ - /** * Associate the model instance to the given parent. * diff --git a/src/Relationships/MorphToMany.php b/src/Relationships/MorphToMany.php index 74f60b6..74e88a0 100755 --- a/src/Relationships/MorphToMany.php +++ b/src/Relationships/MorphToMany.php @@ -35,14 +35,14 @@ class MorphToMany extends BelongsToMany /** * Create a new has many relationship instance. * - * @param \Analogue\ORM\Entityl $parent - * @param string $name - * @param string $table - * @param string $foreignKey - * @param string $otherKey - * @param string $relationName - * @param bool $inverse - * @return void + * @param Mapper $mapper + * @param \Analogue\ORM\Entity $parent + * @param string $name + * @param string $table + * @param string $foreignKey + * @param string $otherKey + * @param string|null $relationName + * @param bool $inverse */ public function __construct(Mapper $mapper, $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false) { @@ -58,7 +58,7 @@ public function __construct(Mapper $mapper, $parent, $name, $table, $foreignKey, /** * Set the where clause for the relation query. * - * @return $this + * @return self */ protected function setWhere() { @@ -72,8 +72,8 @@ protected function setWhere() /** * Add the constraints for a relationship count query. * - * @param Query $query - * @param Query $parent + * @param Query $query + * @param Query $parent * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) @@ -86,7 +86,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Set the constraints for an eager load of the relation. * - * @param array $entities + * @param array $entities * @return void */ public function addEagerConstraints(array $entities) @@ -99,8 +99,8 @@ public function addEagerConstraints(array $entities) /** * Create a new pivot attachment record. * - * @param int $id - * @param bool $timed + * @param int $id + * @param bool $timed * @return array */ protected function createAttachRecord($id, $timed) @@ -113,6 +113,7 @@ protected function createAttachRecord($id, $timed) /** * Create a new query builder for the pivot table. * + * @throws \InvalidArgumentException * @return \Illuminate\Database\Query\Builder */ protected function newPivotQuery() @@ -125,9 +126,9 @@ protected function newPivotQuery() /** * Create a new pivot model instance. * - * @param array $attributes - * @param bool $exists - * @return \Analogue\ORM\Relationships\Pivot + * @param array $attributes + * @param bool $exists + * @return Pivot */ public function newPivot(array $attributes = [], $exists = false) { diff --git a/src/Relationships/Pivot.php b/src/Relationships/Pivot.php index 82c4c23..8b1007d 100755 --- a/src/Relationships/Pivot.php +++ b/src/Relationships/Pivot.php @@ -6,6 +6,9 @@ class Pivot extends Entity { + /** + * @var bool + */ protected $exists; /** @@ -68,12 +71,11 @@ class Pivot extends Entity /** * Create a new pivot model instance. * - * @param \Analogue\ORM\System\InternallyMappable $parent - * @param array $attributes - * @param string $table - * @param bool $exists - * @param \Analogue\ORM\EntityMap $parentMap - * @return void + * @param \Analogue\ORM\System\InternallyMappable $parent + * @param \Analogue\ORM\EntityMap $parentMap + * @param array $attributes + * @param string $table + * @param bool $exists */ public function __construct($parent, $parentMap, $attributes, $table, $exists = false) { @@ -119,8 +121,8 @@ public function getOtherKey() /** * Set the key names for the pivot model instance. * - * @param string $foreignKey - * @param string $otherKey + * @param string $foreignKey + * @param string $otherKey * @return $this */ public function setPivotKeys($foreignKey, $otherKey) diff --git a/src/Relationships/Relationship.php b/src/Relationships/Relationship.php index ec01daa..d51a7fc 100755 --- a/src/Relationships/Relationship.php +++ b/src/Relationships/Relationship.php @@ -12,26 +12,31 @@ use Analogue\ORM\System\Wrappers\Factory; use Illuminate\Database\Query\Expression; +/** + * Class Relationship + * + * @mixin Query + */ abstract class Relationship { /** * The mapper instance for the related entity * - * @var \Analogue\ORM\System\Mapper + * @var Mapper */ protected $relatedMapper; /** * The Analogue Query Builder instance. * - * @var \Analogue\ORM\Query + * @var Query */ protected $query; /** * The parent entity proxy instance. * - * @var \Analogue\ORM\System\InternallyMappable + * @var InternallyMappable */ protected $parent; @@ -44,7 +49,7 @@ abstract class Relationship /** * The Parent Mapper instance * - * @var \Analogue\ORM\System\Mapper + * @var Mapper */ protected $parentMapper; @@ -92,9 +97,8 @@ abstract class Relationship /** * Create a new relation instance. * - * @param \Analogue\ORM\System\Mapper $mapper - * @param Mappable $parent - * @return void + * @param Mapper $mapper + * @param Mappable $parent */ public function __construct(Mapper $mapper, $parent) { @@ -118,14 +122,14 @@ public function __construct(Mapper $mapper, $parent) } /** - * @param [type] $related [description] - * @return [type] [description] + * @param $related + * @return mixed */ abstract public function attachTo($related); /** - * @param [type] $related [description] - * @return [type] [description] + * @param $related + * @return mixed */ abstract public function detachFrom($related); @@ -159,7 +163,7 @@ abstract public function addConstraints(); /** * Set the constraints for an eager load of the relation. * - * @param array $models + * @param array $models * @return void */ abstract public function addEagerConstraints(array $models); @@ -167,8 +171,8 @@ abstract public function addEagerConstraints(array $models); /** * Initialize the relation on a set of models. * - * @param array $models - * @param string $relation + * @param array $models + * @param string $relation * @return array */ abstract public function initRelation(array $models, $relation); @@ -176,9 +180,9 @@ abstract public function initRelation(array $models, $relation); /** * Match the eagerly loaded results to their parents. * - * @param array $entities - * @param \Analogue\ORM\EntityCollection $results - * @param string $relation + * @param array $entities + * @param EntityCollection $results + * @param string $relation * @return array */ abstract public function match(array $entities, EntityCollection $results, $relation); @@ -186,7 +190,7 @@ abstract public function match(array $entities, EntityCollection $results, $rela /** * Get the results of the relationship. * - * @param string $relation relation name in parent's entity map + * @param string $relation relation name in parent's entity map * @return mixed */ abstract public function getResults($relation); @@ -194,7 +198,7 @@ abstract public function getResults($relation); /** * Get the relationship for eager loading. * - * @return \Analogue\ORM\EntityCollection + * @return EntityCollection */ public function getEager() { @@ -204,9 +208,9 @@ public function getEager() /** * Add the constraints for a relationship count query. * - * @param \Analogue\ORM\System\Query $query - * @param \Analogue\ORM\System\Query $parent - * @return \Analogue\ORM\System\Query + * @param Query $query + * @param Query $parent + * @return Query */ public function getRelationCountQuery(Query $query, Query $parent) { @@ -220,7 +224,7 @@ public function getRelationCountQuery(Query $query, Query $parent) /** * Run a callback with constraints disabled on the relation. * - * @param \Closure $callback + * @param Closure $callback * @return mixed */ public static function noConstraints(Closure $callback) @@ -240,8 +244,8 @@ public static function noConstraints(Closure $callback) /** * Get all of the primary keys for an array of entities. * - * @param array $entities - * @param string $key + * @param array $entities + * @param string $key * @return array */ protected function getKeys(array $entities, $key = null) @@ -252,7 +256,7 @@ protected function getKeys(array $entities, $key = null) $host = $this; - return array_unique(array_values(array_map(function($value) use ($key, $host) { + return array_unique(array_values(array_map(function ($value) use ($key, $host) { if (!$value instanceof InternallyMappable) { $value = $host->factory->make($value); } @@ -265,7 +269,7 @@ protected function getKeys(array $entities, $key = null) /** * Get the underlying query for the relation. * - * @return \Analogue\ORM\System\Query + * @return Query */ public function getQuery() { @@ -315,7 +319,7 @@ public function getRelated() /** * Get the related mapper for the relation * - * @return \Analogue\ORM\System\Mapper + * @return Mapper */ public function getRelatedMapper() { @@ -356,7 +360,7 @@ public function relatedUpdatedAt() /** * Wrap the given value with the parent query's grammar. * - * @param string $value + * @param string $value * @return string */ public function wrap($value) @@ -367,7 +371,7 @@ public function wrap($value) /** * Get a fresh timestamp * - * @return \Carbon\Carbon + * @return Carbon */ protected function freshTimestamp() { @@ -378,9 +382,8 @@ protected function freshTimestamp() * Cache the link between parent and related * into the mapper's Entity Cache. * - * @param EntityCollection|Mappable $results result of the relation query - * @param string $relation Name of the relation method on the parent entity - * + * @param EntityCollection|Mappable $results result of the relation query + * @param string $relation name of the relation method on the parent entity * @return void */ protected function cacheRelation($results, $relation) @@ -412,16 +415,14 @@ protected function getEntityHash(Mappable $entity) $keyName = Mapper::getMapper($class)->getEntityMap()->getKeyName(); - $hash = $class . '.' . $entity->getEntityAttribute($keyName); - - return $hash; + return $class . '.' . $entity->getEntityAttribute($keyName); } /** * Run synchronization content if needed by the * relation type. * - * @param array $actualContent + * @param array $actualContent * @return void */ public function sync(array $actualContent) @@ -432,8 +433,8 @@ public function sync(array $actualContent) /** * Handle dynamic method calls to the relationship. * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters * @return mixed */ public function __call($method, $parameters) diff --git a/src/Repository.php b/src/Repository.php index 9e2c863..ca1b70e 100755 --- a/src/Repository.php +++ b/src/Repository.php @@ -2,11 +2,17 @@ namespace Analogue\ORM; +use Analogue\ORM\Exceptions\MappingException; use Exception; use InvalidArgumentException; use Analogue\ORM\System\Mapper; use Analogue\ORM\System\Manager; +/** + * Class Repository + * + * @mixin Mapper + */ class Repository { /** @@ -23,10 +29,10 @@ class Repository * - Mappable object instance * - Instance of mapper * - * @param Mapper $mapper - * @param EntityMap $entityMap (optional) - * + * @param Mapper $mapper + * @param EntityMap|null $entityMap (optional) * @throws \InvalidArgumentException + * @throws MappingException */ public function __construct($mapper, EntityMap $entityMap = null) { @@ -84,8 +90,8 @@ public function allMatching(array $attributes) /** * Return a paginator instance on the EntityCollection * - * @param int $perPage number of item per page (fallback on default setup in entity map) - * @return + * @param int|null $perPage number of item per page (fallback on default setup in entity map) + * @return \Illuminate\Pagination\LengthAwarePaginator */ public function paginate($perPage = null) { @@ -95,7 +101,7 @@ public function paginate($perPage = null) /** * Delete an entity or an entity collection from the database * - * @param Mappable|Collection $entity + * @param Mappable|EntityCollection $entity * @return \Illuminate\Support\Collection|null */ public function delete($entity) @@ -106,8 +112,8 @@ public function delete($entity) /** * Persist an entity or an entity collection in the database. * - * @param Mappable|Collection|array $entity - * @return Mappable|Collection|array + * @param Mappable|EntityCollection|array $entity + * @return Mappable|EntityCollection|array */ public function store($entity) { @@ -117,8 +123,9 @@ public function store($entity) /** * Make custom mapper custom commands available in repository * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters + * @throws Exception * @return mixed */ public function __call($method, $parameters) diff --git a/src/System/Aggregate.php b/src/System/Aggregate.php index 529c398..78569d0 100755 --- a/src/System/Aggregate.php +++ b/src/System/Aggregate.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\System; +use Analogue\ORM\Relationships\Pivot; use Illuminate\Support\Collection; use Analogue\ORM\System\Wrappers\Factory; use Analogue\ORM\System\Proxies\EntityProxy; @@ -74,10 +75,10 @@ class Aggregate implements InternallyMappable /** * Create a new Aggregated Entity instance * - * @param mixed $entity [description] - * @param Aggregate|null $parent [description] - * @param string $parentRelationship [description] - * @param Aggregate|null $root [description] + * @param mixed $entity + * @param Aggregate|null $parent + * @param string $parentRelationship + * @param Aggregate|null $root */ public function __construct($entity, Aggregate $parent = null, $parentRelationship = null, Aggregate $root = null) { @@ -117,7 +118,8 @@ protected function parseRelationships() /** * Parse for values common to single & many relations * - * @param string $relation + * @param string $relation + * @throws MappingException * @return mixed|boolean */ protected function parseForCommonValues($relation) @@ -151,6 +153,7 @@ protected function parseForCommonValues($relation) * Parse a 'single' relationship * * @param string $relation + * @throws MappingException * @return boolean */ protected function parseSingleRelationship($relation) @@ -194,7 +197,7 @@ protected function parseSingleRelationship($relation) * Check if value isn't parent or root in the aggregate * * @param mixed - * @return boolean|null + * @return true|void */ protected function isParentOrRoot($value) { @@ -217,6 +220,7 @@ protected function isParentOrRoot($value) * Parse a 'many' relationship * * @param string $relation + * @throws MappingException * @return boolean */ protected function parseManyRelationship($relation) @@ -255,8 +259,8 @@ protected function parseManyRelationship($relation) * Return Entity's relationship attribute * * @param string $relation + * @throws MappingException * @return mixed - * @throws \Analogue\ORM\Exceptions\MappingException */ protected function getRelationshipValue($relation) { @@ -274,7 +278,7 @@ protected function getRelationshipValue($relation) * * @param mixed $entities * @param string $relation - * @return + * @return array */ protected function createSubAggregates($entities, $relation) { @@ -291,7 +295,7 @@ protected function createSubAggregates($entities, $relation) * Create a related subAggregate * * @param mixed $entity - * @return \Analogue\ORM\System\RootAggregate; + * @return self */ protected function createSubAggregate($entity, $relation) { @@ -302,9 +306,7 @@ protected function createSubAggregate($entity, $relation) $root = $this->root; } - $aggregate = new Aggregate($entity, $this, $relation, $root); - - return $aggregate; + return new self($entity, $this, $relation, $root); } /** @@ -350,7 +352,7 @@ public function getEntityHash() /** * Get wrapped entity class * - * @return + * @return string */ public function getEntityClass() { @@ -395,7 +397,7 @@ public function getPivotAttributes() /** * Get Non existing related entities from several relationships * - * @param array $relationships + * @param array $relationships * @return array */ public function getNonExistingRelated(array $relationships) @@ -432,8 +434,6 @@ protected function getNonExistingFromRelation($relation) /** * Synchronize relationships if needed - * - * @return */ public function syncRelationships() { @@ -447,7 +447,7 @@ public function syncRelationships() /** * Synchronize a relationship attribute * - * @return void + * @param $relation */ protected function synchronize($relation) { @@ -668,7 +668,8 @@ protected function getForeignKeyAttributesFromParent() $parentRelation = $this->parentRelationship; if (in_array($parentRelation, $parentForeignRelations) - && !in_array($parentRelation, $parentPivotRelations)) { + && !in_array($parentRelation, $parentPivotRelations) + ) { $parentObject = $this->parent->getEntityObject(); // Call Relationship's method on parent map @@ -721,8 +722,6 @@ protected function updatePivotRelation($relation) } if (count($new) > 0) { - $relatedCollection = $this->getEntityAttribute($relation); - $pivots = $this->getRelatedAggregatesFromHashes($new, $relation); $this->entityMap->$relation($this->getEntityObject())->createPivots($pivots); @@ -767,8 +766,8 @@ protected function updatePivotIfDirty($pivotHash, $relation) /** * Compare two attributes array and return dirty attributes * - * @param array $actual - * @param array $cached + * @param array $actual + * @param array $cached * @return array */ protected function getDirtyAttributes(array $actual, array $cached) @@ -830,7 +829,7 @@ protected function getRelatedAggregatesFromHashes(array $hashes, $relation) * * @param string $hash * @param string $relation - * @return \Analogue\ORM\System\Aggregate | null + * @return \Analogue\ORM\System\Aggregate|null */ protected function getRelatedAggregateFromHash($hash, $relation) { @@ -850,7 +849,7 @@ protected function getRelatedAggregateFromHash($hash, $relation) */ protected function getEntityHashesFromRelation($relation) { - return array_map(function($aggregate) { + return array_map(function ($aggregate) { return $aggregate->getEntityHash(); }, $this->relationships[$relation]); } @@ -906,6 +905,10 @@ public function getDirtyRawAttributes() return $dirty; } + /** + * @param $key + * @return bool + */ protected function isRelation($key) { return in_array($key, $this->entityMap->getRelationships()); @@ -914,6 +917,8 @@ protected function isRelation($key) /** * Determine if the new and old values for a given key are numerically equivalent. * + * @param $current + * @param $original * @return boolean */ protected function originalIsNumericallyEquivalent($current, $original) @@ -1005,11 +1010,9 @@ public function hasAttribute($key) /** * Set the lazyloading proxies on the wrapped entity - * - * @return void */ public function setProxies() { - return $this->wrappedEntity->setProxies(); + $this->wrappedEntity->setProxies(); } } diff --git a/src/System/CachedRelationship.php b/src/System/CachedRelationship.php index 3b17a99..548f932 100755 --- a/src/System/CachedRelationship.php +++ b/src/System/CachedRelationship.php @@ -22,6 +22,11 @@ class CachedRelationship */ protected $pivotAttributes; + /** + * CachedRelationship constructor. + * @param $hash + * @param array $pivotAttributes + */ public function __construct($hash, $pivotAttributes = []) { $this->hash = $hash; diff --git a/src/System/EntityBuilder.php b/src/System/EntityBuilder.php index 585c391..2ba4ed6 100755 --- a/src/System/EntityBuilder.php +++ b/src/System/EntityBuilder.php @@ -11,7 +11,6 @@ */ class EntityBuilder { - /** * The mapper for the entity to build * @var \Analogue\ORM\System\Mapper @@ -45,6 +44,11 @@ class EntityBuilder */ protected $factory; + /** + * EntityBuilder constructor. + * @param Mapper $mapper + * @param array $eagerLoads + */ public function __construct(Mapper $mapper, array $eagerLoads) { $this->mapper = $mapper; @@ -63,8 +67,7 @@ public function __construct(Mapper $mapper, array $eagerLoads) /** * Convert a result set into an array of entities * - * @param array $results - * + * @param array $results * @return array */ public function build(array $results) @@ -132,7 +135,7 @@ protected function hydrateValueObjects(& $attributes) /** * Hydrate a single value object * - * @param array $attributes + * @param array $attributes * @param string $localKey * @param string $valueClass * @return void @@ -143,8 +146,6 @@ protected function hydrateValueObject(& $attributes, $localKey, $valueClass) $embeddedAttributes = $map->getAttributes(); - //$nestedValueObjects = $map->getEmbeddables(); - $valueObject = $this->mapper->getManager()->getValueObjectInstance($valueClass); foreach ($embeddedAttributes as $key) { diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index 37627ce..c01b9e5 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -43,6 +43,10 @@ class EntityCache */ protected $pivotAttributes = []; + /** + * EntityCache constructor. + * @param EntityMap $entityMap + */ public function __construct(EntityMap $entityMap) { $this->entityMap = $entityMap; @@ -101,25 +105,17 @@ public function has($id) protected function mergeCacheResults($entities) { foreach ($entities as $key => $entity) { - if (array_key_exists($key, $this->cache)) { - /* - $existingValue = $this->cache[$key]; - - $this->cache[$key] = $entity + $existingValue;*/ - - $this->cache[$key] = $entity; - } else { - $this->cache[$key] = $entity; - } + $this->cache[$key] = $entity; } } /** * Cache Relation's query result for an entity * - * @param mixed $parent - * @param string $relation name of the relation - * @param mixed $results results of the relationship's query + * @param mixed $parent + * @param string $relation name of the relation + * @param mixed $results results of the relationship's query + * @param Relationship $relationship * * @return void */ @@ -147,11 +143,11 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation /** * Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any. * - * @param [type] $parentKey [description] - * @param [type] $relation [description] - * @param [type] $result [description] - * @param Relationship $relationship [description] - * @return [type] [description] + * @param $parentKey + * @param $relation + * @param $result + * @param Relationship $relationship + * @return CachedRelationship */ protected function getCachedRelationship($parentKey, $relation, $result, Relationship $relationship) { @@ -186,11 +182,10 @@ protected function getCachedRelationship($parentKey, $relation, $result, Relatio /** * Cache a many relationship * - * @param [type] $parentKey [description] - * @param string $relation [description] - * @param EntityCollection $results [description] - * @param Relationship $relationship [description] - * @return [type] [description] + * @param $parentKey + * @param string $relation + * @param EntityCollection $results + * @param Relationship $relationship */ protected function cacheManyRelationResults($parentKey, $relation, $results, Relationship $relationship) { @@ -208,11 +203,10 @@ protected function cacheManyRelationResults($parentKey, $relation, $results, Rel /** * Cache a single relationship * - * @param [type] $parentKey [description] - * @param string $relation [description] - * @param Mappable $result [description] - * @param Relationship $relationship [description] - * @return [type] [description] + * @param $parentKey + * @param string $relation + * @param Mappable $result + * @param Relationship $relationship */ protected function cacheSingleRelationResult($parentKey, $relation, $result, Relationship $relationship) { @@ -238,9 +232,7 @@ protected function getEntityHash(InternallyMappable $entity) /** * Refresh the cache record for an aggregated entity after a write operation - * - * @param InternallyMappable $entity [description] - * @return [type] [description] + * @param Aggregate $entity */ public function refresh(Aggregate $entity) { @@ -250,6 +242,8 @@ public function refresh(Aggregate $entity) /** * Transform an Aggregated Entity into a cache record * + * @param Aggregate $aggregatedEntity + * @throws MappingException * @return array */ protected function transform(Aggregate $aggregatedEntity) @@ -295,7 +289,12 @@ protected function transform(Aggregate $aggregatedEntity) return $baseAttributes + $relationAttributes; } - + + /** + * @param $relation + * @param InternallyMappable $entity + * @return array + */ protected function getPivotValues($relation, InternallyMappable $entity) { $values = []; diff --git a/src/System/Manager.php b/src/System/Manager.php index 88571c4..14f900f 100755 --- a/src/System/Manager.php +++ b/src/System/Manager.php @@ -11,7 +11,7 @@ use Analogue\ORM\Drivers\Manager as DriverManager; /** - * This class keeps track of instanciated mappers, and entity <-> entityMap associations + * This class keeps track of instantiated mappers, and entity <-> entityMap associations */ class Manager { @@ -108,8 +108,9 @@ public function getDriverManager() /** * Create a mapper for a given entity * - * @param \Analogue\ORM\Mappable|string $entity - * @param mixed $entityMap + * @param \Analogue\ORM\Mappable|string $entity + * @param mixed $entityMap + * @throws MappingException * @return Mapper */ public function mapper($entity, $entityMap = null) @@ -134,7 +135,7 @@ public function mapper($entity, $entityMap = null) * Build a new Mapper instance for a given Entity * * @param string $entity - * @param $entityMap + * @param $entityMap * @return Mapper */ protected function buildMapper($entity, $entityMap) @@ -154,7 +155,7 @@ protected function buildMapper($entity, $entityMap) $this->mappers[$entity] = $mapper; // At this point we can safely call the boot() method on the entityMap as - // the mapper is now instanciated & registered within the manager. + // the mapper is now instantiated & registered within the manager. $mapper->getEntityMap()->boot(); @@ -164,8 +165,9 @@ protected function buildMapper($entity, $entityMap) /** * Create a mapper for a given entity (static alias) * - * @param \Analogue\ORM\Mappable|string $entity - * @param null|EntityMap $entityMap + * @param \Analogue\ORM\Mappable|string $entity + * @param null|EntityMap $entityMap + * @throws MappingException * @return Mapper */ public static function getMapper($entity, $entityMap = null) @@ -177,6 +179,8 @@ public static function getMapper($entity, $entityMap = null) * Get the Repository instance for the given Entity * * @param \Analogue\ORM\Mappable|string $entity + * @throws \InvalidArgumentException + * @throws MappingException * @return \Analogue\ORM\Repository */ public function repository($entity) @@ -198,8 +202,9 @@ public function repository($entity) /** * Register an entity * - * @param string|Mappable $entity entity's class name - * @param string|EntityMap $entityMap map's class name + * @param string|\Analogue\ORM\Mappable $entity entity's class name + * @param string|EntityMap $entityMap map's class name + * @throws MappingException * @return void */ public function register($entity, $entityMap = null) @@ -240,7 +245,7 @@ public function register($entity, $entityMap = null) * Get the entity map instance for a custom entity * * @param string $entity - * @return Mappable + * @return \Analogue\ORM\Mappable */ protected function getEntityMapInstanceFor($entity) { @@ -248,7 +253,7 @@ protected function getEntityMapInstanceFor($entity) $map = $entity . 'Map'; $map = new $map; } else { - // Generate an EntityMap obeject + // Generate an EntityMap object $map = $this->getNewEntityMap(); } @@ -270,6 +275,7 @@ protected function getNewEntityMap() * * @param string $valueObject * @param string $valueMap + * @throws MappingException * @return void */ public function registerValueObject($valueObject, $valueMap = null) @@ -292,7 +298,7 @@ public function registerValueObject($valueObject, $valueMap = null) /** * Return true is the object is registered as value object * - * @param mixed $object + * @param mixed $object * @return boolean */ public function isValueObject($object) @@ -308,6 +314,7 @@ public function isValueObject($object) * Get the Value Map for a given Value Object Class * * @param string $valueObject + * @throws MappingException * @return \Analogue\ORM\ValueMap */ public function getValueMap($valueObject) @@ -327,10 +334,10 @@ public function getValueMap($valueObject) } /** - * Instanciate a new Value Object instance + * Instantiate a new Value Object instance * * @param string $valueObject - * @return ValueObject + * @return \Analogue\ORM\ValueObject */ public function getValueObjectInstance($valueObject) { @@ -356,7 +363,7 @@ public function registerPlugin($plugin) /** * Check if the entity is already registered * - * @param string|object $entity + * @param string|object $entity * @return boolean */ public function isRegisteredEntity($entity) @@ -374,6 +381,7 @@ public function isRegisteredEntity($entity) * * @param string $event * @param \Closure $callback + * @throws \Exception * @return void */ public function registerGlobalEvent($event, $callback) @@ -388,6 +396,7 @@ public function registerGlobalEvent($event, $callback) * Shortcut to Mapper store * * @param mixed $entity + * @throws MappingException * @return mixed */ public function store($entity) @@ -399,6 +408,7 @@ public function store($entity) * Shortcut to Mapper delete * * @param mixed $entity + * @throws MappingException * @return \Illuminate\Support\Collection|null */ public function delete($entity) @@ -410,6 +420,7 @@ public function delete($entity) * Shortcut to Mapper query * * @param mixed $entity + * @throws MappingException * @return Query */ public function query($entity) @@ -421,6 +432,7 @@ public function query($entity) * Shortcut to Mapper Global Query * * @param mixed $entity + * @throws MappingException * @return Query */ public function globalQuery($entity) diff --git a/src/System/Mapper.php b/src/System/Mapper.php index 4bcd6a4..280204e 100755 --- a/src/System/Mapper.php +++ b/src/System/Mapper.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\System; +use Analogue\ORM\System\Wrappers\Wrapper; use InvalidArgumentException; use Analogue\ORM\Mappable; use Analogue\ORM\EntityMap; @@ -12,10 +13,12 @@ use Analogue\ORM\Drivers\DBAdapter; use Analogue\ORM\Exceptions\MappingException; -/* +/** * The mapper provide all the interactions with the database layer * and holds the states for the loaded entity. One instance is * created by used entity class during the application lifecycle. + * + * @mixin \Analogue\ORM\System\Query */ class Mapper { @@ -27,7 +30,7 @@ class Mapper protected $manager; /** - * Instance of EntityMapper Obect + * Instance of EntityMapper Object * * @var \Analogue\ORM\EntityMap */ @@ -70,10 +73,10 @@ class Mapper protected $customCommands = []; /** - * @param EntityMap $entityMap - * @param DBAdapter $adapter - * @param Dispatcher $dispatcher - * @param Manager $manager + * @param EntityMap $entityMap + * @param DBAdapter $adapter + * @param Dispatcher $dispatcher + * @param Manager $manager */ public function __construct(EntityMap $entityMap, DBAdapter $adapter, Dispatcher $dispatcher, Manager $manager) { @@ -106,19 +109,20 @@ public function store($entity) /** * Return true if an object is an array or collection * - * @param mixed $argument + * @param mixed $argument * @return boolean */ protected function isArrayOrCollection($argument) { - return ($argument instanceof Collection || is_array($argument)) ? true : false; + return $argument instanceof Collection || is_array($argument); } /** * Store a single entity into the database * * @param Mappable $entity - * @return Entity + * @throws \InvalidArgumentException + * @return \Analogue\ORM\Entity */ protected function storeEntity($entity) { @@ -132,20 +136,19 @@ protected function storeEntity($entity) /** * Convert an entity into an aggregate root * - * @param mixed $entity + * @param mixed $entity * @return \Analogue\ORM\System\Aggregate */ protected function aggregate($entity) { - $aggregate = new Aggregate($entity); - - return $aggregate; + return new Aggregate($entity); } /** * Store an entity collection inside a single DB Transaction * - * @param Collection|array $entities [description] + * @param Collection|array $entities + * @throws \InvalidArgumentException * @return Collection */ protected function storeCollection($entities) @@ -165,14 +168,14 @@ protected function storeCollection($entities) * Delete an entity or an entity collection from the database * * @param mixed|Collection - * @return Collection|null + * @return Collection|void */ public function delete($entity) { if ($this->isArrayOrCollection($entity)) { return $this->deleteCollection($entity); } else { - return $this->deleteEntity($entity); + $this->deleteEntity($entity); } } @@ -180,6 +183,8 @@ public function delete($entity) * Delete a single entity from the database. * * @param Mappable $entity + * @throws \InvalidArgumentException + * @throws MappingException * @return void */ protected function deleteEntity($entity) @@ -195,6 +200,8 @@ protected function deleteEntity($entity) * Delete an Entity Collection inside a single db transaction * * @param Collection|array $entities + * @throws \InvalidArgumentException + * @throws MappingException * @return Collection */ protected function deleteCollection($entities) @@ -233,15 +240,16 @@ public function getEntityCache() /** * Fire the given event for the entity * - * @param string $event - * @param \Analogue\ORM\Entity $entity - * @param bool $halt + * @param string $event + * @param \Analogue\ORM\Entity $entity + * @param bool $halt + * @throws InvalidArgumentException * @return mixed */ public function fireEvent($event, $entity, $halt = true) { if ($entity instanceof Wrapper) { - throw new InvalidArgumentException("Fired Event with invalid Entity Object"); + throw new InvalidArgumentException('Fired Event with invalid Entity Object'); } $event = "analogue.{$event}." . $this->entityMap->getClass(); @@ -254,8 +262,8 @@ public function fireEvent($event, $entity, $halt = true) /** * Register an entity event with the dispatcher. * - * @param string $event - * @param \Closure $callback + * @param string $event + * @param \Closure $callback * @return void */ public function registerEvent($event, $callback) @@ -279,7 +287,7 @@ public function addGlobalScope(ScopeInterface $scope) /** * Determine if the mapper has a global scope. * - * @param \Analogue\ORM\System\ScopeInterface $scope + * @param \Analogue\ORM\System\ScopeInterface $scope * @return bool */ public function hasGlobalScope($scope) @@ -290,8 +298,8 @@ public function hasGlobalScope($scope) /** * Get a global scope registered with the modal. * - * @param \Analogue\ORM\System\ScopeInterface $scope - * @return \Analogue\ORM\System\ScopeInterface |null + * @param \Analogue\ORM\System\ScopeInterface $scope + * @return \Analogue\ORM\System\ScopeInterface|null */ public function getGlobalScope($scope) { @@ -343,7 +351,7 @@ public function removeGlobalScopes($query) /** * Get a new query instance without a given scope. * - * @param \Analogue\ORM\System\ScopeInterface $scope + * @param \Analogue\ORM\System\ScopeInterface $scope * @return \Analogue\ORM\System\Query */ public function newQueryWithoutScope($scope) @@ -378,9 +386,10 @@ public function addCustomCommand($command) /** * Execute a custom command on an Entity * - * @param string $command + * @param string $command * @param mixed|Collection|array $entity - * @return void + * @throws \InvalidArgumentException + * @return mixed */ public function executeCustomCommand($command, $entity) { @@ -400,6 +409,7 @@ public function executeCustomCommand($command, $entity) * * @param string $commandClass * @param mixed $entity + * @throws \InvalidArgumentException * @return mixed */ protected function executeSingleCustomCommand($commandClass, $entity) @@ -414,10 +424,9 @@ protected function executeSingleCustomCommand($commandClass, $entity) /** * Check that the entity correspond to the current mapper. * - * @param mixed $entity - * @return void - * + * @param mixed $entity * @throws InvalidArgumentException + * @return void */ protected function checkEntityType($entity) { @@ -429,7 +438,7 @@ protected function checkEntityType($entity) } /** - * Get all the custom commands regitered on this mapper + * Get all the custom commands registered on this mapper * * @return array */ @@ -440,7 +449,7 @@ public function getCustomCommands() /** * Check if this mapper supports this command - * @param string $command + * @param string $command * @return boolean */ public function hasCustomCommand($command) @@ -451,7 +460,7 @@ public function hasCustomCommand($command) /** * Create a new instance of the mapped entity class * - * @param array $attributes + * @param array $attributes * @return mixed */ public function newInstance($attributes = []) @@ -477,6 +486,7 @@ public function newInstance($attributes = []) * can instantiate without calling the constructor. * * @param string|null $className + * @throws MappingException * @return mixed */ protected function customClassInstance($className) @@ -490,7 +500,7 @@ protected function customClassInstance($className) } /** - * Get the Analogue Query Builer for this instance + * Get the Analogue Query Builder for this instance * * @return \Analogue\ORM\System\Query */ @@ -502,7 +512,7 @@ public function getQuery() } /** - * Get the Analogue Query Builer for this instance + * Get the Analogue Query Builder for this instance * * @return \Analogue\ORM\System\Query */ @@ -512,7 +522,7 @@ public function query() } /** - * Get an unscoped Analogue Query Builer for this instance + * Get an unscoped Analogue Query Builder for this instance * * @return \Analogue\ORM\System\Query */ @@ -544,8 +554,9 @@ public function getManager() /** * Dynamically handle calls to custom commands, or Redirects to query() * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters + * @throws \Exception * @return mixed */ public function __call($method, $parameters) diff --git a/src/System/MapperFactory.php b/src/System/MapperFactory.php index a06ccf1..0912383 100755 --- a/src/System/MapperFactory.php +++ b/src/System/MapperFactory.php @@ -34,6 +34,12 @@ class MapperFactory */ protected $dispatcher; + /** + * MapperFactory constructor. + * @param DriverManager $drivers + * @param Dispatcher $dispatcher + * @param Manager $manager + */ public function __construct(DriverManager $drivers, Dispatcher $dispatcher, Manager $manager) { $this->drivers = $drivers; @@ -46,8 +52,8 @@ public function __construct(DriverManager $drivers, Dispatcher $dispatcher, Mana /** * Return a new Mapper instance * - * @param string $entityClass - * @param string $entityMap + * @param string $entityClass + * @param EntityMap $entityMap * @return Mapper */ public function make($entityClass, EntityMap $entityMap) diff --git a/src/System/Proxies/CollectionProxy.php b/src/System/Proxies/CollectionProxy.php index 675d9c7..422a9e8 100755 --- a/src/System/Proxies/CollectionProxy.php +++ b/src/System/Proxies/CollectionProxy.php @@ -10,6 +10,11 @@ use Illuminate\Contracts\Support\Arrayable; use Analogue\ORM\EntityCollection; +/** + * Class CollectionProxy + * + * @mixin EntityCollection + */ class CollectionProxy extends Proxy implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable { /** @@ -25,8 +30,8 @@ class CollectionProxy extends Proxy implements ArrayAccess, Arrayable, Countable protected $addedItems; /** - * @param mixed $parentEntity - * @param string $relation relationship method handled by the proxy. + * @param mixed $parentEntity + * @param string $relation relationship method handled by the proxy. */ public function __construct($parentEntity, $relation) { @@ -39,6 +44,7 @@ public function __construct($parentEntity, $relation) * Add an entity to the proxy collection, weither it's loaded or not * * @param mixed $entity + * @return self|void */ public function add($entity) { @@ -62,7 +68,7 @@ public function isLoaded() /** * Return the underlying collection * - * @return \Analogue\ORM\EntityCollection + * @return EntityCollection */ public function getUnderlyingCollection() { @@ -72,7 +78,7 @@ public function getUnderlyingCollection() /** * Return Items that has been added prior to lazy-loading * - * @return \Analogue\ORM\EntityCollection + * @return EntityCollection */ public function getAddedItems() { @@ -114,7 +120,7 @@ public function count() /** * Determine if an item exists at an offset. * - * @param mixed $key + * @param mixed $key * @return bool */ public function offsetExists($key) @@ -127,7 +133,7 @@ public function offsetExists($key) /** * Get an item at a given offset. * - * @param mixed $key + * @param mixed $key * @return mixed */ public function offsetGet($key) @@ -140,28 +146,26 @@ public function offsetGet($key) /** * Set the item at a given offset. * - * @param mixed $key - * @param mixed $value - * @return void + * @param mixed $key + * @param mixed $value */ public function offsetSet($key, $value) { $this->loadOnce(); - return $this->getUnderlyingCollection()->offsetSet($key, $value); + $this->getUnderlyingCollection()->offsetSet($key, $value); } /** * Unset the item at a given offset. * - * @param string $key - * @return void + * @param string $key */ public function offsetUnset($key) { $this->loadOnce(); - return $this->getUnderlyingCollection()->offsetUnset($key); + $this->getUnderlyingCollection()->offsetUnset($key); } /** @@ -191,7 +195,7 @@ public function jsonSerialize() /** * Get the collection of items as JSON. * - * @param int $options + * @param int $options * @return string */ public function toJson($options = 0) @@ -213,12 +217,11 @@ public function getIterator() return $this->getUnderlyingCollection()->getIterator(); } + /** - * Transparently Redirect non overrided calls to the lazy loaded collection - * - * @param [type] $method [description] - * @param [type] $parameters [description] - * @return [type] [description] + * @param $method + * @param $parameters + * @return mixed */ public function __call($method, $parameters) { diff --git a/src/System/Proxies/Proxy.php b/src/System/Proxies/Proxy.php index b8a552c..8370709 100755 --- a/src/System/Proxies/Proxy.php +++ b/src/System/Proxies/Proxy.php @@ -16,7 +16,7 @@ abstract class Proxy implements ProxyInterface /** * Reference to parent entity object * - * @var InternallyMappable + * @var \Analogue\ORM\System\InternallyMappable */ protected $parentEntity; @@ -29,7 +29,7 @@ abstract class Proxy implements ProxyInterface /** * @param mixed $parentEntity - * @param string $relation relationship method handled by the proxy. + * @param string $relation relationship method handled by the proxy. */ public function __construct($parentEntity, $relation) { @@ -65,9 +65,9 @@ public function isLoaded() /** * Return the Query Builder on the relation * - * @param mixed $entity - * @param string $relation - * @return Query + * @param mixed $entity + * @param string $relation + * @return \Analogue\ORM\System\Query */ protected function query($entity, $relation) { diff --git a/src/System/Proxies/ProxyInterface.php b/src/System/Proxies/ProxyInterface.php index 783636e..feb89d6 100755 --- a/src/System/Proxies/ProxyInterface.php +++ b/src/System/Proxies/ProxyInterface.php @@ -8,7 +8,7 @@ interface ProxyInterface /** * Convert a proxy into the underlying related Object * - * @return Mappable|EntityCollection + * @return Mappable|\Analogue\ORM\EntityCollection */ public function load(); diff --git a/src/System/Query.php b/src/System/Query.php index 55d7e81..88c878c 100755 --- a/src/System/Query.php +++ b/src/System/Query.php @@ -2,6 +2,7 @@ namespace Analogue\ORM\System; +use Analogue\ORM\Drivers\QueryAdapter; use Closure; use Exception; use Analogue\ORM\EntityCollection; @@ -14,6 +15,8 @@ /** * Analogue Query builder. + * + * @mixin QueryAdapter */ class Query { @@ -97,7 +100,8 @@ class Query /** * Create a new Analogue Query Builder instance. * - * @param \Analogue\ORM\System\Mapper $mapper + * @param Mapper $mapper + * @param DBAdapter $adapter * @return void */ public function __construct(Mapper $mapper, DBAdapter $adapter) @@ -117,7 +121,7 @@ public function __construct(Mapper $mapper, DBAdapter $adapter) /** * Run the query and return the result * - * @param array $columns + * @param array $columns * @return \Analogue\ORM\EntityCollection */ public function get($columns = ['*']) @@ -139,7 +143,7 @@ public function get($columns = ['*']) * Find an entity by its primary key * * @param string|integer $id - * @param array $columns + * @param array $columns * @return \Analogue\ORM\Mappable */ public function find($id, $columns = ['*']) @@ -156,8 +160,8 @@ public function find($id, $columns = ['*']) /** * Find many entities by their primary keys. * - * @param array $id - * @param array $columns + * @param array $id + * @param array $columns * @return EntityCollection */ public function findMany($id, $columns = ['*']) @@ -174,11 +178,10 @@ public function findMany($id, $columns = ['*']) /** * Find a model by its primary key or throw an exception. * - * @param mixed $id - * @param array $columns - * @return mixed|static - * - * @throws \Analogue\ORM\Exception\EntityNotFoundException + * @param mixed $id + * @param array $columns + * @throws \Analogue\ORM\Exceptions\EntityNotFoundException + * @return mixed|self */ public function findOrFail($id, $columns = ['*']) { @@ -193,7 +196,7 @@ public function findOrFail($id, $columns = ['*']) /** * Execute the query and get the first result. * - * @param array $columns + * @param array $columns * @return \Analogue\ORM\Entity */ public function first($columns = ['*']) @@ -204,10 +207,9 @@ public function first($columns = ['*']) /** * Execute the query and get the first result or throw an exception. * - * @param array $columns - * @return \Analogue\ORM\Entity - * + * @param array $columns * @throws EntityNotFoundException + * @return \Analogue\ORM\Entity */ public function firstOrFail($columns = ['*']) { @@ -221,7 +223,7 @@ public function firstOrFail($columns = ['*']) /** * Pluck a single column from the database. * - * @param string $column + * @param string $column * @return mixed */ public function pluck($column) @@ -236,8 +238,8 @@ public function pluck($column) /** * Chunk the results of the query. * - * @param int $count - * @param callable $callback + * @param int $count + * @param callable $callback * @return void */ public function chunk($count, callable $callback) @@ -259,8 +261,8 @@ public function chunk($count, callable $callback) /** * Get an array with the values of a given column. * - * @param string $column - * @param string $key + * @param string $column + * @param string $key * @return array */ public function lists($column, $key = null) @@ -271,8 +273,8 @@ public function lists($column, $key = null) /** * Get a paginator for the "select" statement. * - * @param int $perPage - * @param array $columns + * @param int $perPage + * @param array $columns * @return LengthAwarePaginator */ public function paginate($perPage = null, $columns = ['*']) @@ -292,9 +294,9 @@ public function paginate($perPage = null, $columns = ['*']) /** * Get a paginator for a grouped statement. * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns + * @param \Illuminate\Pagination\Factory $paginator + * @param int $perPage + * @param array $columns * @return \Illuminate\Pagination\Paginator */ protected function groupedPaginate($paginator, $perPage, $columns) @@ -307,9 +309,9 @@ protected function groupedPaginate($paginator, $perPage, $columns) /** * Get a paginator for an ungrouped statement. * - * @param \Illuminate\Pagination\Factory $paginator - * @param int $perPage - * @param array $columns + * @param \Illuminate\Pagination\Factory $paginator + * @param int $perPage + * @param array $columns * @return \Illuminate\Pagination\Paginator */ protected function ungroupedPaginate($paginator, $perPage, $columns) @@ -329,8 +331,8 @@ protected function ungroupedPaginate($paginator, $perPage, $columns) /** * Paginate the given query into a simple paginator. * - * @param int $perPage - * @param array $columns + * @param int $perPage + * @param array $columns * @return \Illuminate\Contracts\Pagination\Paginator */ public function simplePaginate($perPage = null, $columns = ['*']) @@ -341,18 +343,16 @@ public function simplePaginate($perPage = null, $columns = ['*']) $this->skip(($page - 1) * $perPage)->take($perPage + 1); - return new Paginator($this->get($columns)->all(), $perPage, $page, [ - 'path' => Paginator::resolveCurrentPath() - ]); + return new Paginator($this->get($columns)->all(), $perPage, $page, ['path' => Paginator::resolveCurrentPath()]); } /** * Add a basic where clause to the query. * - * @param string $column - * @param string $operator - * @param mixed $value - * @param string $boolean + * @param string $column + * @param string $operator + * @param mixed $value + * @param string $boolean * @return $this */ public function where($column, $operator = null, $value = null, $boolean = 'and') @@ -373,9 +373,9 @@ public function where($column, $operator = null, $value = null, $boolean = 'and' /** * Add an "or where" clause to the query. * - * @param string $column - * @param string $operator - * @param mixed $value + * @param string $column + * @param string $operator + * @param mixed $value * @return \Analogue\ORM\System\Query */ public function orWhere($column, $operator = null, $value = null) @@ -386,11 +386,11 @@ public function orWhere($column, $operator = null, $value = null) /** * Add a relationship count condition to the query. * - * @param string $relation - * @param string $operator - * @param int $count - * @param string $boolean - * @param \Closure $callback + * @param string $relation + * @param string $operator + * @param int $count + * @param string $boolean + * @param \Closure $callback * @return \Analogue\ORM\System\Query */ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null) @@ -411,10 +411,10 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $ /** * Add a relationship count condition to the query with where clauses. * - * @param string $relation - * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $relation + * @param \Closure $callback + * @param string $operator + * @param int $count * @return \Analogue\ORM\System\Query */ public function whereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -425,9 +425,9 @@ public function whereHas($relation, Closure $callback, $operator = '>=', $count /** * Add a relationship count condition to the query with an "or". * - * @param string $relation - * @param string $operator - * @param int $count + * @param string $relation + * @param string $operator + * @param int $count * @return \Analogue\ORM\System\Query */ public function orHas($relation, $operator = '>=', $count = 1) @@ -438,10 +438,10 @@ public function orHas($relation, $operator = '>=', $count = 1) /** * Add a relationship count condition to the query with where clauses and an "or". * - * @param string $relation - * @param \Closure $callback - * @param string $operator - * @param int $count + * @param string $relation + * @param \Closure $callback + * @param string $operator + * @param int $count * @return \Analogue\ORM\System\Query */ public function orWhereHas($relation, Closure $callback, $operator = '>=', $count = 1) @@ -452,11 +452,11 @@ public function orWhereHas($relation, Closure $callback, $operator = '>=', $coun /** * Add the "has" condition where clause to the query. * - * @param \Analogue\ORM\System\Query $hasQuery - * @param \Analogue\ORM\Relationships\Relationship $relation - * @param string $operator - * @param int $count - * @param string $boolean + * @param \Analogue\ORM\System\Query $hasQuery + * @param \Analogue\ORM\Relationships\Relationship $relation + * @param string $operator + * @param int $count + * @param string $boolean * @return \Analogue\ORM\System\Query */ protected function addHasWhere(Query $hasQuery, Relationship $relation, $operator, $count, $boolean) @@ -473,8 +473,8 @@ protected function addHasWhere(Query $hasQuery, Relationship $relation, $operato /** * Merge the "wheres" from a relation query to a has query. * - * @param \Analogue\ORM\System\Query $hasQuery - * @param \Analogue\ORM\Relationships\Relationship $relation + * @param \Analogue\ORM\System\Query $hasQuery + * @param \Analogue\ORM\Relationships\Relationship $relation * @return void */ protected function mergeWheresToHas(Query $hasQuery, Relationship $relation) @@ -494,12 +494,13 @@ protected function mergeWheresToHas(Query $hasQuery, Relationship $relation) /** * Get the "has relation" base query instance. * - * @param string $relation + * @param string $relation + * @param $entity * @return \Analogue\ORM\System\Query */ protected function getHasRelationQuery($relation, $entity) { - return Relationship::noConstraints(function() use ($relation, $entity) { + return Relationship::noConstraints(function () use ($relation, $entity) { return $this->entityMap->$relation($entity); }); } @@ -517,7 +518,7 @@ public function getTable() /** * Set the relationships that should be eager loaded. * - * @param mixed $relations + * @param mixed $relations * @return $this */ public function with($relations) @@ -536,7 +537,7 @@ public function with($relations) /** * Parse a list of relations into individuals. * - * @param array $relations + * @param array $relations * @return array */ protected function parseRelations(array $relations) @@ -548,7 +549,7 @@ protected function parseRelations(array $relations) // constraints have been specified for the eager load and we'll just put // an empty Closure with the loader so that we can treat all the same. if (is_numeric($name)) { - $f = function() {}; + $f = function () {}; list($name, $constraints) = [$constraints, $f]; } @@ -568,8 +569,8 @@ protected function parseRelations(array $relations) /** * Parse the nested relationships in a relation. * - * @param string $name - * @param array $results + * @param string $name + * @param array $results * @return array */ protected function parseNested($name, $results) @@ -583,7 +584,7 @@ protected function parseNested($name, $results) $progress[] = $segment; if (!isset($results[$last = implode('.', $progress)])) { - $results[$last] = function() {}; + $results[$last] = function () {}; } } @@ -603,7 +604,7 @@ public function getEagerLoads() /** * Set the relationships being eagerly loaded. * - * @param array $eagerLoad + * @param array $eagerLoad * @return void */ public function setEagerLoads(array $eagerLoad) @@ -614,7 +615,7 @@ public function setEagerLoads(array $eagerLoad) /** * Eager load the relationships for the entities. * - * @param array $entities + * @param array $entities * @return array */ public function eagerLoadRelations($entities) @@ -634,9 +635,9 @@ public function eagerLoadRelations($entities) /** * Eagerly load the relationship on a set of entities. * - * @param array $entities - * @param string $name - * @param \Closure $constraints + * @param array $entities + * @param string $name + * @param \Closure $constraints * @return array */ protected function loadRelation(array $entities, $name, Closure $constraints) @@ -664,7 +665,7 @@ protected function loadRelation(array $entities, $name, Closure $constraints) /** * Get the relation instance for the given relation name. * - * @param string $relation + * @param string $relation * @return \Analogue\ORM\Relationships\Relationship */ public function getRelation($relation) @@ -691,7 +692,7 @@ public function getRelation($relation) /** * Get the deeply nested relations for a given top-level relation. * - * @param string $relation + * @param string $relation * @return array */ protected function nestedRelations($relation) @@ -713,8 +714,8 @@ protected function nestedRelations($relation) /** * Determine if the relationship is nested. * - * @param string $name - * @param string $relation + * @param string $name + * @param string $relation * @return bool */ protected function isNested($name, $relation) @@ -742,7 +743,7 @@ protected function enforceIdColumn($columns) * Get the hydrated models without eager loading. * * @param array $columns - * @return Analogue\ORM\EntityCollection + * @return \Analogue\ORM\EntityCollection */ public function getEntities($columns = ['*']) { @@ -763,7 +764,7 @@ public function getEntities($columns = ['*']) * Get a new instance for the entity * * @param array $attributes - * @return Entity + * @return \Analogue\ORM\Entity */ public function getEntityInstance(array $attributes = []) { @@ -773,8 +774,8 @@ public function getEntityInstance(array $attributes = []) /** * Extend the builder with a given callback. * - * @param string $name - * @param \Closure $callback + * @param string $name + * @param \Closure $callback * @return void */ public function macro($name, Closure $callback) @@ -785,7 +786,7 @@ public function macro($name, Closure $callback) /** * Get the given macro by name. * - * @param string $name + * @param string $name * @return \Closure */ public function getMacro($name) @@ -841,8 +842,9 @@ public function getQuery() /** * Dynamically handle calls into the query instance. * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters + * @throws Exception * @return mixed */ public function __call($method, $parameters) diff --git a/src/System/ScopeInterface.php b/src/System/ScopeInterface.php index 29f091b..161ebe2 100755 --- a/src/System/ScopeInterface.php +++ b/src/System/ScopeInterface.php @@ -7,7 +7,7 @@ interface ScopeInterface /** * Apply the scope to a given Query builder. * - * @param \Analogue\ORM\System\Query $builder + * @param \Analogue\ORM\System\Query $builder * @return void */ public function apply(Query $builder); @@ -15,7 +15,7 @@ public function apply(Query $builder); /** * Remove the scope from the Query builder. * - * @param \Analogue\ORM\System\Query $builder + * @param \Analogue\ORM\System\Query $builder * @return void */ public function remove(Query $builder); diff --git a/src/System/Wrappers/EntityWrapper.php b/src/System/Wrappers/EntityWrapper.php index c4e738d..6400b24 100755 --- a/src/System/Wrappers/EntityWrapper.php +++ b/src/System/Wrappers/EntityWrapper.php @@ -69,7 +69,7 @@ public function getEntityAttribute($key) /** * Test if a given attribute exists * - * @param string $key + * @param string $key * @return boolean */ public function hasAttribute($key) diff --git a/src/System/Wrappers/PlainObjectWrapper.php b/src/System/Wrappers/PlainObjectWrapper.php index ba54b17..4aab2e8 100755 --- a/src/System/Wrappers/PlainObjectWrapper.php +++ b/src/System/Wrappers/PlainObjectWrapper.php @@ -16,14 +16,14 @@ class PlainObjectWrapper extends Wrapper /** * The reflection class for the managed entity * - * @var \ReflectionClass + * @var ReflectionClass */ protected $reflection; /** - * - * @param [type] $popoEntity [description] - * @param [type] $entityMap [description] + * PlainObjectWrapper constructor. + * @param $popoEntity + * @param $entityMap */ public function __construct($popoEntity, $entityMap) { @@ -71,8 +71,7 @@ protected function extract() } /** - * [getMappedProperties description] - * @return [type] [description] + * @return \ReflectionProperty[] */ protected function getMappedProperties() { @@ -82,7 +81,7 @@ protected function getMappedProperties() // We need to filter out properties that could belong to the object // and which are not intended to be handled by the ORM - return array_filter($objectProperties, function($item) use ($attributeList) { + return array_filter($objectProperties, function (\ReflectionProperty $item) use ($attributeList) { if (in_array($item->getName(), $attributeList)) { return true; } @@ -90,7 +89,8 @@ protected function getMappedProperties() } /** - * @param string $name + * @param string $name + * @return \ReflectionProperty */ protected function getMappedProperty($name) { @@ -100,6 +100,7 @@ protected function getMappedProperty($name) /** * Hydrate Plain PHP Object with wrapped attributes * + * @param $attributes * @return void */ protected function hydrate($attributes) @@ -113,7 +114,7 @@ protected function hydrate($attributes) $this->entity->$name = $attributes[$name]; } else { $property->setAccessible(true); - + $property->setValue($this->entity, $attributes[$name]); } } @@ -196,8 +197,6 @@ public function getEntityAttribute($key) */ public function hasAttribute($key) { - $attributes = $this->entity->getEntityAttributes(); - if (array_key_exists($key, $$this->attributeList)) { return true; } else { diff --git a/src/System/Wrappers/Wrapper.php b/src/System/Wrappers/Wrapper.php index b7eb7ef..416e4c6 100755 --- a/src/System/Wrappers/Wrapper.php +++ b/src/System/Wrappers/Wrapper.php @@ -25,6 +25,11 @@ abstract class Wrapper implements InternallyMappable */ protected $entityMap; + /** + * Wrapper constructor. + * @param $entity + * @param $entityMap + */ public function __construct($entity, $entityMap) { $this->entity = $entity; @@ -80,13 +85,33 @@ public function setProxies() } } + /** + * @param string $key + * @param string $value + * @return mixed + */ abstract public function setEntityAttribute($key, $value); + /** + * @param string $key + * @return mixed + */ abstract public function getEntityAttribute($key); + /** + * @param array $attributes + * @return mixed + */ abstract public function setEntityAttributes(array $attributes); + /** + * @return mixed + */ abstract public function getEntityAttributes(); + /** + * @param string $key + * @return mixed + */ abstract public function hasAttribute($key); } diff --git a/src/ValueMap.php b/src/ValueMap.php index 04197d5..e53f887 100755 --- a/src/ValueMap.php +++ b/src/ValueMap.php @@ -4,34 +4,61 @@ class ValueMap { + /** + * @var string + */ protected $name; + /** + * @var string + */ protected $class; + /** + * @var array + */ protected $embeddables = []; + /** + * @var array + */ protected $attributes = []; + /** + * @return array + */ public function getAttributes() { return $this->attributes; } + /** + * @return array + */ public function getEmbeddables() { return $this->embeddables; } + /** + * @param $class + */ public function setClass($class) { $this->class = $class; } + /** + * @return mixed + */ public function getClass() { return $this->class; } + /** + * @return string + */ public function getName() { if (isset($this->name)) { diff --git a/src/ValueObject.php b/src/ValueObject.php index 0f4abc1..faf19c8 100755 --- a/src/ValueObject.php +++ b/src/ValueObject.php @@ -16,7 +16,7 @@ class ValueObject implements Mappable, ArrayAccess, Jsonable, JsonSerializable, /** * Dynamically retrieve attributes on the entity. * - * @param string $key + * @param string $key * @return mixed */ public function __get($key) @@ -27,8 +27,8 @@ public function __get($key) /** * Dynamically set attributes on the entity. * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @return void */ public function __set($key, $value) @@ -39,7 +39,7 @@ public function __set($key, $value) /** * Determine if an attribute exists on the entity. * - * @param string $key + * @param string $key * @return bool */ public function __isset($key) @@ -50,7 +50,7 @@ public function __isset($key) /** * Unset an attribute on the entity. * - * @param string $key + * @param string $key * @return void */ public function __unset($key) @@ -62,7 +62,7 @@ public function __unset($key) /** * Determine if the given attribute exists. * - * @param mixed $offset + * @param mixed $offset * @return bool */ public function offsetExists($offset) @@ -73,7 +73,7 @@ public function offsetExists($offset) /** * Get the value for a given offset. * - * @param mixed $offset + * @param mixed $offset * @return mixed */ public function offsetGet($offset) @@ -84,8 +84,8 @@ public function offsetGet($offset) /** * Set the value for a given offset. * - * @param mixed $offset - * @param mixed $value + * @param mixed $offset + * @param mixed $value * @return void */ public function offsetSet($offset, $value) @@ -96,7 +96,7 @@ public function offsetSet($offset, $value) /** * Unset the value for a given offset. * - * @param mixed $offset + * @param mixed $offset * @return void */ public function offsetUnset($offset) @@ -117,7 +117,7 @@ public function jsonSerialize() /** * Convert the entity instance to JSON. * - * @param int $options + * @param int $options * @return string */ public function toJson($options = 0) @@ -138,6 +138,7 @@ public function toArray() /** * Transform the Object to array/json, * + * @param array $sourceAttributes * @return array */ protected function attributesToArray(array $sourceAttributes) From 8b5a2058b6930f7084c9a526d4fd62f1b8481a53 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 8 Jan 2016 17:15:02 +0000 Subject: [PATCH 6/9] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Plugins/SoftDeletes/SoftDeletingScope.php | 2 +- src/Relationships/BelongsTo.php | 4 ++-- src/Relationships/HasManyThrough.php | 8 ++++---- src/Relationships/MorphTo.php | 4 ++-- src/Relationships/Relationship.php | 2 +- src/System/Aggregate.php | 3 ++- src/System/Mapper.php | 2 +- src/System/Proxies/Proxy.php | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Plugins/SoftDeletes/SoftDeletingScope.php b/src/Plugins/SoftDeletes/SoftDeletingScope.php index e20a753..9457c28 100755 --- a/src/Plugins/SoftDeletes/SoftDeletingScope.php +++ b/src/Plugins/SoftDeletes/SoftDeletingScope.php @@ -41,7 +41,7 @@ public function remove(Query $query) $query = $query->getQuery(); - foreach ((array)$query->wheres as $key => $where) { + foreach ((array) $query->wheres as $key => $where) { // If the where clause is a soft delete date constraint, we will remove it from // the query and reset the keys on the wheres. This allows this developer to // include deleted model in a relationship result set that is lazy loaded. diff --git a/src/Relationships/BelongsTo.php b/src/Relationships/BelongsTo.php index e95b925..52352a7 100755 --- a/src/Relationships/BelongsTo.php +++ b/src/Relationships/BelongsTo.php @@ -70,7 +70,7 @@ public function attachTo($related) */ public function detachFrom($related) { - return $this->dissociate($related);//todo + return $this->dissociate($related); //todo } /** @@ -78,7 +78,7 @@ public function detachFrom($related) * * @param $relation * - * @return mixed + * @return \Analogue\ORM\Entity */ public function getResults($relation) { diff --git a/src/Relationships/HasManyThrough.php b/src/Relationships/HasManyThrough.php index 20e85b0..52efa68 100755 --- a/src/Relationships/HasManyThrough.php +++ b/src/Relationships/HasManyThrough.php @@ -150,7 +150,7 @@ public function addEagerConstraints(array $entities) * * @param \Analogue\ORM\Entity[] $entities * @param string $relation - * @return array + * @return \Analogue\ORM\Entity[] */ public function initRelation(array $entities, $relation) { @@ -167,7 +167,7 @@ public function initRelation(array $entities, $relation) * @param \Analogue\ORM\Entity[] $entities * @param EntityCollection $results * @param string $relation - * @return array + * @return \Analogue\ORM\Entity[] */ public function match(array $entities, EntityCollection $results, $relation) { @@ -221,7 +221,7 @@ protected function buildDictionary(EntityCollection $results) * Get the results of the relationship. * * @param $relation - * @return mixed + * @return EntityCollection */ public function getResults($relation) { @@ -277,7 +277,7 @@ protected function getSelectColumns(array $columns = ['*']) * * @param int $perPage * @param array $columns - * @return \Illuminate\Pagination\Paginator + * @return \Illuminate\Pagination\LengthAwarePaginator */ public function paginate($perPage = null, $columns = ['*']) { diff --git a/src/Relationships/MorphTo.php b/src/Relationships/MorphTo.php index 96a1949..0a4b0c1 100755 --- a/src/Relationships/MorphTo.php +++ b/src/Relationships/MorphTo.php @@ -102,7 +102,7 @@ public function match(array $entities, EntityCollection $results, $relation) /** * Get the results of the relationship. * - * @return mixed + * @return EntityCollection */ public function getEager() { @@ -152,7 +152,7 @@ protected function getResultsByType($type) * Gather all of the foreign keys for a given type. * * @param string $type - * @return array + * @return BaseCollection */ protected function gatherKeysByType($type) { diff --git a/src/Relationships/Relationship.php b/src/Relationships/Relationship.php index d51a7fc..4fabcb5 100755 --- a/src/Relationships/Relationship.php +++ b/src/Relationships/Relationship.php @@ -279,7 +279,7 @@ public function getQuery() /** * Get the base query builder * - * @return \Illuminate\Database\Query\Builder + * @return \Analogue\ORM\Drivers\QueryAdapter */ public function getBaseQuery() { diff --git a/src/System/Aggregate.php b/src/System/Aggregate.php index 78569d0..ab4d541 100755 --- a/src/System/Aggregate.php +++ b/src/System/Aggregate.php @@ -197,7 +197,7 @@ protected function parseSingleRelationship($relation) * Check if value isn't parent or root in the aggregate * * @param mixed - * @return true|void + * @return boolean|null */ protected function isParentOrRoot($value) { @@ -295,6 +295,7 @@ protected function createSubAggregates($entities, $relation) * Create a related subAggregate * * @param mixed $entity + * @param string $relation * @return self */ protected function createSubAggregate($entity, $relation) diff --git a/src/System/Mapper.php b/src/System/Mapper.php index 280204e..e53164e 100755 --- a/src/System/Mapper.php +++ b/src/System/Mapper.php @@ -141,7 +141,7 @@ protected function storeEntity($entity) */ protected function aggregate($entity) { - return new Aggregate($entity); + return new Aggregate($entity); } /** diff --git a/src/System/Proxies/Proxy.php b/src/System/Proxies/Proxy.php index 8370709..84d8e00 100755 --- a/src/System/Proxies/Proxy.php +++ b/src/System/Proxies/Proxy.php @@ -65,7 +65,7 @@ public function isLoaded() /** * Return the Query Builder on the relation * - * @param mixed $entity + * @param \Analogue\ORM\System\InternallyMappable $entity * @param string $relation * @return \Analogue\ORM\System\Query */ From c3628d000e05e0b7282838b2b6dc94e01ccb693a Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 8 Jan 2016 17:30:37 +0000 Subject: [PATCH 7/9] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/System/EntityCache.php | 2 +- src/System/Proxies/Proxy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index c01b9e5..a41bd74 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -144,7 +144,7 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation * Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any. * * @param $parentKey - * @param $relation + * @param string $relation * @param $result * @param Relationship $relationship * @return CachedRelationship diff --git a/src/System/Proxies/Proxy.php b/src/System/Proxies/Proxy.php index 84d8e00..dd14193 100755 --- a/src/System/Proxies/Proxy.php +++ b/src/System/Proxies/Proxy.php @@ -79,7 +79,7 @@ protected function query($entity, $relation) /** * Get the mapper instance for the entity * - * @param mixed $entity + * @param \Analogue\ORM\System\InternallyMappable $entity * @return \Analogue\ORM\System\Mapper */ protected function getMapper($entity) From e661259c492faea388218c82b395204937d74239 Mon Sep 17 00:00:00 2001 From: Maxim Kolokolnikov Date: Fri, 8 Jan 2016 23:34:27 +0600 Subject: [PATCH 8/9] small cs fixes --- src/System/EntityCache.php | 4 ++-- src/System/Proxies/Proxy.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index a41bd74..f8b37fe 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -143,8 +143,8 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation /** * Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any. * - * @param $parentKey - * @param string $relation + * @param $parentKey + * @param string $relation * @param $result * @param Relationship $relationship * @return CachedRelationship diff --git a/src/System/Proxies/Proxy.php b/src/System/Proxies/Proxy.php index dd14193..fee111b 100755 --- a/src/System/Proxies/Proxy.php +++ b/src/System/Proxies/Proxy.php @@ -2,7 +2,9 @@ namespace Analogue\ORM\System\Proxies; +use Analogue\ORM\Exceptions\MappingException; use Analogue\ORM\System\Manager; +use Analogue\ORM\System\Mapper; abstract class Proxy implements ProxyInterface { @@ -67,6 +69,7 @@ public function isLoaded() * * @param \Analogue\ORM\System\InternallyMappable $entity * @param string $relation + * @throws MappingException * @return \Analogue\ORM\System\Query */ protected function query($entity, $relation) @@ -80,6 +83,7 @@ protected function query($entity, $relation) * Get the mapper instance for the entity * * @param \Analogue\ORM\System\InternallyMappable $entity + * @throws MappingException * @return \Analogue\ORM\System\Mapper */ protected function getMapper($entity) From aa7f8a8e3bd4f60a781df5e68b4c1730827518fc Mon Sep 17 00:00:00 2001 From: Maxim Kolokolnikov Date: Sat, 9 Jan 2016 00:38:20 +0600 Subject: [PATCH 9/9] more exceptions docblocks --- src/AnalogueServiceProvider.php | 2 +- src/Commands/Command.php | 2 +- src/Commands/Store.php | 4 ++++ src/Drivers/DBAdapter.php | 2 +- src/EntityCollection.php | 9 +++++++++ src/EntityMap.php | 5 +---- src/Plugins/AnaloguePlugin.php | 4 ++++ src/Plugins/SoftDeletes/SoftDeletesPlugin.php | 2 ++ src/Plugins/SoftDeletes/SoftDeletingScope.php | 2 +- src/Plugins/Timestamps/TimestampsPlugin.php | 1 + src/Relationships/BelongsTo.php | 3 ++- src/Relationships/BelongsToMany.php | 14 +++++++------- src/Relationships/HasManyThrough.php | 3 +++ src/Relationships/HasOneOrMany.php | 5 ++++- src/Relationships/MorphOneOrMany.php | 11 ++++++----- src/Relationships/MorphTo.php | 2 ++ src/Relationships/Relationship.php | 5 +++-- src/Repository.php | 4 ++++ src/System/Aggregate.php | 6 +++++- src/System/EntityBuilder.php | 3 +++ src/System/EntityCache.php | 6 +++++- src/System/Manager.php | 3 ++- src/System/Mapper.php | 11 ++++++++++- src/System/Proxies/Proxy.php | 2 +- src/System/Query.php | 7 +++---- src/System/Wrappers/Factory.php | 1 + 26 files changed, 86 insertions(+), 33 deletions(-) diff --git a/src/AnalogueServiceProvider.php b/src/AnalogueServiceProvider.php index 2ebc711..c41d71d 100755 --- a/src/AnalogueServiceProvider.php +++ b/src/AnalogueServiceProvider.php @@ -35,7 +35,7 @@ public function boot() */ public function register() { - $this->app->singleton('analogue', function($app) { + $this->app->singleton('analogue', function ($app) { $db = $app['db']; diff --git a/src/Commands/Command.php b/src/Commands/Command.php index de6ca89..cf5ee58 100755 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -24,7 +24,7 @@ abstract class Command /** * Command constructor. * @param Aggregate $aggregate - * @param QueryAdapter $query + * @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query */ public function __construct(Aggregate $aggregate, QueryAdapter $query) { diff --git a/src/Commands/Store.php b/src/Commands/Store.php index d705958..09e3ae1 100755 --- a/src/Commands/Store.php +++ b/src/Commands/Store.php @@ -17,6 +17,7 @@ class Store extends Command /** * Persist the entity in the database * + * @throws \InvalidArgumentException * @return false|mixed */ public function execute() @@ -69,6 +70,7 @@ public function execute() * Run all operations that have to occur before actually * storing the entity * + * @throws \InvalidArgumentException * @return void */ protected function preStoreProcess() @@ -83,6 +85,7 @@ protected function preStoreProcess() * Check for existence and create non-existing related entities * * @param array + * @throws \InvalidArgumentException * @return void */ protected function createRelatedEntities($relations) @@ -112,6 +115,7 @@ protected function createStoreCommand(Aggregate $aggregate) * Run all operations that have to occur after the entity * is stored. * + * @throws \InvalidArgumentException * @return void */ protected function postStoreProcess() diff --git a/src/Drivers/DBAdapter.php b/src/Drivers/DBAdapter.php index c4e6a7b..2445046 100755 --- a/src/Drivers/DBAdapter.php +++ b/src/Drivers/DBAdapter.php @@ -7,7 +7,7 @@ interface DBAdapter /** * Return's Driver specific Query Implementation * - * @return \Analogue\ORM\Drivers\QueryAdapter + * @return \Analogue\ORM\Drivers\QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter */ public function getQuery(); diff --git a/src/EntityCollection.php b/src/EntityCollection.php index 0c3a4a5..5b2ac7a 100755 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -33,6 +33,7 @@ public function __construct(array $entities = null) * * @param mixed $key * @param mixed $default + * @throws MappingException * @return \Analogue\ORM\Entity */ public function find($key, $default = null) @@ -63,6 +64,7 @@ public function add($entity) * Remove an entity from the collection * * @param $entity + * @throws MappingException * @return mixed */ public function remove($entity) @@ -184,6 +186,7 @@ public function getSubsetByHashes(array $hashes) * Merge the collection with the given items. * * @param array $items + * @throws MappingException * @return self */ public function merge($items) @@ -222,6 +225,7 @@ public function diff($items) * Intersect the collection with the given items. * * @param \ArrayAccess|array $items + * @throws MappingException * @return self */ public function intersect($items) @@ -269,6 +273,7 @@ public function except($keys) * Get a dictionary keyed by primary keys. * * @param \ArrayAccess|array $items + * @throws MappingException * @return array */ public function getDictionary($items = null) @@ -285,6 +290,7 @@ public function getDictionary($items = null) } /** + * @throws MappingException * @return array */ public function getEntityKeys() @@ -310,6 +316,7 @@ protected function getEntityKey($entity) * Get the max value of a given key. * * @param string|null $key + * @throws MappingException * @return mixed */ public function max($key = null) @@ -326,6 +333,7 @@ public function max($key = null) * Get the min value of a given key. * * @param string|null $key + * @throws MappingException * @return mixed */ public function min($key = null) @@ -366,6 +374,7 @@ public function lists($value, $key = null) * Return only unique items from the collection. * * @param string|null $key + * @throws MappingException * @return self */ public function unique($key = null) diff --git a/src/EntityMap.php b/src/EntityMap.php index 0e5600a..e73a931 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -929,10 +929,7 @@ public function morphToMany($entity, $related, $name, $table = null, $foreignKey $table = $table ?: str_plural($name); - return new MorphToMany( - $relatedMapper, $entity, $name, $table, $foreignKey, - $otherKey, $caller, $inverse - ); + return new MorphToMany($relatedMapper, $entity, $name, $table, $foreignKey, $otherKey, $caller, $inverse); } /** diff --git a/src/Plugins/AnaloguePlugin.php b/src/Plugins/AnaloguePlugin.php index ca51788..0b15f29 100755 --- a/src/Plugins/AnaloguePlugin.php +++ b/src/Plugins/AnaloguePlugin.php @@ -13,6 +13,10 @@ abstract class AnaloguePlugin implements AnaloguePluginInterface */ protected $manager; + /** + * AnaloguePlugin constructor. + * @param Manager $manager + */ public function __construct(Manager $manager) { $this->manager = $manager; diff --git a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php index c6ef36e..b0c9866 100755 --- a/src/Plugins/SoftDeletes/SoftDeletesPlugin.php +++ b/src/Plugins/SoftDeletes/SoftDeletesPlugin.php @@ -16,6 +16,7 @@ class SoftDeletesPlugin extends AnaloguePlugin /** * Register the plugin * + * @throws \Exception * @return void */ public function register() @@ -38,6 +39,7 @@ public function register() * with the softDelete capacity. * * @param \Analogue\ORM\System\Mapper $mapper + * @throws \Analogue\ORM\Exceptions\MappingException * @return bool|void */ protected function registerSoftDelete(Mapper $mapper) diff --git a/src/Plugins/SoftDeletes/SoftDeletingScope.php b/src/Plugins/SoftDeletes/SoftDeletingScope.php index 9457c28..27108fc 100755 --- a/src/Plugins/SoftDeletes/SoftDeletingScope.php +++ b/src/Plugins/SoftDeletes/SoftDeletingScope.php @@ -32,7 +32,7 @@ public function apply(Query $query) /** * Remove the scope from the given Analogue query builder. * - * @param \Analogue\ORM\System\Query $query + * @param mixed $query * @return void */ public function remove(Query $query) diff --git a/src/Plugins/Timestamps/TimestampsPlugin.php b/src/Plugins/Timestamps/TimestampsPlugin.php index 17edfd3..0e83fb7 100755 --- a/src/Plugins/Timestamps/TimestampsPlugin.php +++ b/src/Plugins/Timestamps/TimestampsPlugin.php @@ -15,6 +15,7 @@ class TimestampsPlugin extends AnaloguePlugin /** * Register the plugin * + * @throws \Exception * @return void */ public function register() diff --git a/src/Relationships/BelongsTo.php b/src/Relationships/BelongsTo.php index 52352a7..fc046c7 100755 --- a/src/Relationships/BelongsTo.php +++ b/src/Relationships/BelongsTo.php @@ -57,7 +57,8 @@ public function __construct(Mapper $mapper, $parent, $foreignKey, $otherKey, $re } /** - * @param $related + * @param $related + * @return mixed */ public function attachTo($related) { diff --git a/src/Relationships/BelongsToMany.php b/src/Relationships/BelongsToMany.php index f5208b4..f23bb86 100755 --- a/src/Relationships/BelongsToMany.php +++ b/src/Relationships/BelongsToMany.php @@ -10,10 +10,6 @@ use Analogue\ORM\System\InternallyMappable; use Analogue\ORM\Exceptions\EntityNotFoundException; -/** - * @method where - * @method take - */ class BelongsToMany extends Relationship { /** @@ -79,14 +75,16 @@ public function __construct(Mapper $mapper, $parent, $table, $foreignKey, $other } /** - * @param $related + * @param $related + * @return mixed */ public function attachTo($related) { } /** - * @param $related + * @param $related + * @return mixed */ public function detachFrom($related) { @@ -574,6 +572,7 @@ public function createPivots($relatedEntities) * * @param mixed $id * @param array $attributes + * @throws \InvalidArgumentException * @return integer */ public function updateExistingPivot($id, array $attributes) @@ -762,6 +761,7 @@ protected function getModelKeysFromCollection(EntityCollection $entities) * Detach models from the relationship. * * @param int|array $ids + * @throws \InvalidArgumentException * @return int */ public function detach($ids = []) @@ -790,7 +790,7 @@ public function detach($ids = []) /** * Create a new query builder for the pivot table. * - * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * * @return \Illuminate\Database\Query\Builder */ diff --git a/src/Relationships/HasManyThrough.php b/src/Relationships/HasManyThrough.php index 52efa68..0367956 100755 --- a/src/Relationships/HasManyThrough.php +++ b/src/Relationships/HasManyThrough.php @@ -45,6 +45,7 @@ class HasManyThrough extends Relationship * @param \Analogue\ORM\EntityMap $parentMap * @param string $firstKey * @param string $secondKey + * @throws \Analogue\ORM\Exceptions\MappingException */ public function __construct(Mapper $mapper, $farParent, $parentMap, $firstKey, $secondKey) { @@ -61,6 +62,7 @@ public function __construct(Mapper $mapper, $farParent, $parentMap, $firstKey, $ /** * @param $related + * @return mixed */ public function attachTo($related) { @@ -69,6 +71,7 @@ public function attachTo($related) /** * @param $related + * @return mixed */ public function detachFrom($related) { diff --git a/src/Relationships/HasOneOrMany.php b/src/Relationships/HasOneOrMany.php index e0038a5..5128f9a 100755 --- a/src/Relationships/HasOneOrMany.php +++ b/src/Relationships/HasOneOrMany.php @@ -39,6 +39,7 @@ public function __construct(Mapper $mapper, $parentEntity, $foreignKey, $localKe /** * @param \Analogue\ORM\Entity|EntityCollection $entity + * @return void */ public function attachTo($entity) { @@ -96,6 +97,7 @@ protected function detachOne($entityHash) /** * Attach ids that are passed as arguments, and detach any other * @param mixed $entities + * @throws \InvalidArgumentException * @return void */ public function sync(array $entities) @@ -104,7 +106,8 @@ public function sync(array $entities) } /** - * @param $entities + * @param $entities + * @throws \InvalidArgumentException */ protected function detachExcept($entities) { diff --git a/src/Relationships/MorphOneOrMany.php b/src/Relationships/MorphOneOrMany.php index fff114b..dae623d 100755 --- a/src/Relationships/MorphOneOrMany.php +++ b/src/Relationships/MorphOneOrMany.php @@ -24,11 +24,12 @@ abstract class MorphOneOrMany extends HasOneOrMany /** * Create a new has many relationship instance. * - * @param Mapper $mapper - * @param \Analogue\ORM\Mappable $parent - * @param string $type - * @param string $id - * @param string $localKey + * @param Mapper $mapper + * @param \Analogue\ORM\Mappable $parent + * @param string $type + * @param string $id + * @param string $localKey + * @throws \Analogue\ORM\Exceptions\MappingException */ public function __construct(Mapper $mapper, $parent, $type, $id, $localKey) { diff --git a/src/Relationships/MorphTo.php b/src/Relationships/MorphTo.php index 0a4b0c1..b823358 100755 --- a/src/Relationships/MorphTo.php +++ b/src/Relationships/MorphTo.php @@ -102,6 +102,7 @@ public function match(array $entities, EntityCollection $results, $relation) /** * Get the results of the relationship. * + * @throws \Analogue\ORM\Exceptions\MappingException * @return EntityCollection */ public function getEager() @@ -135,6 +136,7 @@ protected function matchToMorphParents($type, EntityCollection $results) * Get all of the relation results for a type. * * @param string $type + * @throws \Analogue\ORM\Exceptions\MappingException * @return EntityCollection */ protected function getResultsByType($type) diff --git a/src/Relationships/Relationship.php b/src/Relationships/Relationship.php index 4fabcb5..0c0a6eb 100755 --- a/src/Relationships/Relationship.php +++ b/src/Relationships/Relationship.php @@ -97,8 +97,9 @@ abstract class Relationship /** * Create a new relation instance. * - * @param Mapper $mapper - * @param Mappable $parent + * @param Mapper $mapper + * @param Mappable $parent + * @throws \Analogue\ORM\Exceptions\MappingException */ public function __construct(Mapper $mapper, $parent) { diff --git a/src/Repository.php b/src/Repository.php index ca1b70e..cd5ca0d 100755 --- a/src/Repository.php +++ b/src/Repository.php @@ -102,6 +102,8 @@ public function paginate($perPage = null) * Delete an entity or an entity collection from the database * * @param Mappable|EntityCollection $entity + * @throws MappingException + * @throws \InvalidArgumentException * @return \Illuminate\Support\Collection|null */ public function delete($entity) @@ -113,6 +115,8 @@ public function delete($entity) * Persist an entity or an entity collection in the database. * * @param Mappable|EntityCollection|array $entity + * @throws MappingException + * @throws \InvalidArgumentException * @return Mappable|EntityCollection|array */ public function store($entity) diff --git a/src/System/Aggregate.php b/src/System/Aggregate.php index ab4d541..aadb328 100755 --- a/src/System/Aggregate.php +++ b/src/System/Aggregate.php @@ -79,6 +79,7 @@ class Aggregate implements InternallyMappable * @param Aggregate|null $parent * @param string $parentRelationship * @param Aggregate|null $root + * @throws MappingException */ public function __construct($entity, Aggregate $parent = null, $parentRelationship = null, Aggregate $root = null) { @@ -102,6 +103,7 @@ public function __construct($entity, Aggregate $parent = null, $parentRelationsh /** * Parse Every relationships defined on the entity * + * @throws MappingException * @return void */ protected function parseRelationships() @@ -295,7 +297,8 @@ protected function createSubAggregates($entities, $relation) * Create a related subAggregate * * @param mixed $entity - * @param string $relation + * @param string $relation + * @throws MappingException * @return self */ protected function createSubAggregate($entity, $relation) @@ -577,6 +580,7 @@ protected function flattenEmbeddables($attributes) * Return's entity raw attributes in the state they were at last * query. * + * @param array|null $columns * @return array */ protected function getCachedRawAttributes(array $columns = null) diff --git a/src/System/EntityBuilder.php b/src/System/EntityBuilder.php index 2ba4ed6..cbfa990 100755 --- a/src/System/EntityBuilder.php +++ b/src/System/EntityBuilder.php @@ -112,6 +112,7 @@ public function build(array $results) /** * Get the correct wrapper prototype corresponding to the object type * + * @throws \Analogue\ORM\Exceptions\MappingException * @return InternallyMappable */ protected function getWrapperInstance() @@ -123,6 +124,7 @@ protected function getWrapperInstance() * Hydrate value object embedded in this entity * * @param array $attributes + * @throws \Analogue\ORM\Exceptions\MappingException * @return void */ protected function hydrateValueObjects(& $attributes) @@ -138,6 +140,7 @@ protected function hydrateValueObjects(& $attributes) * @param array $attributes * @param string $localKey * @param string $valueClass + * @throws \Analogue\ORM\Exceptions\MappingException * @return void */ protected function hydrateValueObject(& $attributes, $localKey, $valueClass) diff --git a/src/System/EntityCache.php b/src/System/EntityCache.php index f8b37fe..9ad2a15 100755 --- a/src/System/EntityCache.php +++ b/src/System/EntityCache.php @@ -116,7 +116,7 @@ protected function mergeCacheResults($entities) * @param string $relation name of the relation * @param mixed $results results of the relationship's query * @param Relationship $relationship - * + * @throws MappingException * @return void */ public function cacheLoadedRelationResult($parent, $relation, $results, Relationship $relationship) @@ -147,6 +147,7 @@ public function cacheLoadedRelationResult($parent, $relation, $results, Relation * @param string $relation * @param $result * @param Relationship $relationship + * @throws MappingException * @return CachedRelationship */ protected function getCachedRelationship($parentKey, $relation, $result, Relationship $relationship) @@ -186,6 +187,7 @@ protected function getCachedRelationship($parentKey, $relation, $result, Relatio * @param string $relation * @param EntityCollection $results * @param Relationship $relationship + * @throws MappingException */ protected function cacheManyRelationResults($parentKey, $relation, $results, Relationship $relationship) { @@ -207,6 +209,7 @@ protected function cacheManyRelationResults($parentKey, $relation, $results, Rel * @param string $relation * @param Mappable $result * @param Relationship $relationship + * @throws MappingException */ protected function cacheSingleRelationResult($parentKey, $relation, $result, Relationship $relationship) { @@ -217,6 +220,7 @@ protected function cacheSingleRelationResult($parentKey, $relation, $result, Rel * Get Entity's Hash * * @param $entity + * @throws MappingException * @return string */ protected function getEntityHash(InternallyMappable $entity) diff --git a/src/System/Manager.php b/src/System/Manager.php index 14f900f..b71f5ac 100755 --- a/src/System/Manager.php +++ b/src/System/Manager.php @@ -136,6 +136,7 @@ public function mapper($entity, $entityMap = null) * * @param string $entity * @param $entityMap + * @throws MappingException * @return Mapper */ protected function buildMapper($entity, $entityMap) @@ -231,7 +232,7 @@ public function register($entity, $entityMap = null) } if (!$entityMap instanceof EntityMap) { - throw new MappingException(get_class($entityMap) . " must be an instance of EntityMap."); + throw new MappingException(get_class($entityMap) . ' must be an instance of EntityMap.'); } $entityMap->setClass($entity); diff --git a/src/System/Mapper.php b/src/System/Mapper.php index e53164e..2fbf25b 100755 --- a/src/System/Mapper.php +++ b/src/System/Mapper.php @@ -95,6 +95,8 @@ public function __construct(EntityMap $entityMap, DBAdapter $adapter, Dispatcher * Persist an entity or an entity collection into the database * * @param Mappable|Collection $entity + * @throws \InvalidArgumentException + * @throws MappingException * @return Mappable|Collection */ public function store($entity) @@ -122,6 +124,7 @@ protected function isArrayOrCollection($argument) * * @param Mappable $entity * @throws \InvalidArgumentException + * @throws MappingException * @return \Analogue\ORM\Entity */ protected function storeEntity($entity) @@ -137,11 +140,12 @@ protected function storeEntity($entity) * Convert an entity into an aggregate root * * @param mixed $entity + * @throws MappingException * @return \Analogue\ORM\System\Aggregate */ protected function aggregate($entity) { - return new Aggregate($entity); + return new Aggregate($entity); } /** @@ -149,6 +153,7 @@ protected function aggregate($entity) * * @param Collection|array $entities * @throws \InvalidArgumentException + * @throws MappingException * @return Collection */ protected function storeCollection($entities) @@ -168,6 +173,8 @@ protected function storeCollection($entities) * Delete an entity or an entity collection from the database * * @param mixed|Collection + * @throws MappingException + * @throws \InvalidArgumentException * @return Collection|void */ public function delete($entity) @@ -389,6 +396,7 @@ public function addCustomCommand($command) * @param string $command * @param mixed|Collection|array $entity * @throws \InvalidArgumentException + * @throws MappingException * @return mixed */ public function executeCustomCommand($command, $entity) @@ -410,6 +418,7 @@ public function executeCustomCommand($command, $entity) * @param string $commandClass * @param mixed $entity * @throws \InvalidArgumentException + * @throws MappingException * @return mixed */ protected function executeSingleCustomCommand($commandClass, $entity) diff --git a/src/System/Proxies/Proxy.php b/src/System/Proxies/Proxy.php index fee111b..c371d8a 100755 --- a/src/System/Proxies/Proxy.php +++ b/src/System/Proxies/Proxy.php @@ -4,7 +4,6 @@ use Analogue\ORM\Exceptions\MappingException; use Analogue\ORM\System\Manager; -use Analogue\ORM\System\Mapper; abstract class Proxy implements ProxyInterface { @@ -43,6 +42,7 @@ public function __construct($parentEntity, $relation) /** * Call the relationship method on the underlying entity map * + * @throws MappingException * @return mixed */ public function load() diff --git a/src/System/Query.php b/src/System/Query.php index 88c878c..2c8056d 100755 --- a/src/System/Query.php +++ b/src/System/Query.php @@ -16,7 +16,7 @@ /** * Analogue Query builder. * - * @mixin QueryAdapter + * @mixin QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter */ class Query { @@ -37,7 +37,7 @@ class Query /** * Query Builder Instance * - * @var \Analogue\ORM\Drivers\QueryAdapter + * @var \Analogue\ORM\Drivers\QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter */ protected $query; @@ -102,7 +102,6 @@ class Query * * @param Mapper $mapper * @param DBAdapter $adapter - * @return void */ public function __construct(Mapper $mapper, DBAdapter $adapter) { @@ -832,7 +831,7 @@ public function getMapper() * (REFACTOR: this method should move out, we need to provide the client classes * with the adapter instead.) * - * @return \Analogue\ORM\Drivers\QueryAdapter + * @return \Analogue\ORM\Drivers\QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter */ public function getQuery() { diff --git a/src/System/Wrappers/Factory.php b/src/System/Wrappers/Factory.php index cac385f..33e3812 100755 --- a/src/System/Wrappers/Factory.php +++ b/src/System/Wrappers/Factory.php @@ -11,6 +11,7 @@ class Factory * Build the wrapper corresponding to the object's type * * @param mixed $object + * @throws \Analogue\ORM\Exceptions\MappingException * @return Wrapper */ public function make($object)