diff --git a/readme.md b/readme.md index 0d12077..bc7c999 100644 --- a/readme.md +++ b/readme.md @@ -726,7 +726,7 @@ class Post extends Eloquent implements RelatingModelInterface { * [ 'morphMany', 'related', 'name', 'type', 'id', 'localKey' ] * [ 'morphTo', 'name', 'type', 'id' ] * [ 'morphToMany', 'related', 'name', 'table', 'foreignKey', 'otherKey', 'inverse' ] - * [ 'morphByMany', 'related', 'name', 'table', 'foreignKey', 'otherKey' ] + * [ 'morphedByMany', 'related', 'name', 'table', 'foreignKey', 'otherKey' ] * * @var array */ diff --git a/src/Contracts/ValidatingModelInterface.php b/src/Contracts/ValidatingModelInterface.php index e7ab2d6..11c8881 100644 --- a/src/Contracts/ValidatingModelInterface.php +++ b/src/Contracts/ValidatingModelInterface.php @@ -15,7 +15,7 @@ * @deprecated In watson/validating@0.10.9 the custom methods * used below were deprecated in favor of Laravel 5's * form request validation classes. Stop using - * rulesets right now as they will be removed. + * rulesets right now as they will be removed * @see Watson\Validating\ValidatingInterface */ interface ValidatingModelInterface extends ValidatingInterface diff --git a/src/Model.php b/src/Model.php index 15c5dec..3a56726 100644 --- a/src/Model.php +++ b/src/Model.php @@ -173,7 +173,6 @@ public function __get($key) // Dynamically retrieve the encryptable attribute $value = $this->getDynamicEncrypted($key); if (is_null($value) || ! is_string($value)) { - // Fallback to the default Eloquent dynamic getter $value = parent::__get($key); } diff --git a/src/Observers/ValidatingModelObserver.php b/src/Observers/ValidatingModelObserver.php index a77d73e..f7891ac 100644 --- a/src/Observers/ValidatingModelObserver.php +++ b/src/Observers/ValidatingModelObserver.php @@ -16,7 +16,7 @@ * @deprecated In watson/validating@0.10.9 the custom methods * used below were deprecated in favor of Laravel 5's * form request validation classes. Stop using - * rulesets right now as they will be removed. + * rulesets right now as they will be removed * @see Esensi\Model\Traits\ValidatingModelTrait * @see Watson\Validating\ValidatingObserver */ @@ -105,7 +105,6 @@ protected function performValidation(Model $model, $event) { // If the model has validating enabled, perform it. if ($model->getValidating()) { - // Fire the namespaced validating event and prevent validation // if it returns a value. if ($this->fireValidatingEvent($model, $event) !== null) { diff --git a/src/Traits/EncryptingModelTrait.php b/src/Traits/EncryptingModelTrait.php index 1baf922..7c5e312 100644 --- a/src/Traits/EncryptingModelTrait.php +++ b/src/Traits/EncryptingModelTrait.php @@ -79,7 +79,6 @@ protected function getDynamicEncrypted($attribute) { // Dynamically get the encrypted attributes if ($this->isEncryptable($attribute)) { - // Decrypt only encrypted values if ($this->isEncrypted($attribute)) { return $this->getEncryptedAttribute($attribute); @@ -99,7 +98,6 @@ protected function setDynamicEncryptable($attribute, $value) { // Dynamically set the encryptable attribute if ($this->isEncryptable($attribute)) { - // Encrypt only decrypted values if ($this->isDecrypted($attribute)) { $this->setEncryptingAttribute($attribute, $value); diff --git a/src/Traits/JugglingModelTrait.php b/src/Traits/JugglingModelTrait.php index d3baa53..c94e9b6 100644 --- a/src/Traits/JugglingModelTrait.php +++ b/src/Traits/JugglingModelTrait.php @@ -68,7 +68,6 @@ public function attributesToArray() { // Check if juggling is enabled if ($this->getJuggling()) { - // Juggle all the jugglable attributes $this->juggleAttributes(); } @@ -106,7 +105,6 @@ protected function setDynamicJuggle($key, $value) { // Check that the attribute is jugglable if ( ! is_null($value) && $this->isJugglable($key)) { - // Cast the value to the type set for the attribute $this->juggleAttribute($key, $value); } @@ -254,7 +252,6 @@ public function checkJuggleType($type) // If not valid, throw an exception. if ( ! $this->isJuggleType($type)) { throw new InvalidArgumentException('The type "'.$type.'" is not a valid type cast.'); - return false; } @@ -275,7 +272,6 @@ public function buildJuggleMethod($type) // Map the type to it's normalized type switch ($type) { - case 'bool': case 'boolean': $normalizedType = 'boolean'; @@ -364,12 +360,10 @@ public function juggle($value, $type) { // Cast non-null values if ( ! is_null($value)) { - // Ensure that the type is a valid type to cast. // We do this check here because it might not have been done // as is the case when the model is first initialized. if ($this->checkJuggleType($type)) { - // Get the method that the type maps to $method = $this->buildJuggleMethod($type); diff --git a/src/Traits/PurgingModelTrait.php b/src/Traits/PurgingModelTrait.php index 2e7fb2f..1d353b3 100644 --- a/src/Traits/PurgingModelTrait.php +++ b/src/Traits/PurgingModelTrait.php @@ -131,7 +131,6 @@ public function purgeAttributes() // Filter out keys that should purged $attributes = array_filter($keys, function ($key) { - // Remove attributes that should be purged if (in_array($key, $this->getPurgeable())) { return false; diff --git a/src/Traits/RelatingModelTrait.php b/src/Traits/RelatingModelTrait.php index 5058d68..fef8687 100644 --- a/src/Traits/RelatingModelTrait.php +++ b/src/Traits/RelatingModelTrait.php @@ -81,7 +81,6 @@ protected function getDynamicRelationship($name) { // Dynamically get the relationship if ($this->isRelationship($name)) { - // Use the relationship already loaded if (array_key_exists($name, $this->getRelations())) { return $this->getRelation($name); @@ -144,7 +143,7 @@ public function getPivotAttributes($name) */ public function isRelationship($name) { - return array_key_exists($name, $this->relationships); + return array_key_exists($name, $this->relationships) || method_exists($this, $name); } /** @@ -156,7 +155,7 @@ public function isRelationship($name) */ public function hasPivotAttributes($name) { - return array_key_exists($name, $this->relationshipPivots); + return array_key_exists($name, $this->relationshipPivots ?: []); } /** @@ -178,7 +177,6 @@ protected function callRelationship($name) // Check to see if this relationship has extended pivot attributes if ($this->hasPivotAttributes($name)) { - // Add timestamps to relationship $attributes = $this->getPivotAttributes($name); if (in_array('timestamps', $attributes)) { diff --git a/src/Traits/ValidatingModelTrait.php b/src/Traits/ValidatingModelTrait.php index cb5eddc..ee0d45f 100644 --- a/src/Traits/ValidatingModelTrait.php +++ b/src/Traits/ValidatingModelTrait.php @@ -16,7 +16,7 @@ * @deprecated In watson/validating@0.10.9 the custom methods * used below were deprecated in favor of Laravel 5's * form request validation classes. Stop using - * rulesets right now as they will be removed. + * rulesets right now as they will be removed * @see Esensi\Model\Contracts\ValidatingModelInterface */ trait ValidatingModelTrait @@ -98,7 +98,6 @@ public function getRuleset($ruleset, $mergeWithSaving = false) { $rulesets = $this->getRulesets(); if (array_key_exists($ruleset, $rulesets)) { - // If the ruleset exists and merge with saving is true, return // the rulesets merged. if ($mergeWithSaving) { diff --git a/tests/RelatingModelTraitTest.php b/tests/RelatingModelTraitTest.php index 57e68da..36c777b 100644 --- a/tests/RelatingModelTraitTest.php +++ b/tests/RelatingModelTraitTest.php @@ -150,8 +150,8 @@ public function testScopeWithoutRemovesArrayDotKeys() // Make sure high level unsetting maintains deep relationships $relationships = $model->with('foo.bar')->without('foo')->getEagerLoads(); $keys = array_keys(array_dot($relationships)); - $this->assertContains('foo', $keys); - $this->assertContains('foo.bar', $keys); + $this->assertNotContains('foo', $keys, 'foo should NOT be in '.var_export($keys, true)); + $this->assertContains('foo.bar', $keys, 'foo.bar should be in '.var_export($keys, true)); // Make sure high level relationships are not unset by low level $relationships = $model->with('foo')->without('foo.bar')->getEagerLoads(); @@ -179,7 +179,6 @@ class ModelRelatingStub extends Model * @var array */ protected $relationships = [ - 'foo' => [ 'belongsTo', 'FooModelStub', @@ -202,7 +201,6 @@ class ModelRelatingStub extends Model * @var array */ protected $relationshipPivots = [ - 'many' => ['foo', 'timestamps'], ]; } @@ -218,7 +216,6 @@ class FooModelStub extends Model * @var array */ protected $relationships = [ - 'bar' => [ 'belongsTo', 'BarModelStub',