-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove unused code and optimize QueryBuilder class
- Loading branch information
Showing
8 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace KCNetwork\Liquipedia\Query; | ||
|
||
use stdClass; | ||
|
||
class QueryParameter implements QueryParametersInterface | ||
{ | ||
private stdClass $params; | ||
|
||
public function __construct(array $params = []) | ||
{ | ||
$this->params = (object) $params; | ||
|
||
foreach ($this->params as $key => $value) { | ||
$this->generateMethod($key); | ||
} | ||
} | ||
|
||
private function generateMethod(string $key): void | ||
{ | ||
$methodName = 'get'.ucfirst($key); | ||
$this->{$methodName} = fn () => $this->params->{$key}; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return (array) $this->params; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return json_encode($this->params, JSON_THROW_ON_ERROR); | ||
} | ||
|
||
public function __get(string $name): mixed | ||
{ | ||
return $this->params->{$name}; | ||
} | ||
|
||
public function __set(string $name, mixed $value): void | ||
{ | ||
$this->params->{$name} = $value; | ||
$this->generateMethod($name); | ||
} | ||
|
||
public function __isset(string $name): bool | ||
{ | ||
return isset($this->params->{$name}); | ||
} | ||
|
||
public function __unset(string $name): void | ||
{ | ||
unset($this->params->{$name}); | ||
unset($this->{'get'.ucfirst($name)}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace KCNetwork\Liquipedia\Query; | ||
|
||
use JsonException; | ||
|
||
interface QueryParametersInterface | ||
{ | ||
/** | ||
* Returns the parameters as an array | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(): array; | ||
|
||
/** | ||
* Returns the parameters as a json string | ||
* | ||
* @throws JsonException | ||
*/ | ||
public function __toString(): string; | ||
|
||
/** | ||
* Returns the value of the parameter | ||
*/ | ||
public function __get(string $name): mixed; | ||
|
||
/** | ||
* Sets the value of the parameter | ||
*/ | ||
public function __set(string $name, mixed $value): void; | ||
|
||
/** | ||
* Checks if the parameter is set | ||
*/ | ||
public function __isset(string $name): bool; | ||
|
||
/** | ||
* Unsets the parameter | ||
*/ | ||
public function __unset(string $name): void; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
use KCNetwork\Liquipedia\Query\QueryParameter; | ||
|
||
it('it can be instantiated', function () { | ||
$queryParameter = new QueryParameter(); | ||
|
||
expect($queryParameter)->toBeInstanceOf(QueryParameter::class); | ||
}); | ||
|