Fix Codacy "Code Style" Pattern

This commit is contained in:
Sebastian Meyer 2017-10-15 18:05:50 +02:00
parent aa9748799a
commit e94e5e044c
1 changed files with 32 additions and 36 deletions

View File

@ -38,12 +38,12 @@ class OAI2Server {
private $token_valid = 86400; private $token_valid = 86400;
public function __construct($uri, $args, $identifyResponse, $callbacks, $config) { public function __construct($uri, $args, $identifyResponse, $callbacks, $config) {
$this->uri = $uri;
if (!isset($args['verb']) || empty($args['verb'])) {
$this->errors[] = new OAI2Exception('badVerb');
} else {
$verbs = array('Identify', 'ListMetadataFormats', 'ListSets', 'ListIdentifiers', 'ListRecords', 'GetRecord'); $verbs = array('Identify', 'ListMetadataFormats', 'ListSets', 'ListIdentifiers', 'ListRecords', 'GetRecord');
if (in_array($args['verb'], $verbs)) { if (empty($args['verb']) || !in_array($args['verb'], $verbs)) {
$this->errors[] = new OAI2Exception('badVerb');
return;
}
$this->uri = $uri;
$this->verb = $args['verb']; $this->verb = $args['verb'];
unset($args['verb']); unset($args['verb']);
$this->args = $args; $this->args = $args;
@ -57,10 +57,6 @@ class OAI2Server {
$this->token_valid = $config['tokenValid']; $this->token_valid = $config['tokenValid'];
$this->response = new OAI2XMLResponse($this->uri, $this->verb, $this->args); $this->response = new OAI2XMLResponse($this->uri, $this->verb, $this->args);
call_user_func(array($this, $this->verb)); call_user_func(array($this, $this->verb));
} else {
$this->errors[] = new OAI2Exception('badVerb');
}
}
} }
public function response() { public function response() {
@ -249,8 +245,8 @@ class OAI2Server {
private function createResumptionToken($delivered_records) { private function createResumptionToken($delivered_records) {
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
$token = ((int)($usec*1000) + (int)($sec*1000)); $token = ((int)($usec*1000) + (int)($sec*1000));
$fp = fopen ($this->token_prefix.$token, 'w'); $file = fopen ($this->token_prefix.$token, 'w');
if($fp == false) { if($file == false) {
exit('Cannot write resumption token. Writing permission needs to be changed.'); exit('Cannot write resumption token. Writing permission needs to be changed.');
} }
$values = array( $values = array(
@ -259,21 +255,21 @@ class OAI2Server {
'from' => isset($this->args['from']) ? $this->args['from'] : '', 'from' => isset($this->args['from']) ? $this->args['from'] : '',
'until' => isset($this->args['until']) ? $this->args['until'] : '' 'until' => isset($this->args['until']) ? $this->args['until'] : ''
); );
fputs($fp, $values['deliveredRecords'].'#'); fputs($file, $values['deliveredRecords'].'#');
fputs($fp, $values['metadataPrefix'].'#'); fputs($file, $values['metadataPrefix'].'#');
fputs($fp, $values['from'].'#'); fputs($file, $values['from'].'#');
fputs($fp, $values['until'].'#'); fputs($file, $values['until'].'#');
fclose($fp); fclose($file);
return $token; return $token;
} }
private function readResumptionToken($resumptionToken) { private function readResumptionToken($resumptionToken) {
$rtVal = false; $rtVal = false;
$fp = fopen($resumptionToken, 'r'); $file = fopen($resumptionToken, 'r');
if ($fp != false) { if ($file != false) {
$filetext = fgets($fp, 255); $filetext = fgets($file, 255);
$textparts = explode('#', $filetext); $textparts = explode('#', $filetext);
fclose($fp); fclose($file);
unlink($resumptionToken); unlink($resumptionToken);
$rtVal = array_values($textparts); $rtVal = array_values($textparts);
} }
@ -293,11 +289,11 @@ class OAI2Server {
} }
private function checkDateFormat($date) { private function checkDateFormat($date) {
$dt = DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $date); $datetime = DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $date);
if ($dt === false) { if ($datetime === false) {
$dt = DateTime::createFromFormat('Y-m-d', $date); $datetime = DateTime::createFromFormat('Y-m-d', $date);
} }
return ($dt !== false) && !array_sum($dt->getLastErrors()); return ($datetime !== false) && !array_sum($dt->getLastErrors());
} }
} }