@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
| 9 | - throw new Exception('The TopMcApi requires PHP version 5.4 or higher.'); |
|
| 9 | + throw new Exception('The TopMcApi requires PHP version 5.4 or higher.'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -18,29 +18,29 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | spl_autoload_register(function ($class) |
| 20 | 20 | { |
| 21 | - // project-specific namespace prefix |
|
| 22 | - $prefix = 'TopMcFrance\\\Api\\'; |
|
| 21 | + // project-specific namespace prefix |
|
| 22 | + $prefix = 'TopMcFrance\\\Api\\'; |
|
| 23 | 23 | |
| 24 | - // base directory for the namespace prefix |
|
| 25 | - $base_dir = __DIR__ . '/src/'; |
|
| 24 | + // base directory for the namespace prefix |
|
| 25 | + $base_dir = __DIR__ . '/src/'; |
|
| 26 | 26 | |
| 27 | - // does the class use the namespace prefix? |
|
| 28 | - $len = strlen($prefix); |
|
| 29 | - if (strncmp($prefix, $class, $len) !== 0) { |
|
| 27 | + // does the class use the namespace prefix? |
|
| 28 | + $len = strlen($prefix); |
|
| 29 | + if (strncmp($prefix, $class, $len) !== 0) { |
|
| 30 | 30 | // no, move to the next registered autoloader |
| 31 | 31 | return; |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - // get the relative class name |
|
| 35 | - $relative_class = substr($class, $len); |
|
| 34 | + // get the relative class name |
|
| 35 | + $relative_class = substr($class, $len); |
|
| 36 | 36 | |
| 37 | - // replace the namespace prefix with the base directory, replace namespace |
|
| 38 | - // separators with directory separators in the relative class name, append |
|
| 39 | - // with .php |
|
| 40 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
| 37 | + // replace the namespace prefix with the base directory, replace namespace |
|
| 38 | + // separators with directory separators in the relative class name, append |
|
| 39 | + // with .php |
|
| 40 | + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
| 41 | 41 | |
| 42 | - // if the file exists, require it |
|
| 43 | - if (file_exists($file)) { |
|
| 42 | + // if the file exists, require it |
|
| 43 | + if (file_exists($file)) { |
|
| 44 | 44 | require $file; |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | }); |
| 47 | 47 | \ No newline at end of file |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @param string $class The fully-qualified class name. |
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | -spl_autoload_register(function ($class) |
|
| 19 | +spl_autoload_register(function($class) |
|
| 20 | 20 | { |
| 21 | 21 | // project-specific namespace prefix |
| 22 | 22 | $prefix = 'TopMcFrance\\\Api\\'; |
| 23 | 23 | |
| 24 | 24 | // base directory for the namespace prefix |
| 25 | - $base_dir = __DIR__ . '/src/'; |
|
| 25 | + $base_dir = __DIR__.'/src/'; |
|
| 26 | 26 | |
| 27 | 27 | // does the class use the namespace prefix? |
| 28 | 28 | $len = strlen($prefix); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | // replace the namespace prefix with the base directory, replace namespace |
| 38 | 38 | // separators with directory separators in the relative class name, append |
| 39 | 39 | // with .php |
| 40 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
| 40 | + $file = $base_dir.str_replace('\\', '/', $relative_class).'.php'; |
|
| 41 | 41 | |
| 42 | 42 | // if the file exists, require it |
| 43 | 43 | if (file_exists($file)) { |
@@ -36,20 +36,20 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function checkCode($code){ |
| 38 | 38 | |
| 39 | - $response = $this->getResponse($code); |
|
| 39 | + $response = $this->getResponse($code); |
|
| 40 | 40 | |
| 41 | - if($response->etat === true){ |
|
| 42 | - return true; |
|
| 43 | - } else { |
|
| 44 | - switch ($response->etat){ |
|
| 45 | - case '1' : |
|
| 41 | + if($response->etat === true){ |
|
| 42 | + return true; |
|
| 43 | + } else { |
|
| 44 | + switch ($response->etat){ |
|
| 45 | + case '1' : |
|
| 46 | 46 | throw ApiException::alreadyUsed($code, $response); |
| 47 | - case '2' : |
|
| 47 | + case '2' : |
|
| 48 | 48 | throw ApiException::invalidCode($code, $response); |
| 49 | - default: |
|
| 49 | + default: |
|
| 50 | 50 | throw ApiException::unknowException($code, $response); |
| 51 | - } |
|
| 52 | - } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $result = file_get_contents($this->buildURI($code)); |
| 72 | 72 | |
| 73 | 73 | if($result === false){ |
| 74 | - throw new \Exception("Impossible to accès to TopMcFrance"); |
|
| 74 | + throw new \Exception("Impossible to accès to TopMcFrance"); |
|
| 75 | 75 | } |
| 76 | 76 | return json_decode($result); |
| 77 | 77 | } |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * @return boolean |
| 35 | 35 | * @throws type |
| 36 | 36 | */ |
| 37 | - public function checkCode($code){ |
|
| 37 | + public function checkCode($code) { |
|
| 38 | 38 | |
| 39 | 39 | $response = $this->getResponse($code); |
| 40 | 40 | |
| 41 | - if($response->etat === true){ |
|
| 41 | + if ($response->etat === true) { |
|
| 42 | 42 | return true; |
| 43 | 43 | } else { |
| 44 | - switch ($response->etat){ |
|
| 44 | + switch ($response->etat) { |
|
| 45 | 45 | case '1' : |
| 46 | 46 | throw ApiException::alreadyUsed($code, $response); |
| 47 | 47 | case '2' : |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param string $code |
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | - public function buildURI($code){ |
|
| 60 | + public function buildURI($code) { |
|
| 61 | 61 | return self::HOST_API.'?id_serv='.$this->serverId.'&code='.$code; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * @param string $code |
| 67 | 67 | * @return string |
| 68 | 68 | */ |
| 69 | - protected function getResponse($code){ |
|
| 69 | + protected function getResponse($code) { |
|
| 70 | 70 | |
| 71 | 71 | $result = file_get_contents($this->buildURI($code)); |
| 72 | 72 | |
| 73 | - if($result === false){ |
|
| 73 | + if ($result === false) { |
|
| 74 | 74 | throw new \Exception("Impossible to accès to TopMcFrance"); |
| 75 | 75 | } |
| 76 | 76 | return json_decode($result); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param mixed $response |
| 49 | 49 | * @return \self |
| 50 | 50 | */ |
| 51 | - public static function alreadyUsed($code, $response){ |
|
| 51 | + public static function alreadyUsed($code, $response) { |
|
| 52 | 52 | $exception = new self(sprintf('Code %s has already used at %s.', |
| 53 | 53 | $code, |
| 54 | 54 | $response->use_date |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param mixed $response |
| 67 | 67 | * @return \self |
| 68 | 68 | */ |
| 69 | - public static function invalidCode($code, $response){ |
|
| 69 | + public static function invalidCode($code, $response) { |
|
| 70 | 70 | $exception = new self(sprintf('Code %s isn\'t valid.', |
| 71 | 71 | $code |
| 72 | 72 | )); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param mixed $response |
| 82 | 82 | * @return \self |
| 83 | 83 | */ |
| 84 | - public static function unknowException($message, $response){ |
|
| 84 | + public static function unknowException($message, $response) { |
|
| 85 | 85 | $exception = new self(sprintf('Unknow code error : %s.', |
| 86 | 86 | $message |
| 87 | 87 | )); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | return $exception; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - private function baseException($response){ |
|
| 94 | + private function baseException($response) { |
|
| 95 | 95 | $this->apiCodeError = $response->erreur; |
| 96 | 96 | $this->apiMessage = $response->detail; |
| 97 | 97 | } |