Skip to content

Commit

Permalink
Apply updated CS rules from doctrine/coding-standard 8.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Feb 10, 2021
1 parent 9c17397 commit 152a503
Show file tree
Hide file tree
Showing 91 changed files with 531 additions and 477 deletions.
52 changes: 27 additions & 25 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Scoutapm\Helper\LocateFileOrFolder;
use Scoutapm\Logger\FilteredLogLevelDecorator;
use Throwable;

use function count;
use function in_array;
use function is_array;
Expand Down Expand Up @@ -105,7 +106,7 @@ private function __construct(
$this->ignoredEndpoints = new IgnoredEndpoints($configuration->get(ConfigKey::IGNORED_ENDPOINTS));
}

private function warnIfConfigValueIsNotSet(string $configKey) : void
private function warnIfConfigValueIsNotSet(string $configKey): void
{
$configValue = $this->config->get($configKey);

Expand All @@ -116,7 +117,7 @@ private function warnIfConfigValueIsNotSet(string $configKey) : void
$this->logger->warning(sprintf('Config key "%s" should be set, but it was empty', $configKey));
}

private static function createConnectorFromConfig(Config $config) : SocketConnector
private static function createConnectorFromConfig(Config $config): SocketConnector
{
return new SocketConnector(
ConnectionAddress::fromConfig($config),
Expand All @@ -131,7 +132,7 @@ public static function fromConfig(
?Connector $connector = null,
?ExtentionCapabilities $extentionCapabilities = null,
?LocateFileOrFolder $locateFileOrFolder = null
) : self {
): self {
return new self(
$config,
$connector ?? self::createConnectorFromConfig($config),
Expand All @@ -142,14 +143,14 @@ public static function fromConfig(
);
}

private function extensionVersion() : string
private function extensionVersion(): string
{
$extensionVersion = $this->phpExtension->version();

return $extensionVersion === null ? 'n/a' : $extensionVersion->toString();
}

private function checkExtensionVersion() : void
private function checkExtensionVersion(): void
{
$extensionVersion = $this->phpExtension->version();

Expand All @@ -170,7 +171,7 @@ private function checkExtensionVersion() : void
));
}

public function connect() : void
public function connect(): void
{
$this->logger->debug('Configuration: ' . json_encode($this->config->asArrayWithSecretsRemoved()));

Expand Down Expand Up @@ -234,7 +235,7 @@ public function connect() : void
}

/** {@inheritDoc} */
public function enabled() : bool
public function enabled(): bool
{
return $this->config->get(ConfigKey::MONITORING_ENABLED);
}
Expand Down Expand Up @@ -270,12 +271,12 @@ private function onlyRunIfBelowSpanLimit(callable $codeToRunIfBelowSpanLimit)
}

/** {@inheritDoc} */
public function startSpan(string $operation, ?float $overrideTimestamp = null) : ?SpanReference
public function startSpan(string $operation, ?float $overrideTimestamp = null): ?SpanReference
{
$this->addSpansFromExtension();

$returnValue = $this->onlyRunIfBelowSpanLimit(
function () use ($operation, $overrideTimestamp) : ?Span {
function () use ($operation, $overrideTimestamp): ?Span {
if ($this->request === null) {
return null;
}
Expand All @@ -291,7 +292,7 @@ function () use ($operation, $overrideTimestamp) : ?Span {
return SpanReference::fromSpan($returnValue);
}

public function stopSpan() : void
public function stopSpan(): void
{
if ($this->request === null) {
return;
Expand All @@ -302,10 +303,10 @@ public function stopSpan() : void
$this->request->stopSpan();
}

private function addSpansFromExtension() : void
private function addSpansFromExtension(): void
{
$this->onlyRunIfBelowSpanLimit(
function () : ?Span {
function (): ?Span {
if ($this->request === null) {
return null;
}
Expand Down Expand Up @@ -353,12 +354,12 @@ public function backgroundTransaction(string $name, callable $block)
return $this->instrument(SpanReference::INSTRUMENT_JOB, $name, $block);
}

public function addContext(string $tag, string $value) : void
public function addContext(string $tag, string $value): void
{
$this->tagRequest($tag, $value);
}

public function tagRequest(string $tag, string $value) : void
public function tagRequest(string $tag, string $value): void
{
if ($this->request === null) {
return;
Expand All @@ -368,20 +369,20 @@ public function tagRequest(string $tag, string $value) : void
}

/** {@inheritDoc} */
public function ignored(string $path) : bool
public function ignored(string $path): bool
{
return $this->ignoredEndpoints->ignored($path);
}

/** {@inheritDoc} */
public function ignore() : void
public function ignore(): void
{
$this->request = null;
$this->isIgnored = true;
}

/** {@inheritDoc} */
public function shouldInstrument(string $functionality) : bool
public function shouldInstrument(string $functionality): bool
{
$disabledInstruments = $this->config->get(ConfigKey::DISABLED_INSTRUMENTS);

Expand All @@ -391,16 +392,17 @@ public function shouldInstrument(string $functionality) : bool
}

/** {@inheritDoc} */
public function changeRequestUri(string $newRequestUri) : void
public function changeRequestUri(string $newRequestUri): void
{
if ($this->request === null) {
return;
}

$this->request->overrideRequestUri($newRequestUri);
}

/** {@inheritDoc} */
public function send() : bool
public function send(): bool
{
// Don't send if the agent is not enabled.
if (! $this->enabled()) {
Expand Down Expand Up @@ -472,7 +474,7 @@ public function send() : bool
}

/** {@inheritDoc} */
public function startNewRequest() : void
public function startNewRequest(): void
{
if ($this->request !== null) {
$this->request->cleanUp();
Expand All @@ -481,7 +483,7 @@ public function startNewRequest() : void
$this->request = new Request();
}

private function registerIfRequired() : void
private function registerIfRequired(): void
{
if ($this->registered) {
return;
Expand All @@ -499,7 +501,7 @@ private function registerIfRequired() : void
/**
* @throws Exception
*/
private function sendMetadataIfRequired() : void
private function sendMetadataIfRequired(): void
{
if ($this->metadataWasSent()) {
$this->logger->debug('Skipping metadata send, already sent');
Expand All @@ -524,12 +526,12 @@ private function sendMetadataIfRequired() : void
}
}

private function metadataWasSent() : bool
private function metadataWasSent(): bool
{
return (bool) $this->cache->get(self::CACHE_KEY_METADATA_SENT, false);
}

private function markMetadataSent() : void
private function markMetadataSent(): void
{
if ($this->metadataWasSent()) {
return;
Expand All @@ -544,7 +546,7 @@ private function markMetadataSent() : void
* @internal
* @deprecated
*/
public function getRequest() : ?Request
public function getRequest(): ?Request
{
return $this->request;
}
Expand Down
16 changes: 7 additions & 9 deletions src/Cache/DevNullCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Scoutapm\Cache;

use Psr\SimpleCache\CacheInterface;
use Traversable;

use function array_combine;
use function array_map;
use function is_array;
Expand All @@ -21,27 +21,25 @@ public function get($key, $default = null)
}

/** @inheritDoc */
public function set($key, $value, $ttl = null) : bool
public function set($key, $value, $ttl = null): bool
{
return true;
}

/** @inheritDoc */
public function delete($key) : bool
public function delete($key): bool
{
return true;
}

/** @inheritDoc */
public function clear() : bool
public function clear(): bool
{
return true;
}

/** @inheritDoc */
public function getMultiple($keys, $default = null)
{
/** @var array|Traversable $keys */
if (is_array($keys)) {
$keysAsArray = $keys;
} else {
Expand All @@ -61,19 +59,19 @@ function (string $key) use ($default) {
}

/** @inheritDoc */
public function setMultiple($values, $ttl = null) : bool
public function setMultiple($values, $ttl = null): bool
{
return true;
}

/** @inheritDoc */
public function deleteMultiple($keys) : bool
public function deleteMultiple($keys): bool
{
return true;
}

/** @inheritDoc */
public function has($key) : bool
public function has($key): bool
{
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Scoutapm\Config\TypeCoercion\CoerceBoolean;
use Scoutapm\Config\TypeCoercion\CoerceJson;
use Scoutapm\Config\TypeCoercion\CoerceType;

use function array_combine;
use function array_key_exists;
use function array_map;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct()
}

/** @param mixed[]|array<string, mixed> $config */
public static function fromArray(array $config = []) : self
public static function fromArray(array $config = []): self
{
$instance = new self();

Expand Down Expand Up @@ -96,7 +97,7 @@ public function get(string $key)
*
* @param mixed $value
*/
public function set(string $key, $value) : void
public function set(string $key, $value): void
{
$this->userSettingsSource->set($key, $value);
}
Expand All @@ -109,7 +110,7 @@ public function set(string $key, $value) : void
*
* @psalm-return array<string, mixed>
*/
public function asArrayWithSecretsRemoved() : array
public function asArrayWithSecretsRemoved(): array
{
$keys = ConfigKey::allConfigurationKeys();

Expand Down
4 changes: 2 additions & 2 deletions src/Config/ConfigKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ConfigKey
private const SECRET_CONFIGURATIONS = [self::APPLICATION_KEY];

/** @return string[] */
public static function allConfigurationKeys() : array
public static function allConfigurationKeys(): array
{
return [
self::MONITORING_ENABLED,
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function allConfigurationKeys() : array
* @psalm-param array<string, mixed> $configArray
* @psalm-return array<string, mixed>
*/
public static function filterSecretsFromConfigArray(array $configArray) : array
public static function filterSecretsFromConfigArray(array $configArray): array
{
return array_combine(
array_keys($configArray),
Expand Down
2 changes: 1 addition & 1 deletion src/Config/IgnoredEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(array $ignoredPaths)
$this->ignoredPaths = $ignoredPaths;
}

public function ignored(string $url) : bool
public function ignored(string $url): bool
{
foreach ($this->ignoredPaths as $ignore) {
if (strpos($url, $ignore) === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Source/ConfigSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ConfigSource
/**
* Returns true if this config source knows for certain it has an answer for this key
*/
public function hasKey(string $key) : bool;
public function hasKey(string $key): bool;

/**
* Returns the value for this configuration key.
Expand Down
6 changes: 3 additions & 3 deletions src/Config/Source/DefaultSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Scoutapm\Config\Source;

use Scoutapm\Config\ConfigKey;

use function array_key_exists;

/** @internal */
Expand All @@ -24,8 +25,7 @@ public function __construct()
$this->defaults = $this->getDefaultConfig();
}

/** @inheritDoc */
public function hasKey(string $key) : bool
public function hasKey(string $key): bool
{
return array_key_exists($key, $this->defaults);
}
Expand All @@ -43,7 +43,7 @@ public function get(string $key)
*
* @return array<string, (string|bool|array<int, string>|int)>
*/
private function getDefaultConfig() : array
private function getDefaultConfig(): array
{
return [
ConfigKey::API_VERSION => '1.0',
Expand Down
Loading

0 comments on commit 152a503

Please sign in to comment.