Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
17 / 17 |
Contract | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
17 / 17 |
__construct(\aae\db\FunctionAPI $storageAPI) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getInfo($contractId, $requestorEmail) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
initiateContract($user) | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
reciprocateContract($user, $contractId, $plainCode) | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
|||
deleteInitiatedContract($user) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
/** | |
* | |
*/ | |
namespace aae\app { | |
/** | |
* @author Axel Ancona Esselmann | |
* @package aae\app | |
*/ | |
class Contract implements ContractInterface { | |
private $_storageAPI; | |
public function __construct(\aae\db\FunctionAPI $storageAPI) { | |
$this->_storageAPI = $storageAPI; | |
} | |
public function getInfo($contractId, $requestorEmail) { | |
return $this->_storageAPI->getInfo($contractId, $requestorEmail); | |
} | |
public function initiateContract($user) { | |
$plainCode = $user->getCode(20); | |
$codeHash = $user->createPWHash($plainCode); | |
$userEmail = $user->getEmail(); | |
$contractId = (int)$this->_storageAPI->initiateContract($userEmail, $codeHash); | |
return ["contractId" => $contractId, "plainCode" => $plainCode]; | |
} | |
public function reciprocateContract($user, $contractId, $plainCode) { | |
$userEmail = $user->getEmail(); | |
$codeHash = $this->_storageAPI->getInitiatedContractCode($contractId); | |
$validCode = $user->verifyPWHash($plainCode, $codeHash); | |
if ($validCode) { | |
$success = (bool)$this->_storageAPI->reciprocateContract($userEmail, $contractId, $plainCode); | |
if ($success > 0) return true; | |
} | |
return false; | |
} | |
public function deleteInitiatedContract($user) { | |
return (bool)$this->_storageAPI->deleteInitiatedContract($user->getEmail()); | |
} | |
} | |
} |