From 534a2f5ed7b85abdbe294aa1b7a5484a2a6908cf Mon Sep 17 00:00:00 2001 From: Daniel LaBarge Date: Wed, 27 Jan 2016 12:33:38 -0600 Subject: [PATCH 1/6] Fixed isRelationship() --- src/Traits/RelatingModelTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/RelatingModelTrait.php b/src/Traits/RelatingModelTrait.php index 0066cbb..a60e283 100644 --- a/src/Traits/RelatingModelTrait.php +++ b/src/Traits/RelatingModelTrait.php @@ -141,7 +141,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 ); } /** From ef8241ca88c9df1791278494b54af5457e65645a Mon Sep 17 00:00:00 2001 From: Daniel LaBarge Date: Wed, 27 Jan 2016 12:40:39 -0600 Subject: [PATCH 2/6] Fix for relationshipPivots not being set on the model. --- src/Traits/RelatingModelTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/RelatingModelTrait.php b/src/Traits/RelatingModelTrait.php index a60e283..c31b505 100644 --- a/src/Traits/RelatingModelTrait.php +++ b/src/Traits/RelatingModelTrait.php @@ -152,7 +152,7 @@ public function isRelationship( $name ) */ public function hasPivotAttributes( $name ) { - return array_key_exists( $name, $this->relationshipPivots ); + return array_key_exists( $name, $this->relationshipPivots ?: [] ); } /** From b5d47a92326b378fd8b3f19cfefb4516ce487301 Mon Sep 17 00:00:00 2001 From: Diego Caprioli Date: Wed, 14 Sep 2016 14:26:07 -0300 Subject: [PATCH 3/6] Updated the read.me relationship bindings example. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 */ From 70af1ba0af10b3df553840d502e73820736726f3 Mon Sep 17 00:00:00 2001 From: Diego Caprioli Date: Wed, 14 Sep 2016 14:35:31 -0300 Subject: [PATCH 4/6] Updated the read.me relationship bindings example. --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index de61c2b..15da74e 100644 --- a/readme.md +++ b/readme.md @@ -725,7 +725,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 */ From 4ccdd493a701af1a60d981104c056863d63f1acc Mon Sep 17 00:00:00 2001 From: Diego Caprioli Date: Wed, 14 Sep 2016 14:58:55 -0300 Subject: [PATCH 5/6] Fixed failing test. --- tests/RelatingModelTraitTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RelatingModelTraitTest.php b/tests/RelatingModelTraitTest.php index 57e68da..5e8dcd4 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(); From 1ec936e53c1b07556be143a04c96e983ebff41a6 Mon Sep 17 00:00:00 2001 From: Diego Caprioli Date: Wed, 14 Sep 2016 15:19:25 -0300 Subject: [PATCH 6/6] Processed code with php-cs-fixer. --- src/Contracts/ValidatingModelInterface.php | 2 +- src/Model.php | 1 - src/Observers/ValidatingModelObserver.php | 3 +-- src/Traits/EncryptingModelTrait.php | 2 -- src/Traits/JugglingModelTrait.php | 6 ------ src/Traits/PurgingModelTrait.php | 1 - src/Traits/RelatingModelTrait.php | 6 ++---- src/Traits/ValidatingModelTrait.php | 3 +-- tests/RelatingModelTraitTest.php | 7 ++----- 9 files changed, 7 insertions(+), 24 deletions(-) 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 e37603b..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 ) || method_exists( $this, $name ); + 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 5e8dcd4..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->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)); + $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',