Skip to content

Commit

Permalink
Add context creation methods and refactor code
Browse files Browse the repository at this point in the history
Implemented new static methods in the Context class to create default, user, and admin contexts. Refactored the Core class to simplify checks for the existence of the itemsOrder attribute. Made changes in the AbstractItem class to change typing for array offset access methods and improve code readability.

Signed-off-by: B24io <app@b24.io>
  • Loading branch information
b24io-sdk committed May 22, 2024
1 parent 461ef32 commit 5dd8926
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function call(Command $cmd): Response
'apiMethod' => $cmd->apiMethod,
'parameters' => $cmd->parameters,
'order' => [
'orderBy' => $cmd->itemsOrder?->orderBy,
'direction' => $cmd->itemsOrder?->direction,
'orderBy' => $cmd->itemsOrder !== null ? $cmd->itemsOrder->orderBy : null,
'direction' => $cmd->itemsOrder !== null ? $cmd->itemsOrder->direction : null,
],
]
);
Expand Down Expand Up @@ -76,7 +76,7 @@ public function call(Command $cmd): Response
//todo check with empty response size from server
$response = new Response($apiCallResponse,
new Command(
Context::admin,
Context::admin(),
$cmd->httpMethod,
$cmd->apiMethod,
$cmd->parameters
Expand Down
15 changes: 15 additions & 0 deletions src/Core/Credentials/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public function __construct(string $value)
$this->value = $value;
}

public static function default(): self
{
return new self(self::default);
}

public static function user(): self
{
return new self(self::user);
}

public static function admin(): self
{
return new self(self::admin);
}

public function isDefault(): bool
{
return $this->value === self::default;
Expand Down
11 changes: 7 additions & 4 deletions src/Core/Result/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public function __construct(array $data)
$this->decimalMoneyParser = new DecimalMoneyParser(new ISOCurrencies());
}

public function __isset(int|string $offset): bool
/**
* @param int|string $offset
*/
public function __isset($offset): bool
{
return isset($this->data[$offset]);
}
Expand All @@ -46,7 +49,7 @@ public function __isset(int|string $offset): bool
* @return mixed
* @throws Exception
*/
public function __get(int|string $offset)
public function __get($offset)
{
switch ($offset) {
case 'id':
Expand Down Expand Up @@ -76,7 +79,7 @@ public function __get(int|string $offset)
* @throws ImmutableResultViolationException
*
*/
public function __set(int|string $offset, mixed $value)
public function __set($offset, $value)
{
throw new ImmutableResultViolationException(sprintf('Result is immutable, violation at offset %s', $offset));
}
Expand All @@ -86,7 +89,7 @@ public function __set(int|string $offset, mixed $value)
*
* @throws ImmutableResultViolationException
*/
public function __unset(int|string $offset)
public function __unset($offset)
{
throw new ImmutableResultViolationException(sprintf('Result is immutable, violation at offset %s', $offset));
}
Expand Down

0 comments on commit 5dd8926

Please sign in to comment.