/**
  * Creates a StatementOfAccount model from array.
  *
  * @param array $array
  * @return StatementOfAccount|null
  */
 public static function createModelFromArray(array $array)
 {
     if (empty($array)) {
         return null;
     }
     $soa = new StatementOfAccount();
     foreach ($array as $date => $statement) {
         $statementModel = new Statement();
         $statementModel->setDate(new \DateTime($date));
         $statementModel->setStartBalance((double) $statement['start_balance']['amount']);
         $statementModel->setCreditDebit($statement['start_balance']['credit_debit']);
         if (isset($statement['transactions'])) {
             foreach ($statement['transactions'] as $trx) {
                 $transaction = new Transaction();
                 $transaction->setBookingDate(new \DateTime($trx['booking_date']));
                 $transaction->setValutaDate(new \DateTime($trx['valuta_date']));
                 $transaction->setCreditDebit($trx['credit_debit']);
                 $transaction->setAmount($trx['amount']);
                 $transaction->setBookingText($trx['description']['booking_text']);
                 $transaction->setDescription1($trx['description']['description_1']);
                 $transaction->setDescription2($trx['description']['description_2']);
                 $transaction->setBankCode($trx['description']['bank_code']);
                 $transaction->setAccountNumber($trx['description']['account_number']);
                 $transaction->setName($trx['description']['name']);
                 $statementModel->addTransaction($transaction);
             }
         }
         $soa->addStatement($statementModel);
     }
     return $soa;
 }
 public function test_getter_and_setter()
 {
     $obj = new StatementOfAccount();
     $this->assertInternalType('array', $obj->getStatements());
     $s1 = new Statement();
     $s2 = new Statement();
     $obj->addStatement($s1);
     $this->assertInternalType('array', $obj->getStatements());
     $this->assertCount(1, $obj->getStatements());
     $result = $obj->getStatements();
     $this->assertSame($s1, $result[0]);
     $obj->setStatements(null);
     $this->assertInternalType('array', $obj->getStatements());
     $this->assertEmpty($obj->getStatements());
     $obj->setStatements(array($s1, $s2));
     $this->assertInternalType('array', $obj->getStatements());
     $this->assertCount(2, $obj->getStatements());
     $this->assertSame(array($s1, $s2), $obj->getStatements());
 }