original_string: public static function apply($object, array $values)
      {
          foreach ($values as $property => $value) {
              // Check if the value is a map (associative array) by checking for
              // a zero index.
              if (is_array($value) and ! isset($value[0])) {
                  $method = "get".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      //$object->{$method}()->apply( $value );
                      static::apply($object->{$method}(), $value);
                  }
              } elseif (is_array($value) and isset($value[0])) {
                  // Check if the value is a collection, i.e. an indexed array. If this
                  // is the case then the $value is an interable array. If the object
                  // has an "add" method for the property then we call this x times.
                  $method = "add".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      foreach ($value as $arguments) {
                          if (! is_array($arguments)) {
                              $arguments = array( $arguments );
                          }
  
                          call_user_func_array(array( $object, $method ), $arguments);
                      }
                  }
              } else {
                  // Check if the value has a corresponding setter method
                  // on the object.
                  $method = "set".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      $object->{$method}($value);
                  }
              }
          }
      }
code: public static function apply($object, array $values)
      {
          foreach ($values as $property => $value) {
              // Check if the value is a map (associative array) by checking for
              // a zero index.
              if (is_array($value) and ! isset($value[0])) {
                  $method = "get".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      //$object->{$method}()->apply( $value );
                      static::apply($object->{$method}(), $value);
                  }
              } elseif (is_array($value) and isset($value[0])) {
                  // Check if the value is a collection, i.e. an indexed array. If this
                  // is the case then the $value is an interable array. If the object
                  // has an "add" method for the property then we call this x times.
                  $method = "add".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      foreach ($value as $arguments) {
                          if (! is_array($arguments)) {
                              $arguments = array( $arguments );
                          }
  
                          call_user_func_array(array( $object, $method ), $arguments);
                      }
                  }
              } else {
                  // Check if the value has a corresponding setter method
                  // on the object.
                  $method = "set".ucfirst($property);
  
                  if (method_exists($object, $method)) {
                      $object->{$method}($value);
                  }
              }
          }
      }
code_tokens: public static function apply ( $ object , array $ values ) { foreach ( $ values as $ property => $ value ) { // Check if the value is a map (associative array) by checking for // a zero index. if ( is_array ( $ value ) and ! isset ( $ value [ 0 ] ) ) { $ method = "get" . ucfirst ( $ property ) ; if ( method_exists ( $ object , $ method ) ) { //$object->{$method}()->apply( $value ); static :: apply ( $ object -> { $ method } ( ) , $ value ) ; } } elseif ( is_array ( $ value ) and isset ( $ value [ 0 ] ) ) { // Check if the value is a collection, i.e. an indexed array. If this // is the case then the $value is an interable array. If the object // has an "add" method for the property then we call this x times. $ method = "add" . ucfirst ( $ property ) ; if ( method_exists ( $ object , $ method ) ) { foreach ( $ value as $ arguments ) { if ( ! is_array ( $ arguments ) ) { $ arguments = array ( $ arguments ) ; } call_user_func_array ( array ( $ object , $ method ) , $ arguments ) ; } } } else { // Check if the value has a corresponding setter method // on the object. $ method = "set" . ucfirst ( $ property ) ; if ( method_exists ( $ object , $ method ) ) { $ object -> { $ method } ( $ value ) ; } } } }
docstring: This method applies a given set of values to a given object.
  
  The array with values supplied must be actual values of the
  object and must be exposed through a corresponding setter method.
  E.g. if you wish to set the value on a property called 'firstname'
  then the object needs to have a 'setFirstname' setter method. If
  the setter is not available the property will not be set and the
  corresponding value will not be applied.
  
  @param object $object
  @param array  $values
docstring_tokens: This method applies a given set of values to a given object .