diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 2f32b5f..c958238 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -19,7 +19,7 @@ jobs: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@1.0.0 + uses: aglipanci/laravel-pint-action@2.3.1 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/src/EnergyZero.php b/src/EnergyZero.php index c1bf042..59dd8d0 100755 --- a/src/EnergyZero.php +++ b/src/EnergyZero.php @@ -3,8 +3,8 @@ namespace Baspa\EnergyZero; use DateTime; -use Exception; use DateTimeZone; +use Exception; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; @@ -12,11 +12,14 @@ class EnergyZero { private bool $vat = true; + private int $requestTimeout = 10; + private string $baseUri = 'https://api.energyzero.nl/v1/'; + private ClientInterface $client; - public function __construct(ClientInterface $client = null) + public function __construct(?ClientInterface $client = null) { $this->client = $client ?? new Client([ 'base_uri' => $this->baseUri, @@ -42,10 +45,11 @@ public function request(string $uri, array $params = []): ?array if ($response->getStatusCode() === 200) { return json_decode($response->getBody()->getContents(), true); } else { - throw new Exception('Unexpected response status: ' . $response->getStatusCode()); + throw new Exception('Unexpected response status: '.$response->getStatusCode()); } } catch (RequestException $e) { - error_log('Error: ' . $e->getMessage()); + error_log('Error: '.$e->getMessage()); + return null; } } @@ -192,4 +196,4 @@ public function getValleyHours(string $startDate, string $endDate, int $topN = 5 return array_slice($prices, 0, $topN); } -} \ No newline at end of file +} diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index f61b951..1815066 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -7,7 +7,7 @@ use GuzzleHttp\Psr7\Response; beforeEach(function () { - $this->mockHandler = new MockHandler(); + $this->mockHandler = new MockHandler; $handlerStack = HandlerStack::create($this->mockHandler); $client = new Client(['handler' => $handlerStack]); $this->energyZero = new EnergyZero($client); @@ -171,4 +171,4 @@ ['readingDate' => '2023-05-01T00:00:00', 'price' => 0.1], ['readingDate' => '2023-05-01T02:00:00', 'price' => 0.2], ]); -}); \ No newline at end of file +});