Skip to content

Commit

Permalink
Renamed the property _hasErrors and method hasErrors() to respectivel…
Browse files Browse the repository at this point in the history
…y _canBePersisted and canBePersisted().
  • Loading branch information
JoshuaLuckers committed Jul 4, 2018
1 parent f620cad commit 4069319
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Datasource/EntityInterface.php
Expand Up @@ -29,8 +29,8 @@
* @method array getVirtual()
* @method $this setDirty($property, $isDirty)
* @method bool isDirty($property = null)
* @method bool canBePersisted()
* @method array getErrors()
* @method bool hasErrors()
* @method array getError($field)
* @method array setErrors(array $fields, $overwrite = false)
* @method array setError($field, $errors, $overwrite = false)
Expand Down
36 changes: 18 additions & 18 deletions src/Datasource/EntityTrait.php
Expand Up @@ -91,18 +91,18 @@ trait EntityTrait
protected $_new = true;

/**
* List of errors per field as stored in this object
* Returns whether this entity can be persisted.
*
* @var array
* @var bool
*/
protected $_errors = [];
protected $_canBePersisted = true;

/**
* Returns whether this entity contains errors.
* List of errors per field as stored in this object
*
* @var bool
* @var array
*/
protected $_hasErrors = false;
protected $_errors = [];

/**
* List of invalid fields and their data for errors upon validation/patching
Expand Down Expand Up @@ -865,7 +865,7 @@ public function clean()
{
$this->_dirty = [];
$this->_errors = [];
$this->_hasErrors = false;
$this->_canBePersisted = true;
$this->_invalid = [];
$this->_original = [];
}
Expand Down Expand Up @@ -899,6 +899,16 @@ public function isNew($new = null)
return $this->_new = $new;
}

/**
* Returns whether this entity can be persisted.
*
* @return bool
*/
public function canBePersisted()
{
return $this->_canBePersisted;
}

/**
* Returns all validation errors.
*
Expand All @@ -919,16 +929,6 @@ public function getErrors()
->toArray();
}

/**
* Returns whether this entity contains errors.
*
* @return bool
*/
public function hasErrors()
{
return $this->_hasErrors;
}

/**
* Returns validation errors of a field
*
Expand Down Expand Up @@ -961,7 +961,7 @@ public function getError($field)
*/
public function setErrors(array $fields, $overwrite = false)
{
$this->_hasErrors = true;
$this->_canBePersisted = false;
if ($overwrite) {
foreach ($fields as $f => $error) {
$this->_errors[$f] = (array)$error;
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -1902,7 +1902,7 @@ public function save(EntityInterface $entity, $options = [])
'_primary' => true
]);

if ($entity->hasErrors() === true) {
if ($entity->canBePersisted() === false) {
return false;
}

Expand Down

0 comments on commit 4069319

Please sign in to comment.