original_string: public function setErrors(array $fields, $overwrite = false)
      {
          if ($overwrite) {
              foreach ($fields as $f => $error) {
                  $this->_errors[$f] = (array)$error;
              }
  
              return $this;
          }
  
          foreach ($fields as $f => $error) {
              $this->_errors += [$f => []];
  
              // String messages are appended to the list,
              // while more complex error structures need their
              // keys preserved for nested validator.
              if (is_string($error)) {
                  $this->_errors[$f][] = $error;
              } else {
                  foreach ($error as $k => $v) {
                      $this->_errors[$f][$k] = $v;
                  }
              }
          }
  
          return $this;
      }
code: public function setErrors(array $fields, $overwrite = false)
      {
          if ($overwrite) {
              foreach ($fields as $f => $error) {
                  $this->_errors[$f] = (array)$error;
              }
  
              return $this;
          }
  
          foreach ($fields as $f => $error) {
              $this->_errors += [$f => []];
  
              // String messages are appended to the list,
              // while more complex error structures need their
              // keys preserved for nested validator.
              if (is_string($error)) {
                  $this->_errors[$f][] = $error;
              } else {
                  foreach ($error as $k => $v) {
                      $this->_errors[$f][$k] = $v;
                  }
              }
          }
  
          return $this;
      }
code_tokens: public function setErrors ( array $ fields , $ overwrite = false ) { if ( $ overwrite ) { foreach ( $ fields as $ f => $ error ) { $ this -> _errors [ $ f ] = ( array ) $ error ; } return $ this ; } foreach ( $ fields as $ f => $ error ) { $ this -> _errors += [ $ f => [ ] ] ; // String messages are appended to the list, // while more complex error structures need their // keys preserved for nested validator. if ( is_string ( $ error ) ) { $ this -> _errors [ $ f ] [ ] = $ error ; } else { foreach ( $ error as $ k => $ v ) { $ this -> _errors [ $ f ] [ $ k ] = $ v ; } } } return $ this ; }
docstring: Sets error messages to the entity
  
  ## Example
  
  ```
  // Sets the error messages for multiple fields at once
  $entity->setErrors(['salary' => ['message'], 'name' => ['another message']]);
  ```
  
  @param array $fields The array of errors to set.
  @param bool $overwrite Whether or not to overwrite pre-existing errors for $fields
  @return $this
docstring_tokens: Sets error messages to the entity