code: private function resolveClassAndCreateObject($type, $subject)
      {
          foreach ($this->classes[$type] as $source => $target) {
              if ($subject instanceof $source) {
                  return new $target;
              }
          }
  
          throw new InvalidArgumentException('Unsupported object class.');
      }
docs: Resolves the class and creates the expected object.
  
  @param string $type
  @param object $subject
  
  @return object