/**
  * @param \Elastica\Document $document
  * @param string $opType
  * @return \Elastica\Bulk\Action\AbstractDocument
  */
 public static function create(Document $document, $opType = null)
 {
     if (null === $opType && $document->hasOpType()) {
         $opType = $document->getOpType();
     }
     switch ($opType) {
         case self::OP_TYPE_DELETE:
             $action = new DeleteDocument($document);
             break;
         case self::OP_TYPE_CREATE:
             $action = new CreateDocument($document);
             break;
         case self::OP_TYPE_UPDATE:
             $action = new UpdateDocument($document);
             break;
         case self::OP_TYPE_INDEX:
         default:
             $action = new IndexDocument($document);
             break;
     }
     return $action;
 }
 /**
  * @param \Elastica\Document|\Elastica\Script\AbstractScript $data
  * @param string                                             $opType
  *
  * @return static
  */
 public static function create($data, $opType = null)
 {
     //Check type
     if (!$data instanceof Document && !$data instanceof AbstractScript) {
         throw new \InvalidArgumentException('The data needs to be a Document or a Script.');
     }
     if (null === $opType && $data->hasOpType()) {
         $opType = $data->getOpType();
     }
     //Check that scripts can only be used for updates
     if ($data instanceof AbstractScript) {
         if ($opType === null) {
             $opType = self::OP_TYPE_UPDATE;
         } elseif ($opType != self::OP_TYPE_UPDATE) {
             throw new \InvalidArgumentException('Scripts can only be used with the update operation type.');
         }
     }
     switch ($opType) {
         case self::OP_TYPE_DELETE:
             $action = new DeleteDocument($data);
             break;
         case self::OP_TYPE_CREATE:
             $action = new CreateDocument($data);
             break;
         case self::OP_TYPE_UPDATE:
             $action = new UpdateDocument($data);
             break;
         case self::OP_TYPE_INDEX:
         default:
             $action = new IndexDocument($data);
             break;
     }
     return $action;
 }
 /**
  * @param \Elastica\Document|\Elastica\Script $data
  * @param string $opType
  * @return \Elastica\Bulk\Action\AbstractDocument
  */
 public static function create($data, $opType = null)
 {
     //Check type
     if (!$data instanceof Document && !$data instanceof Script) {
         throw new \InvalidArgumentException("The data needs to be a Document or a Script.");
     }
     if (null === $opType && $data->hasOpType()) {
         $opType = $data->getOpType();
     }
     //Check that scripts can only be used for updates
     if ($data instanceof Script && isset($opType) && $opType != self::OP_TYPE_UPDATE) {
         throw new \InvalidArgumentException("When performing an update action, the data needs to be a Document or a Script.");
     }
     switch ($opType) {
         case self::OP_TYPE_DELETE:
             $action = new DeleteDocument($data);
             break;
         case self::OP_TYPE_CREATE:
             $action = new CreateDocument($data);
             break;
         case self::OP_TYPE_UPDATE:
             $action = new UpdateDocument($data);
             break;
         case self::OP_TYPE_INDEX:
         default:
             $action = new IndexDocument($data);
             break;
     }
     return $action;
 }