@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | public static function create(Connector $connector, string $model, array $data = []): Model |
| 22 | 22 | { |
| 23 | 23 | $model = strtolower($model); |
| 24 | - if (!array_key_exists($model, ClassMap::MODELS)) return new LifeboatModel($connector, $data); |
|
| 24 | + if (!array_key_exists($model, ClassMap::MODELS)) { |
|
| 25 | + return new LifeboatModel($connector, $data); |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | $cls = ClassMap::MODELS[$model]; |
| 27 | 29 | return new $cls($connector, $data); |
@@ -35,7 +37,9 @@ discard block |
||
| 35 | 37 | public static function make(Connector $connector, array $data): Model |
| 36 | 38 | { |
| 37 | 39 | $model = $data['model'] ?? ''; |
| 38 | - if (!$model) return new LifeboatModel($connector, $data); |
|
| 40 | + if (!$model) { |
|
| 41 | + return new LifeboatModel($connector, $data); |
|
| 42 | + } |
|
| 39 | 43 | return self::create($connector, $model, $data); |
| 40 | 44 | } |
| 41 | 45 | } |
@@ -212,20 +212,20 @@ |
||
| 212 | 212 | $t = $this->getItems(1); |
| 213 | 213 | $c = $this->count(); |
| 214 | 214 | |
| 215 | - return (function () use ($t, $c) { |
|
| 215 | + return (function() use ($t, $c) { |
|
| 216 | 216 | $i = 0; |
| 217 | 217 | $x = 0; |
| 218 | 218 | |
| 219 | 219 | while ($i < $c) { |
| 220 | 220 | if ($x === 0) { |
| 221 | 221 | $x = $this->_page_length; |
| 222 | - $t = $this->getItems((int) floor($i / $this->_page_length) + 1); |
|
| 222 | + $t = $this->getItems((int) floor($i / $this->_page_length)+1); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - yield $i => $t[$this->_page_length - $x]; |
|
| 225 | + yield $i => $t[$this->_page_length-$x]; |
|
| 226 | 226 | |
| 227 | 227 | $x -= 1; |
| 228 | - $i ++; |
|
| 228 | + $i++; |
|
| 229 | 229 | } |
| 230 | 230 | })(); |
| 231 | 231 | } |
@@ -129,16 +129,22 @@ discard block |
||
| 129 | 129 | $response = $this->getClient()->curl_api($this->getURL(), 'GET', $data); |
| 130 | 130 | $data = ($response->isValid() && $response->isJSON()) ? $response->getJSON() : []; |
| 131 | 131 | |
| 132 | - if (empty($data)) throw new ApiException($response->getError()); |
|
| 132 | + if (empty($data)) { |
|
| 133 | + throw new ApiException($response->getError()); |
|
| 134 | + } |
|
| 133 | 135 | |
| 134 | 136 | $this->_max_items = (int) $data['available_items']; |
| 135 | 137 | |
| 136 | - if (empty($data['items'])) return $this->_items[$page] = []; |
|
| 138 | + if (empty($data['items'])) { |
|
| 139 | + return $this->_items[$page] = []; |
|
| 140 | + } |
|
| 137 | 141 | |
| 138 | 142 | |
| 139 | 143 | foreach ($data['items'] as $item) { |
| 140 | 144 | $obj = ObjectFactory::make($this->getClient(), $item); |
| 141 | - if (!$obj) continue; |
|
| 145 | + if (!$obj) { |
|
| 146 | + continue; |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | 149 | $this->_items[$page][] = $obj; |
| 144 | 150 | } |
@@ -153,7 +159,9 @@ discard block |
||
| 153 | 159 | */ |
| 154 | 160 | public function offsetGet($offset): ?ObjectResource |
| 155 | 161 | { |
| 156 | - foreach ($this as $i => $obj) if ($i === $offset) return $obj; |
|
| 162 | + foreach ($this as $i => $obj) { |
|
| 163 | + if ($i === $offset) return $obj; |
|
| 164 | + } |
|
| 157 | 165 | return null; |
| 158 | 166 | } |
| 159 | 167 | |
@@ -184,7 +192,9 @@ discard block |
||
| 184 | 192 | */ |
| 185 | 193 | public function offsetExists($offset): bool |
| 186 | 194 | { |
| 187 | - foreach ($this as $i => $obj) if ($offset === $i) return true; |
|
| 195 | + foreach ($this as $i => $obj) { |
|
| 196 | + if ($offset === $i) return true; |
|
| 197 | + } |
|
| 188 | 198 | return false; |
| 189 | 199 | } |
| 190 | 200 | |
@@ -240,6 +250,8 @@ discard block |
||
| 240 | 250 | */ |
| 241 | 251 | public function first(): ?Model |
| 242 | 252 | { |
| 243 | - foreach ($this as $obj) return $obj; |
|
| 253 | + foreach ($this as $obj) { |
|
| 254 | + return $obj; |
|
| 255 | + } |
|
| 244 | 256 | } |
| 245 | 257 | } |
@@ -54,10 +54,10 @@ |
||
| 54 | 54 | { |
| 55 | 55 | $app = new App('id', 'secret', 'http://test.domain'); |
| 56 | 56 | $url = $app->getAuthURL('process.php', 'error.php', 'challenge'); |
| 57 | - $expect = 'http://test.domain/oauth/code?app_id=id&process_url=' . |
|
| 58 | - urlencode('process.php') . |
|
| 59 | - '&error_url=' . urlencode('error.php') . |
|
| 60 | - '&challenge=' . Utils::pack('challenge'); |
|
| 57 | + $expect = 'http://test.domain/oauth/code?app_id=id&process_url='. |
|
| 58 | + urlencode('process.php'). |
|
| 59 | + '&error_url='.urlencode('error.php'). |
|
| 60 | + '&challenge='.Utils::pack('challenge'); |
|
| 61 | 61 | |
| 62 | 62 | $this->assertEquals($expect, $url); |
| 63 | 63 | } |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | if (!$date) return null; |
| 10 | 10 | |
| 11 | 11 | try { |
| 12 | - $date = new \DateTime($date . ' CET'); |
|
| 12 | + $date = new \DateTime($date.' CET'); |
|
| 13 | 13 | return $date; |
| 14 | 14 | } catch (Exception $e) { |
| 15 | 15 | return null; |
@@ -6,7 +6,9 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | function lifeboat_date_formatter(string $date): ?DateTime |
| 8 | 8 | { |
| 9 | - if (!$date) return null; |
|
| 9 | + if (!$date) { |
|
| 10 | + return null; |
|
| 11 | + } |
|
| 10 | 12 | |
| 11 | 13 | try { |
| 12 | 14 | $date = new \DateTime($date . ' CET'); |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function testFactory() |
| 21 | 21 | { |
| 22 | - $mock_data = ['ID' => 0]; |
|
| 22 | + $mock_data = ['ID' => 0]; |
|
| 23 | 23 | |
| 24 | 24 | foreach (ClassMap::MODELS as $name => $class) { |
| 25 | 25 | $this->assertInstanceOf($class, ObjectFactory::create($this->getMockClient(), $name, $mock_data)); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public function test_is_associative_array() |
| 22 | 22 | { |
| 23 | 23 | $this->assertEquals(true, ArrayLib::is_associative(['a' => 1])); |
| 24 | - $this->assertEquals(false, ArrayLib::is_associative([1,2,3])); |
|
| 24 | + $this->assertEquals(false, ArrayLib::is_associative([1, 2, 3])); |
|
| 25 | 25 | $this->assertEquals(false, ArrayLib::is_associative([])); |
| 26 | 26 | |
| 27 | 27 | try { |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | public function test_set_get_var() |
| 43 | 43 | { |
| 44 | 44 | $rel_path = '/path'; |
| 45 | - $this->assertEquals($rel_path . '?var=1', URL::setGetVar('var', 1, $rel_path)); |
|
| 45 | + $this->assertEquals($rel_path.'?var=1', URL::setGetVar('var', 1, $rel_path)); |
|
| 46 | 46 | |
| 47 | 47 | $rel_path_t = '/path/'; |
| 48 | - $this->assertEquals($rel_path_t . '?var=1', URL::setGetVar('var', 1, $rel_path_t)); |
|
| 48 | + $this->assertEquals($rel_path_t.'?var=1', URL::setGetVar('var', 1, $rel_path_t)); |
|
| 49 | 49 | |
| 50 | 50 | $absolute = 'https://test.com'; |
| 51 | - $this->assertEquals($absolute . '?var=1', URL::setGetVar('var', 1, $absolute)); |
|
| 51 | + $this->assertEquals($absolute.'?var=1', URL::setGetVar('var', 1, $absolute)); |
|
| 52 | 52 | |
| 53 | 53 | $absolute_t = 'https://test.com/'; |
| 54 | - $this->assertEquals($absolute_t . '?var=1', URL::setGetVar('var', 1, $absolute_t)); |
|
| 54 | + $this->assertEquals($absolute_t.'?var=1', URL::setGetVar('var', 1, $absolute_t)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | while (count($generated) < 100000) $generated[] = Utils::create_random_string(); |
| 72 | 72 | $count = count($generated); |
| 73 | 73 | $unique = count(array_unique($generated)); |
| 74 | - $random = 100 - ((100 / $count) * $unique); |
|
| 74 | + $random = 100-((100 / $count) * $unique); |
|
| 75 | 75 | |
| 76 | 76 | // Less than 2% repeat |
| 77 | 77 | $this->assertTrue($random < 2); |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | |
| 69 | 69 | // Test the randomness |
| 70 | 70 | $generated = []; |
| 71 | - while (count($generated) < 100000) $generated[] = Utils::create_random_string(); |
|
| 71 | + while (count($generated) < 100000) { |
|
| 72 | + $generated[] = Utils::create_random_string(); |
|
| 73 | + } |
|
| 72 | 74 | $count = count($generated); |
| 73 | 75 | $unique = count(array_unique($generated)); |
| 74 | 76 | $random = 100 - ((100 / $count) * $unique); |
@@ -20,13 +20,13 @@ discard block |
||
| 20 | 20 | public static function setGetVar(string $key, string $value, string $url): string |
| 21 | 21 | { |
| 22 | 22 | if (!self::is_absolute_url($url)) { |
| 23 | - $url = 'http://dummy.com/' . ltrim($url, '/'); |
|
| 23 | + $url = 'http://dummy.com/'.ltrim($url, '/'); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // try to parse uri |
| 27 | 27 | $parts = parse_url($url); |
| 28 | 28 | if (empty($parts)) { |
| 29 | - throw new InvalidArgumentException("Can't parse URL: " . $url); |
|
| 29 | + throw new InvalidArgumentException("Can't parse URL: ".$url); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Parse params and add new variable |
@@ -40,18 +40,18 @@ discard block |
||
| 40 | 40 | // Generate URI segments and formatting |
| 41 | 41 | $scheme = (array_key_exists('scheme', $parts)) ? $parts['scheme'] : 'http'; |
| 42 | 42 | $user = (array_key_exists('user', $parts)) ? $parts['user'] : ''; |
| 43 | - $port = (array_key_exists('port', $parts) && $parts['port']) ? ':' . $parts['port'] : ''; |
|
| 43 | + $port = (array_key_exists('port', $parts) && $parts['port']) ? ':'.$parts['port'] : ''; |
|
| 44 | 44 | |
| 45 | 45 | if ($user != '') { |
| 46 | 46 | // format in either user:[email protected] or [email protected] |
| 47 | - $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':' . $parts['pass'] . '@' : ''; |
|
| 47 | + $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':'.$parts['pass'].'@' : ''; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // handle URL params which are existing / new |
| 51 | - $params = ($params) ? '?' . http_build_query($params) : ''; |
|
| 51 | + $params = ($params) ? '?'.http_build_query($params) : ''; |
|
| 52 | 52 | |
| 53 | 53 | // Recompile URI segments |
| 54 | - $newUri = $scheme . '://' . $user . $parts['host'] . $port . ($parts['path'] ?? '') . $params; |
|
| 54 | + $newUri = $scheme.'://'.$user.$parts['host'].$port.($parts['path'] ?? '').$params; |
|
| 55 | 55 | |
| 56 | 56 | return str_replace('http://dummy.com', '', $newUri); |
| 57 | 57 | } |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | // Strip off the query and fragment parts of the URL before checking |
| 66 | 66 | if (($queryPosition = strpos($url, '?')) !== false) { |
| 67 | - $url = substr($url, 0, $queryPosition - 1); |
|
| 67 | + $url = substr($url, 0, $queryPosition-1); |
|
| 68 | 68 | } |
| 69 | 69 | if (($hashPosition = strpos($url, '#')) !== false) { |
| 70 | - $url = substr($url, 0, $hashPosition - 1); |
|
| 70 | + $url = substr($url, 0, $hashPosition-1); |
|
| 71 | 71 | } |
| 72 | 72 | $colonPosition = strpos($url, ':'); |
| 73 | 73 | $slashPosition = strpos($url, '/'); |
@@ -148,7 +148,7 @@ |
||
| 148 | 148 | string $url, |
| 149 | 149 | string $list_class = ListResource::class, |
| 150 | 150 | array $params = [] |
| 151 | - ){ |
|
| 151 | + ) { |
|
| 152 | 152 | $this->assertInstanceOf($list_class, $all); |
| 153 | 153 | $this->assertEquals($url, $all->getURL()); |
| 154 | 154 | $this->assertEquals($this->getMockClient(), $all->getClient()); |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Lifeboat; |
| 4 | 4 | |
| 5 | -require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'functions.php'; |
|
| 5 | +require_once __DIR__.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'functions.php'; |
|
| 6 | 6 | |
| 7 | 7 | use Lifeboat\Exceptions\BadMethodException; |
| 8 | 8 | use Lifeboat\Exceptions\OAuthException; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | public function curl_api(string $url, string $method = 'GET', array $data = [], array $headers = []): CurlResponse |
| 166 | 166 | { |
| 167 | 167 | $url = URL::is_absolute_url($url) ? $url |
| 168 | - : 'https://' . rtrim($this->getHost(), '/') . '/' . ltrim($url, '/'); |
|
| 168 | + : 'https://'.rtrim($this->getHost(), '/').'/'.ltrim($url, '/'); |
|
| 169 | 169 | |
| 170 | 170 | $curl = new Curl($url, $data, $headers); |
| 171 | 171 | |
@@ -184,6 +184,6 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | protected function auth_url(string $path): string |
| 186 | 186 | { |
| 187 | - return rtrim($this->_auth_domain, '/') . '/' . ltrim($path, '/'); |
|
| 187 | + return rtrim($this->_auth_domain, '/').'/'.ltrim($path, '/'); |
|
| 188 | 188 | } |
| 189 | 189 | } |
@@ -60,7 +60,9 @@ discard block |
||
| 60 | 60 | public function __get(string $service): ?ApiService |
| 61 | 61 | { |
| 62 | 62 | $obj = ServiceFactory::inst($this, $service); |
| 63 | - if (!$obj) throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 63 | + if (!$obj) { |
|
| 64 | + throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | return $obj; |
| 66 | 68 | } |
@@ -118,7 +120,9 @@ discard block |
||
| 118 | 120 | */ |
| 119 | 121 | public function getHost(): ?string |
| 120 | 122 | { |
| 121 | - if (!$this->getActiveSite(true)) return null; |
|
| 123 | + if (!$this->getActiveSite(true)) { |
|
| 124 | + return null; |
|
| 125 | + } |
|
| 122 | 126 | return $this->_host; |
| 123 | 127 | } |
| 124 | 128 | |
@@ -127,7 +131,9 @@ discard block |
||
| 127 | 131 | */ |
| 128 | 132 | public function getSiteKey(): ?string |
| 129 | 133 | { |
| 130 | - if (!$this->getActiveSite(true)) return null; |
|
| 134 | + if (!$this->getActiveSite(true)) { |
|
| 135 | + return null; |
|
| 136 | + } |
|
| 131 | 137 | return $this->_site_key; |
| 132 | 138 | } |
| 133 | 139 | |
@@ -151,7 +157,9 @@ discard block |
||
| 151 | 157 | $curl->addHeader('Host', $this->getHost()); |
| 152 | 158 | |
| 153 | 159 | foreach ($this->getAuthHeaders() as $header => $value) { |
| 154 | - if ($value) $curl->addHeader($header, $value); |
|
| 160 | + if ($value) { |
|
| 161 | + $curl->addHeader($header, $value); |
|
| 162 | + } |
|
| 155 | 163 | } |
| 156 | 164 | |
| 157 | 165 | return $curl->curl_json(); |
@@ -163,8 +171,12 @@ discard block |
||
| 163 | 171 | */ |
| 164 | 172 | public function getAuthHeaders(): array |
| 165 | 173 | { |
| 166 | - if (!$this->getAccessToken()) $this->fetchAccessToken(); |
|
| 167 | - if (!$this->getAccessToken()) throw new OAuthException("Access token has not been retreived"); |
|
| 174 | + if (!$this->getAccessToken()) { |
|
| 175 | + $this->fetchAccessToken(); |
|
| 176 | + } |
|
| 177 | + if (!$this->getAccessToken()) { |
|
| 178 | + throw new OAuthException("Access token has not been retreived"); |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | return [ |
| 170 | 182 | 'access-token' => $this->getAccessToken(), |