Repository: ProcessMaker/nayra (php)

Issue:
Change to TokenRepositoryInterface::createTokenInstance
Instead of ExecutionInstanceRepositoryInterface::createToken, we must use TokenRepositoryInterface::createTokenInstance

Pull request:
Change to TokenRepositoryInterface::createTokenInstance. Resolves #102

Patch:
diff --git a/src/ProcessMaker/Nayra/Bpmn/StateTrait.php b/src/ProcessMaker/Nayra/Bpmn/StateTrait.php
index 992ae88..3b57b88 100755
--- a/src/ProcessMaker/Nayra/Bpmn/StateTrait.php
+++ b/src/ProcessMaker/Nayra/Bpmn/StateTrait.php
@@ -86,7 +86,7 @@ trait StateTrait
      */
     public function addNewToken(ExecutionInstanceInterface $instance = null, array $properties = [])
     {
-        $token = $this->getRepository()->createExecutionInstanceRepository()->createToken();
+        $token = $this->getRepository()->getTokenRepository()->createTokenInstance();
         $token->setOwner($this);
         $token->setProperties($properties);
         $token->setOwner($this);
diff --git a/src/ProcessMaker/Nayra/Contracts/Repositories/ExecutionInstanceRepositoryInterface.php b/src/ProcessMaker/Nayra/Contracts/Repositories/ExecutionInstanceRepositoryInterface.php
index 65d146e..41e8bec 100644
--- a/src/ProcessMaker/Nayra/Contracts/Repositories/ExecutionInstanceRepositoryInterface.php
+++ b/src/ProcessMaker/Nayra/Contracts/Repositories/ExecutionInstanceRepositoryInterface.php
@@ -23,13 +23,6 @@ interface ExecutionInstanceRepositoryInterface
      */
     public function loadExecutionInstanceByUid($uid, StorageInterface $storage);
 
-    /**
-     * Creates an instance of Token.
-     *
-     * @return \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface
-     */
-    public function createToken();
-
     /**
      * Creates an execution instance.
      *
@@ -40,18 +33,18 @@ interface ExecutionInstanceRepositoryInterface
     /**
      * Persists instance's data related to the event Process Instance Created
      *
-     * @param $instance
+     * @param ExecutionInstanceInterface $instance
      *
      * @return mixed
      */
-    public function persistInstanceCreated($instance);
+    public function persistInstanceCreated(ExecutionInstanceInterface $instance);
 
     /**
      * Persists instance's data related to the event Process Instance Completed
      *
-     * @param $instance
+     * @param ExecutionInstanceInterface $instance
      *
      * @return mixed
      */
-    public function persistInstanceCompleted($instance);
+    public function persistInstanceCompleted(ExecutionInstanceInterface $instance);
 }


Test patch:
diff --git a/tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php b/tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php
index 6749ea1..06d0d91 100644
--- a/tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php
+++ b/tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php
@@ -2,8 +2,6 @@
 
 namespace ProcessMaker\Test\Models;
 
-use ProcessMaker\Nayra\Bpmn\Models\Token;
-use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
 use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
 use ProcessMaker\Nayra\Contracts\Repositories\ExecutionInstanceRepositoryInterface;
 use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface;
@@ -37,7 +35,7 @@ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterfac
             return;
         }
         $data = self::$data[$uid];
-        $instance = new ExecutionInstance();
+        $instance = $this->createExecutionInstance();
         $process = $storage->getProcess($data['processId']);
         $process->addInstance($instance);
         $dataStore = $storage->getFactory()->createDataStore();
@@ -48,7 +46,7 @@ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterfac
 
         //Load tokens:
         foreach($data['tokens'] as $tokenInfo) {
-            $token = $this->createToken();
+            $token = $storage->getFactory()->getTokenRepository()->createTokenInstance();
             $token->setProperties($tokenInfo);
             $element = $storage->getElementInstanceById($tokenInfo['elementId']);
             $element->addToken($instance, $token);
@@ -66,16 +64,6 @@ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterfac
         self::$data = $data;
     }
 
-    /**
-     * Creates an instance of Token.
-     *
-     * @return \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface
-     */
-    public function createToken()
-    {
-        return new Token();
-    }
-
     /**
      * Creates an execution instance.
      *
@@ -89,11 +77,11 @@ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterfac
     /**
      * Persists instance's data related to the event Process Instance Created
      *
-     * @param $instance
+     * @param ExecutionInstanceInterface $instance
      *
      * @return mixed
      */
-    public function persistInstanceCreated($instance)
+    public function persistInstanceCreated(ExecutionInstanceInterface $instance)
     {
 
     }
@@ -101,11 +89,11 @@ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterfac
     /**
      * Persists instance's data related to the event Process Instance Completed
      *
-     * @param $instance
+     * @param ExecutionInstanceInterface $instance
      *
      * @return mixed
      */
-    public function persistInstanceCompleted($instance)
+    public function persistInstanceCompleted(ExecutionInstanceInterface $instance)
     {
     }
 }
diff --git a/tests/ProcessMaker/Test/Models/TokenRepository.php b/tests/ProcessMaker/Test/Models/TokenRepository.php
index 21b78d9..05f3e9a 100755
--- a/tests/ProcessMaker/Test/Models/TokenRepository.php
+++ b/tests/ProcessMaker/Test/Models/TokenRepository.php
@@ -2,6 +2,7 @@
 
 namespace ProcessMaker\Test\Models;
 
+use ProcessMaker\Nayra\Bpmn\Models\Token;
 use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface;
@@ -106,11 +107,20 @@ class TokenRepository implements TokenRepositoryInterface
         
     }
 
+    /**
+     * Get persist calls
+     *
+     * @return int
+     */
     public function getPersistCalls()
     {
         return $this->persistCalls;
     }
 
+    /**
+     * Reset persist calls
+     *
+     */
     public function resetPersistCalls()
     {
         $this->persistCalls = 0;