original_string: public function createObject($meta, $mapped, $args=null)
      {
          if (!$meta instanceof Meta) {
              $meta = $this->getMeta($meta);
          }
  
          $object = null;
          $args = $args ? array_values($args) : [];
          $argc = $args ? count($args) : 0;
  
          if ($meta->constructorArgs) {
              $actualArgs = [];
              foreach ($meta->constructorArgs as $argInfo) {
                  $type = $argInfo[0];
                  $id   = isset($argInfo[1]) ? $argInfo[1] : null;
  
                  switch ($type) {
                  case 'property':
                      $actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
                      unset($mapped->{$id});
                  break;
  
                  case 'arg':
                      if ($id >= $argc) {
                          throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
                      }
                      $actualArgs[] = $args[$id];
                  break;
  
                  case 'all': $actualArgs[] = $mapped; break;
  
                  // NO! leaky abstraction.
                  // case 'meta': $actualArgs[] = $meta; break;
  
                  default:
                      throw new Exception("Invalid constructor argument type {$type}");
                  }
              }
              $args = $actualArgs;
          }
  
          if ($meta->constructor == '__construct') {
              if ($args) {
                  $rc = new \ReflectionClass($meta->class);
                  $object = $rc->newInstanceArgs($args);
              }
              else {
                  $cname = $meta->class;
                  $object = new $cname;
              }
          }
          else {
              $rc = new \ReflectionClass($meta->class);
              $method = $rc->getMethod($meta->constructor);
              $object = $method->invokeArgs(null, $args ?: []);
          }
  
          if (!$object instanceof $meta->class) {
              throw new Exception(
                  "Constructor {$meta->constructor} did not return instance of {$meta->class}"
              );
          }
  
          return $object;
      }
code: public function createObject($meta, $mapped, $args=null)
      {
          if (!$meta instanceof Meta) {
              $meta = $this->getMeta($meta);
          }
  
          $object = null;
          $args = $args ? array_values($args) : [];
          $argc = $args ? count($args) : 0;
  
          if ($meta->constructorArgs) {
              $actualArgs = [];
              foreach ($meta->constructorArgs as $argInfo) {
                  $type = $argInfo[0];
                  $id   = isset($argInfo[1]) ? $argInfo[1] : null;
  
                  switch ($type) {
                  case 'property':
                      $actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
                      unset($mapped->{$id});
                  break;
  
                  case 'arg':
                      if ($id >= $argc) {
                          throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
                      }
                      $actualArgs[] = $args[$id];
                  break;
  
                  case 'all': $actualArgs[] = $mapped; break;
  
                  // NO! leaky abstraction.
                  // case 'meta': $actualArgs[] = $meta; break;
  
                  default:
                      throw new Exception("Invalid constructor argument type {$type}");
                  }
              }
              $args = $actualArgs;
          }
  
          if ($meta->constructor == '__construct') {
              if ($args) {
                  $rc = new \ReflectionClass($meta->class);
                  $object = $rc->newInstanceArgs($args);
              }
              else {
                  $cname = $meta->class;
                  $object = new $cname;
              }
          }
          else {
              $rc = new \ReflectionClass($meta->class);
              $method = $rc->getMethod($meta->constructor);
              $object = $method->invokeArgs(null, $args ?: []);
          }
  
          if (!$object instanceof $meta->class) {
              throw new Exception(
                  "Constructor {$meta->constructor} did not return instance of {$meta->class}"
              );
          }
  
          return $object;
      }
code_tokens: public function createObject ( $ meta , $ mapped , $ args = null ) { if ( ! $ meta instanceof Meta ) { $ meta = $ this -> getMeta ( $ meta ) ; } $ object = null ; $ args = $ args ? array_values ( $ args ) : [ ] ; $ argc = $ args ? count ( $ args ) : 0 ; if ( $ meta -> constructorArgs ) { $ actualArgs = [ ] ; foreach ( $ meta -> constructorArgs as $ argInfo ) { $ type = $ argInfo [ 0 ] ; $ id = isset ( $ argInfo [ 1 ] ) ? $ argInfo [ 1 ] : null ; switch ( $ type ) { case 'property' : $ actualArgs [ ] = isset ( $ mapped -> { $ id } ) ? $ mapped -> { $ id } : null ; unset ( $ mapped -> { $ id } ) ; break ; case 'arg' : if ( $ id >= $ argc ) { throw new Exception ( "Class {$meta->class} requires argument at index $id - please use Select->\$args" ) ; } $ actualArgs [ ] = $ args [ $ id ] ; break ; case 'all' : $ actualArgs [ ] = $ mapped ; break ; // NO! leaky abstraction. // case 'meta': $actualArgs[] = $meta; break; default : throw new Exception ( "Invalid constructor argument type {$type}" ) ; } } $ args = $ actualArgs ; } if ( $ meta -> constructor == '__construct' ) { if ( $ args ) { $ rc = new \ ReflectionClass ( $ meta -> class ) ; $ object = $ rc -> newInstanceArgs ( $ args ) ; } else { $ cname = $ meta -> class ; $ object = new $ cname ; } } else { $ rc = new \ ReflectionClass ( $ meta -> class ) ; $ method = $ rc -> getMethod ( $ meta -> constructor ) ; $ object = $ method -> invokeArgs ( null , $ args ? : [ ] ) ; } if ( ! $ object instanceof $ meta -> class ) { throw new Exception ( "Constructor {$meta->constructor} did not return instance of {$meta->class}" ) ; } return $ object ; }
docstring: The row is made available to this function, but this is so it can be
  used to construct the object, not to populate it. Feel free to ignore it,
  it will be passed to populateObject as well.
  
  @param $meta \Amiss\Meta  The metadata to use to create the object
  @param array $mapped      Input values after mapping to property names and type handling
  @param array $args        Class constructor arguments
  @return void
docstring_tokens: The row is made available to this function but this is so it can be used to construct the object not to populate it . Feel free to ignore it it will be passed to populateObject as well .