Skip to content

Commit

Permalink
Added some stopwatches
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Feb 19, 2024
1 parent a547afe commit ae3a602
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Service/SyncAanslagenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Entity\Entity;
use DateTime;
use DateInterval;
use Symfony\Component\Stopwatch\Stopwatch;

class SyncAanslagenService
{
Expand Down Expand Up @@ -52,6 +53,8 @@ class SyncAanslagenService
* @var LoggerInterface
*/
private LoggerInterface $logger;

private Stopwatch $stopwatch;


/**
Expand All @@ -63,14 +66,16 @@ public function __construct(
EntityManagerInterface $entityManager,
LoggerInterface $pluginLogger,
SynchronizationService $synchronizationService,

Check warning on line 68 in src/Service/SyncAanslagenService.php

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $synchronizationService. Keep variable name length under 20.
CallService $callService
CallService $callService,
Stopwatch $stopwatch
) {
$this->entityManager = $entityManager;
$this->logger = $pluginLogger;
$this->synchronizationService = $synchronizationService;
$this->callService = $callService;
$this->configuration = [];
$this->data = [];
$this->stopwatch = $stopwatch;

Check warning on line 78 in src/Service/SyncAanslagenService.php

View workflow job for this annotation

GitHub Actions / build

Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

}//end __construct()

Expand Down Expand Up @@ -113,6 +118,8 @@ private function syncAanslag(array $aanslag, Gateway $source, Entity $entity)
*/
private function syncAanslagen(array $fetchedAanslagen, Gateway $source, Entity $entity): array

Check warning on line 119 in src/Service/SyncAanslagenService.php

View workflow job for this annotation

GitHub Actions / build

Avoid assigning values to variables in if clauses and the like (line '127', column '17').
{
$this->stopwatch->start('syncAanslagen', 'open-belasting-bundle');

$syncedAanslagen = [];
$syncedAanslagenCount = 0;
$flushCount = 0;
Expand All @@ -122,6 +129,8 @@ private function syncAanslagen(array $fetchedAanslagen, Gateway $source, Entity
$flushCount = ($flushCount + 1);
$syncedAanslagen[] = $syncedAanslag;
}//end if

$this->stopwatch->lap('syncAanslagen');

// Flush every 20.
if ($flushCount == 20) {
Expand All @@ -137,7 +146,9 @@ private function syncAanslagen(array $fetchedAanslagen, Gateway $source, Entity
}//end if

$this->logger->debug("Synced $flushCount aanslagen from the $syncedAanslagenCount fetched aanslagen");


$this->stopwatch->stop('syncAanslagen');

return $syncedAanslagen;

}//end syncAanslagen()
Expand All @@ -153,6 +164,8 @@ private function syncAanslagen(array $fetchedAanslagen, Gateway $source, Entity
*/
private function fetchAanslagen(Gateway $source, string $bsn): array
{
$this->stopwatch->start('fetchAanslagen', 'open-belasting-bundle');

$endpoint = '/v1/aanslagen';
$dateTime = new DateTime();
$dateTime->add(DateInterval::createFromDateString('-4 year'));

Check warning on line 171 in src/Service/SyncAanslagenService.php

View workflow job for this annotation

GitHub Actions / build

Avoid using static access to class '\DateInterval' in method 'fetchAanslagen'.
Expand All @@ -171,6 +184,8 @@ private function fetchAanslagen(Gateway $source, string $bsn): array

$fetchedAanslagenCount = count($fetchedAanslagen);

Check warning on line 185 in src/Service/SyncAanslagenService.php

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $fetchedAanslagenCount. Keep variable name length under 20.
$this->logger->debug("Fetched $fetchedAanslagenCount aanslagen");

$this->stopwatch->stop('fetchAanslagen');

return $fetchedAanslagen;

Expand All @@ -186,6 +201,7 @@ private function fetchAanslagen(Gateway $source, string $bsn): array
**/
public function fetchAndSyncAanslagen(string $bsn): array
{
$this->stopwatch->start('fetchAndSyncAanslagen', 'open-belasting-bundle');

$source = $this->entityManager->getRepository('App:Gateway')->findOneBy(['reference' => 'https://openbelasting.nl/source/openbelasting.pinkapi.source.json']);
$entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => 'https://openbelasting.nl/schemas/openblasting.aanslagbiljet.schema.json']);
Expand All @@ -198,8 +214,12 @@ public function fetchAndSyncAanslagen(string $bsn): array
$this->logger->debug("SyncAanslagenService -> syncAanslagenHandler()");

$fetchedAanslagen = $this->fetchAanslagen($source, $bsn);

$array = $this->syncAanslagen($fetchedAanslagen, $source, $entity);

$this->stopwatch->stop('fetchAndSyncAanslagen');

return $this->syncAanslagen($fetchedAanslagen, $source, $entity);
return $array;

}//end fetchAndSyncAanslagen()

Expand Down

0 comments on commit ae3a602

Please sign in to comment.