Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Caprioli committed Sep 14, 2016
2 parents 6bc8a8d + 1ec936e commit ed72750
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ValidatingModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Observers/ValidatingModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/Traits/EncryptingModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/Traits/JugglingModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function attributesToArray()
{
// Check if juggling is enabled
if ($this->getJuggling()) {

// Juggle all the jugglable attributes
$this->juggleAttributes();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -275,7 +272,6 @@ public function buildJuggleMethod($type)

// Map the type to it's normalized type
switch ($type) {

case 'bool':
case 'boolean':
$normalizedType = 'boolean';
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/Traits/PurgingModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/Traits/RelatingModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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 ?: []);
}

/**
Expand All @@ -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)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Traits/ValidatingModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions tests/RelatingModelTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -179,7 +179,6 @@ class ModelRelatingStub extends Model
* @var array
*/
protected $relationships = [

'foo' => [
'belongsTo',
'FooModelStub',
Expand All @@ -202,7 +201,6 @@ class ModelRelatingStub extends Model
* @var array
*/
protected $relationshipPivots = [

'many' => ['foo', 'timestamps'],
];
}
Expand All @@ -218,7 +216,6 @@ class FooModelStub extends Model
* @var array
*/
protected $relationships = [

'bar' => [
'belongsTo',
'BarModelStub',
Expand Down

0 comments on commit ed72750

Please sign in to comment.