Skip to content

Commit

Permalink
chore: cs
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Feb 29, 2024
1 parent 253474f commit 146c52b
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 34 deletions.
5 changes: 2 additions & 3 deletions examples/castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use function Castor\import;
use function Castor\io;
use function Castor\notify;
use function Castor\variable;
use function docker\about;
use function docker\build;
use function docker\docker_compose_run;
Expand All @@ -23,9 +22,9 @@ function create_default_variables(): array
{
return [
'project_name' => 'symfony-metrics',
'root_domain' => "symfony-metrics.test",
'root_domain' => 'symfony-metrics.test',
'extra_domains' => [
"grafana.symfony-metrics.test",
'grafana.symfony-metrics.test',
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions examples/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
}
2 changes: 1 addition & 1 deletion examples/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
Expand Down
4 changes: 2 additions & 2 deletions examples/src/Controller/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
class HomepageController extends AbstractController
{
public function __construct(
#[Target("null")]
#[Target('null')]
private CollectorInterface $collector2,
#[Target("null2")]
#[Target('null2')]
private CollectorInterface $collector,
) {
}
Expand Down
8 changes: 4 additions & 4 deletions examples/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';
require dirname(__DIR__) . '/vendor/autoload.php';

if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
require dirname(__DIR__).'/config/bootstrap.php';
if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
require dirname(__DIR__) . '/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
}
7 changes: 6 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Variable \\$name might not be defined\\.$#"
message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, Closure\\(\\)\\: null given\\.$#"
count: 1
path: src/Metrics/Utils/Box.php

-
message: "#^Cannot access offset 'null' on 0\\|0\\.0\\|''\\|'0'\\|array\\{\\}\\|false\\|null\\.$#"
count: 1
path: src/MetricsBundle/DependencyInjection/BeberleiMetricsExtension.php

Expand Down
1 change: 0 additions & 1 deletion src/Metrics/Collector/DogStatsD.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function flush(): void

private function doFlush(): void
{

$fp = fsockopen('udp://' . $this->host, $this->port, $errno, $errstr, 1.0);

if (!$fp) {
Expand Down
20 changes: 10 additions & 10 deletions src/Metrics/Collector/Graphite.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function flush(): void
Box::box($this->doFlush(...));
}

public function push(string $variable, int|float $value, ?int $time = null): void
{
$this->data[] = sprintf(
\is_float($value) ? "%s %.18f %d\n" : "%s %d %d\n",
$variable,
$value,
$time ?: time()
);
}

private function doFlush(): void
{
$fp = fsockopen($this->protocol . '://' . $this->host, $this->port);
Expand All @@ -74,14 +84,4 @@ private function doFlush(): void

$this->data = [];
}

public function push(string $variable, int|float $value, ?int $time = null): void
{
$this->data[] = sprintf(
\is_float($value) ? "%s %.18f %d\n" : "%s %d %d\n",
$variable,
$value,
$time ?: time()
);
}
}
13 changes: 6 additions & 7 deletions src/Metrics/Collector/Telegraf.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ public function flush(): void
Box::box($this->doFlush(...));
}

private function doFlush(): void
public function setTags(array $tags): void
{
$this->tags = http_build_query($tags, '', ',');
$this->tags = \strlen($this->tags) > 0 ? ',' . $this->tags : $this->tags;
}

private function doFlush(): void
{
$fp = fsockopen('udp://' . $this->host, $this->port, $errno, $errstr, 1.0);

if (!$fp) {
Expand All @@ -88,10 +93,4 @@ private function doFlush(): void

$this->data = [];
}

public function setTags(array $tags): void
{
$this->tags = http_build_query($tags, '', ',');
$this->tags = \strlen($this->tags) > 0 ? ',' . $this->tags : $this->tags;
}
}
2 changes: 2 additions & 0 deletions src/Metrics/Utils/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public static function box(callable $callable): mixed
} finally {
restore_error_handler();
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function load(array $configs, ContainerBuilder $container): void
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('metrics.xml');


if (!$config['collectors']) {
$config['collectors']['null'] = [
'type' => 'null',
Expand All @@ -38,7 +37,7 @@ public function load(array $configs, ContainerBuilder $container): void
throw new InvalidArgumentException(sprintf('The default collector "%s" does not exist.', $config['default']));
}
$name = $config['default'];
} else if (1 === count($config['collectors'])) {
} elseif (1 === \count($config['collectors'])) {
$name = key($config['collectors']);
} else {
throw new InvalidArgumentException('No default collector is configured and there is more than one collector. Please define a default collector');
Expand Down
2 changes: 1 addition & 1 deletion src/MetricsBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('type')
->isRequired()
->validate()
->ifTrue(static fn ($v) => !is_string($v))
->ifTrue(static fn ($v) => !\is_string($v))
->thenInvalid('The type must be a string got "%s".')
->end()

Expand Down

0 comments on commit 146c52b

Please sign in to comment.