Skip to content

Commit

Permalink
feat: Added PHP equivalents for Python dependencie
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 12, 2024
1 parent ac56520 commit 5181fb3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Snps/IO/PythonDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Dna\Snps\IO;

use Exception;
use GuzzleHttp\Client;

class FileHandler
{
public static function writeFile(string $path, string $content): void
{
$file = fopen($path, 'w');
fwrite($file, $content);
fclose($file);
}
}

class DataManipulator
{
public static function filterArray(array $data, callable $callback): array
{
return array_filter($data, $callback, ARRAY_FILTER_USE_BOTH);
}

public static function sortArray(array &$data, callable $callback): void
{
usort($data, $callback);
}
}

class ExternalDataFetcher
{
private Client $client;

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

public function fetchData(string $url): ?array
{
try {
$response = $this->client->request('GET', $url);
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody()->getContents(), true);
}
return null;
} catch (Exception $e) {
error_log("Failed to fetch data from {$url}: " . $e->getMessage());
return null;
}
}
}

0 comments on commit 5181fb3

Please sign in to comment.