@@ -15,7 +15,6 @@ |
||
| 15 | 15 | * @property Byte $Main Indicates the main unit per division. Will be used when creating new item |
| 16 | 16 | * @property String $TimeUnit If Type = 'T' (time) then this fields indicates the type of time frame. yy = Year, mm = Month, wk = Week, dd = Day, hh = Hour, mi = Minute, ss = Second |
| 17 | 17 | * @property String $Type Type 'Time' is especially important for contracts. |
| 18 | - |
|
| 19 | 18 | */ |
| 20 | 19 | class Units extends Model |
| 21 | 20 | {
|
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | |
| 6 | 6 | public function find($id) |
| 7 | 7 | { |
| 8 | - $filter = $this->primaryKey . " eq guid'$id'"; |
|
| 8 | + $filter = $this->primaryKey . " eq guid'$id'"; |
|
| 9 | 9 | |
| 10 | 10 | if ($this->primaryKey === 'Code') { |
| 11 | 11 | $filter = $this->primaryKey . " eq $id"; |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return string (guid) |
| 43 | 43 | */ |
| 44 | - public function findId($code, $key='Code'){ |
|
| 45 | - if ( $this->isFillable($key) ) { |
|
| 44 | + public function findId($code, $key = 'Code') { |
|
| 45 | + if ($this->isFillable($key)) { |
|
| 46 | 46 | $format = ($this->url == 'crm/Accounts' && $key === 'Code') ? '%18s' : '%s'; |
| 47 | 47 | if (preg_match('/^[\w]{8}-([\w]{4}-){3}[\w]{12}$/', $code)) { |
| 48 | 48 | $format = "guid'$format'"; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | '$select' => $this->primaryKey, |
| 59 | 59 | '$orderby' => $this->primaryKey, |
| 60 | 60 | ]; |
| 61 | - if( $records = $this->connection()->get($this->url, $request) ){ |
|
| 61 | + if ($records = $this->connection()->get($this->url, $request)) { |
|
| 62 | 62 | return $records[0][$this->primaryKey]; |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $result = $this->connection()->get($this->url, $request, $headers); |
| 92 | 92 | |
| 93 | - if (!empty($divisionId)) { |
|
| 93 | + if ( ! empty($divisionId)) { |
|
| 94 | 94 | $this->connection()->setDivision($originalDivision); // Restore division |
| 95 | 95 | } |
| 96 | 96 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | // If we have one result which is not an assoc array, make it the first element of an array for the |
| 126 | 126 | // collectionFromResult function so we always return a collection from filter |
| 127 | 127 | if ((bool) count(array_filter(array_keys($result), 'is_string'))) { |
| 128 | - $result = [ $result ]; |
|
| 128 | + $result = [$result]; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | while ($this->connection()->nextUrl !== null) |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $nextResult = $this->connection()->get($this->connection()->nextUrl); |
| 134 | 134 | $result = array_merge($result, $nextResult); |
| 135 | 135 | } |
| 136 | - $collection = [ ]; |
|
| 136 | + $collection = []; |
|
| 137 | 137 | foreach ($result as $r) { |
| 138 | 138 | $collection[] = new self($this->connection(), $r); |
| 139 | 139 | } |
@@ -46,8 +46,7 @@ |
||
| 46 | 46 | $format = ($this->url == 'crm/Accounts' && $key === 'Code') ? '%18s' : '%s'; |
| 47 | 47 | if (preg_match('/^[\w]{8}-([\w]{4}-){3}[\w]{12}$/', $code)) { |
| 48 | 48 | $format = "guid'$format'"; |
| 49 | - } |
|
| 50 | - elseif (is_string($code)) { |
|
| 49 | + } elseif (is_string($code)) { |
|
| 51 | 50 | $format = "'$format'"; |
| 52 | 51 | } |
| 53 | 52 | |
@@ -131,7 +131,7 @@ |
||
| 131 | 131 | * @return mixed |
| 132 | 132 | */ |
| 133 | 133 | public function getSalesInvoiceLines() { |
| 134 | - if(array_key_exists('__deferred', $this->attributes['SalesInvoiceLines'])) { |
|
| 134 | + if (array_key_exists('__deferred', $this->attributes['SalesInvoiceLines'])) { |
|
| 135 | 135 | $this->attributes['SalesInvoiceLines'] = (new SalesInvoiceLine($this->connection()))->filter("InvoiceID eq guid'{$this->InvoiceID}'"); |
| 136 | 136 | } |
| 137 | 137 | return $this->attributes['SalesInvoiceLines']; |
@@ -42,8 +42,8 @@ |
||
| 42 | 42 | |
| 43 | 43 | public function addItem(array $array) |
| 44 | 44 | { |
| 45 | - if ( ! isset( $this->attributes['GeneralJournalEntryLines'] ) || $this->attributes['GeneralJournalEntryLines'] == null) { |
|
| 46 | - $this->attributes['GeneralJournalEntryLines'] = [ ]; |
|
| 45 | + if ( ! isset($this->attributes['GeneralJournalEntryLines']) || $this->attributes['GeneralJournalEntryLines'] == null) { |
|
| 46 | + $this->attributes['GeneralJournalEntryLines'] = []; |
|
| 47 | 47 | } |
| 48 | 48 | $this->attributes['GeneralJournalEntryLines'][] = $array; |
| 49 | 49 | } |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // If we have a token, sign the request |
| 168 | - if (!$this->needsAuthentication() && !empty($this->accessToken)) { |
|
| 168 | + if ( ! $this->needsAuthentication() && ! empty($this->accessToken)) { |
|
| 169 | 169 | $headers['Authorization'] = 'Bearer ' . $this->accessToken; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Create param string |
| 173 | - if (!empty($params)) { |
|
| 173 | + if ( ! empty($params)) { |
|
| 174 | 174 | $endpoint .= '?' . http_build_query($params); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | private function getDateTimeFromExpires($expires) |
| 460 | 460 | { |
| 461 | - if (!is_numeric($expires)) { |
|
| 461 | + if ( ! is_numeric($expires)) { |
|
| 462 | 462 | throw new \InvalidArgumentException('Function requires a numeric expires value'); |
| 463 | 463 | } |
| 464 | 464 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | */ |
| 544 | 544 | private function parseExceptionForErrorMessages(Exception $e) |
| 545 | 545 | { |
| 546 | - if (! $e instanceof BadResponseException) { |
|
| 546 | + if ( ! $e instanceof BadResponseException) { |
|
| 547 | 547 | throw new ApiException($e->getMessage()); |
| 548 | 548 | } |
| 549 | 549 | |
@@ -552,13 +552,13 @@ discard block |
||
| 552 | 552 | $responseBody = $response->getBody()->getContents(); |
| 553 | 553 | $decodedResponseBody = json_decode($responseBody, true); |
| 554 | 554 | |
| 555 | - if (! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) { |
|
| 555 | + if ( ! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) { |
|
| 556 | 556 | $errorMessage = $decodedResponseBody['error']['message']['value']; |
| 557 | 557 | } else { |
| 558 | 558 | $errorMessage = $responseBody; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - throw new ApiException('Error ' . $response->getStatusCode() .': ' . $errorMessage); |
|
| 561 | + throw new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -358,8 +358,7 @@ |
||
| 358 | 358 | if (array_key_exists('d', $json)) { |
| 359 | 359 | if (array_key_exists('__next', $json['d'])) { |
| 360 | 360 | $this->nextUrl = $json['d']['__next']; |
| 361 | - } |
|
| 362 | - else { |
|
| 361 | + } else { |
|
| 363 | 362 | $this->nextUrl = null; |
| 364 | 363 | } |
| 365 | 364 | |
@@ -94,8 +94,8 @@ |
||
| 94 | 94 | protected $middleWares = []; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * @var |
|
| 98 | - */ |
|
| 97 | + * @var |
|
| 98 | + */ |
|
| 99 | 99 | public $nextUrl = null; |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -124,10 +124,10 @@ |
||
| 124 | 124 | */ |
| 125 | 125 | public function addItem(array $array) |
| 126 | 126 | { |
| 127 | - if (! isset($this->attributes['PurchaseOrderLines']) || $this->attributes['PurchaseOrderLines'] == null) { |
|
| 127 | + if ( ! isset($this->attributes['PurchaseOrderLines']) || $this->attributes['PurchaseOrderLines'] == null) { |
|
| 128 | 128 | $this->attributes['PurchaseOrderLines'] = []; |
| 129 | 129 | } |
| 130 | - if (! isset($array['LineNumber'])) { |
|
| 130 | + if ( ! isset($array['LineNumber'])) { |
|
| 131 | 131 | $array['LineNumber'] = count($this->attributes['PurchaseOrderLines']) + 1; |
| 132 | 132 | } |
| 133 | 133 | $this->attributes['PurchaseOrderLines'][] = $array; |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | |
| 53 | 53 | public function addItem(array $array) |
| 54 | 54 | { |
| 55 | - if (! isset($this->attributes['CashEntryLines']) || $this->attributes['CashEntryLines'] == null) { |
|
| 55 | + if ( ! isset($this->attributes['CashEntryLines']) || $this->attributes['CashEntryLines'] == null) { |
|
| 56 | 56 | $this->attributes['CashEntryLines'] = []; |
| 57 | 57 | } |
| 58 | 58 | $this->attributes['CashEntryLines'][] = $array; |
@@ -142,10 +142,10 @@ |
||
| 142 | 142 | */ |
| 143 | 143 | public function addItem(array $array) |
| 144 | 144 | { |
| 145 | - if (! isset($this->attributes['SalesOrderLines']) || $this->attributes['SalesOrderLines'] == null) { |
|
| 145 | + if ( ! isset($this->attributes['SalesOrderLines']) || $this->attributes['SalesOrderLines'] == null) { |
|
| 146 | 146 | $this->attributes['SalesOrderLines'] = []; |
| 147 | 147 | } |
| 148 | - if (! isset($array['LineNumber'])) { |
|
| 148 | + if ( ! isset($array['LineNumber'])) { |
|
| 149 | 149 | $array['LineNumber'] = count($this->attributes['SalesOrderLines']) + 1; |
| 150 | 150 | } |
| 151 | 151 | $this->attributes['SalesOrderLines'][] = $array; |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @var array The model's attributes |
| 20 | 20 | */ |
| 21 | - protected $attributes = [ ]; |
|
| 21 | + protected $attributes = []; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @deferred array The model's collection values |
| 25 | 25 | */ |
| 26 | - protected $deferred = [ ]; |
|
| 26 | + protected $deferred = []; |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @var array The model's fillable attributes |
| 30 | 30 | */ |
| 31 | - protected $fillable = [ ]; |
|
| 31 | + protected $fillable = []; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @var string The URL endpoint of this model |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | try { |
| 137 | - if(is_array($this->attributes[$key]) && array_key_exists('__deferred', $this->attributes[$key])) { |
|
| 137 | + if (is_array($this->attributes[$key]) && array_key_exists('__deferred', $this->attributes[$key])) { |
|
| 138 | 138 | $class = preg_replace('/(.+?)s?$/', __NAMESPACE__ . '\\\$1', $key); // Filter plural 's' and add namespace |
| 139 | 139 | $deferred = new $class($this->connection()); |
| 140 | 140 | $uri = $this->attributes[$key]['__deferred']['uri']; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | return $this->deferred[$key]; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if (isset( $this->attributes[$key] )) { |
|
| 161 | + if (isset($this->attributes[$key])) { |
|
| 162 | 162 | return $this->attributes[$key]; |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - return ! empty( $this->attributes[$this->primaryKey] ); |
|
| 199 | + return ! empty($this->attributes[$this->primaryKey]); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | $attributes = $this->attributes; |
| 213 | 213 | if ($withDeferred) { |
| 214 | - foreach($this->deferred as $attribute => $collection) { |
|
| 214 | + foreach ($this->deferred as $attribute => $collection) { |
|
| 215 | 215 | if (empty($collection)) { |
| 216 | 216 | continue; // Leave orriginal array with __deferred key |
| 217 | 217 | } |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return boolean |
| 252 | 252 | */ |
| 253 | - public function userHasRights($action='GET') |
|
| 253 | + public function userHasRights($action = 'GET') |
|
| 254 | 254 | { |
| 255 | - $action = preg_match('/^GET|POST|PUT|DELETE$/i', $action) ? strtoupper($action) : 'GET'; |
|
| 255 | + $action = preg_match('/^GET|POST|PUT|DELETE$/i', $action) ? strtoupper($action) : 'GET'; |
|
| 256 | 256 | $result = $this->connection()->get('users/UserHasRights', [ |
| 257 | 257 | 'endpoint' => "'{$this->url}'", |
| 258 | 258 | 'action' => "'{$action}'" |
@@ -144,8 +144,7 @@ |
||
| 144 | 144 | |
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | - } |
|
| 148 | - catch (\Exception $e) { |
|
| 147 | + } catch (\Exception $e) { |
|
| 149 | 148 | // We tried lets leave it as is. |
| 150 | 149 | } |
| 151 | 150 | |