Skip to content

Commit

Permalink
Apply fixes from StyleCI (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedash95 committed Dec 30, 2021
1 parent 1357cbe commit a133be5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
1 change: 0 additions & 1 deletion leetcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Repositories\DailyProblem\DailyProblemRepository;
use App\Repositories\DataStructures\DataStructuresCacheRepository;
use App\Repositories\Problems\ProblemCacheRepository;
use App\Services\ChallengesService;
use App\Services\DailyProblemsService;
use App\Services\DataStructureService;
use App\Services\ProblemsService;
Expand Down
99 changes: 49 additions & 50 deletions src/Repositories/DailyProblem/DailyProblemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,53 @@

class DailyProblemRepository implements DailyProblemRepositoryInterface
{
/**
* @var HttpClient
*/
private $client;

public function __construct(HttpClientInterface $client)
{
$this->client = $client;
}

public function get(): array
{

$response = $this->client->request('POST', 'https://leetcode.com/graphql', [
'json' => [
'query' => 'query questionOfToday {activeDailyCodingChallengeQuestion {link question { title }}}',
],
]);

return $this->hydrate($response->toArray()['data']['activeDailyCodingChallengeQuestion'] ?? null);
}

/**
* @param string $query
*
* @return array
*/
public function search($query): array
{
return $this->get();
}

/**
* @param array $data
*
* @return LeetCodeItem[]
*/
private function hydrate(array $data)
{
if($data === null) {
return [];
}

$leetcode = new LeetCodeItem();
$leetcode->setName($data['question']['title']);
$leetcode->setType(LeetCodeType::PROBLEM_OF_THE_DAY);
$leetcode->setSlug($data['link']);

return [$leetcode];
}
/**
* @var HttpClient
*/
private $client;

public function __construct(HttpClientInterface $client)
{
$this->client = $client;
}

public function get(): array
{
$response = $this->client->request('POST', 'https://leetcode.com/graphql', [
'json' => [
'query' => 'query questionOfToday {activeDailyCodingChallengeQuestion {link question { title }}}',
],
]);

return $this->hydrate($response->toArray()['data']['activeDailyCodingChallengeQuestion'] ?? null);
}

/**
* @param string $query
*
* @return array
*/
public function search($query): array
{
return $this->get();
}

/**
* @param array $data
*
* @return LeetCodeItem[]
*/
private function hydrate(array $data)
{
if ($data === null) {
return [];
}

$leetcode = new LeetCodeItem();
$leetcode->setName($data['question']['title']);
$leetcode->setType(LeetCodeType::PROBLEM_OF_THE_DAY);
$leetcode->setSlug($data['link']);

return [$leetcode];
}
}

0 comments on commit a133be5

Please sign in to comment.