Skip to content

Commit

Permalink
Merge branch 'main' into node/unified-snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcuva authored Dec 19, 2023
2 parents b4d752d + 36506cd commit 9090451
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/php/src/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Metrics
private Client $readme_api_client;

private string|null $package_version;
private string $cache_dir;
private string|null $cache_dir;
private string $user_agent;

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ public function __construct(public string $api_key, public string $group_handler
]);

$this->package_version = InstalledVersions::getVersion(self::PACKAGE_NAME);
$this->cache_dir = Factory::createConfig()->get('cache-dir');
$this->cache_dir = null;

$this->user_agent = 'readme-metrics-php/' . ($this->package_version ?? 'unknown');
}
Expand Down Expand Up @@ -247,7 +247,20 @@ public function getCacheFile(): string
// Replace potentially unsafe characters in the cache key so it can be safely used as a filename on the server.
$cache_key = str_replace([DIRECTORY_SEPARATOR, '@'], '-', $cache_key);

return $this->cache_dir . DIRECTORY_SEPARATOR . $cache_key;
return $this->getCacheDir() . DIRECTORY_SEPARATOR . $cache_key;
}

/**
* Retrieve the cache dir where the cache file will be stored.
*
*/
public function getCacheDir(): string
{
if ($this->cache_dir === null) {
$this->cache_dir = Factory::createConfig()->get('cache-dir');
}

return $this->cache_dir;
}

public function getPackageVersion(): ?string
Expand Down

0 comments on commit 9090451

Please sign in to comment.