Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .circleci/config.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 🏗 Build

on:
pull_request:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
prefer_lowest: ["", "--prefer-lowest"]
php: ["8.2", "8.5"]
container:
image: skpr/php-cli:${{ matrix.php }}-dev-v2-stable
options:
--pull always
--user 1001:1001
steps:
- name: Checkout
uses: actions/checkout@v6
with:
show-progress: false
- name: Composer Update
run: composer update --with-all-dependencies --prefer-dist --no-progress --no-interaction ${{ matrix.prefer_lowest }}
- name: PHPCS
# Convert emacs format (file:line:col: severity - message) to GitHub annotations (::severity file=,line=,col=::message)
run: |
./bin/phpcs --report=emacs -q | sed -E 's/^([^:]+):([0-9]+):([0-9]+): (error|warning) - (.*)$/::\4 file=\1,line=\2,col=\3::\5/' || true
./bin/phpcs --report=full
- name: PHPStan
run: ./bin/phpstan --error-format=github analyse
- name: Add PHPUnit matcher
run: |
cat << 'EOF' > .github/phpunit-failure.json
{"problemMatcher":[{"owner":"phpunit-failure","severity":"error","pattern":[{"regexp":"##teamcity\\[testFailed[^\\]]*message='([^']*)'[^\\]]*details='/data/([^:]+):(\\d+)","message":1,"file":2,"line":3}]}]}
EOF
echo "::add-matcher::.github/phpunit-failure.json"
- name: Run Tests
run: ./bin/phpunit --teamcity
- name: Remove PHPUnit matcher
if: always()
run: echo "::remove-matcher owner=phpunit-failure::"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin
/vendor
/composer.lock
.phpunit.cache
.phpunit.result.cache
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-json": "*",
"symfony/property-access": "^5.4|^6.2|^7.1",
"symfony/serializer": "^5.4|^6.2|^7.1"
"symfony/property-access": "^6.4.32|^7.4.8|^8.0.8",
"symfony/serializer": "^6.4.32|^7.4.8|^8.0.10"
},
"require-dev": {
"drupal/coder": "^8.3.16",
"phpunit/phpunit": "^9.5.28",
"phpspec/prophecy": "^1.16",
"symfony/phpunit-bridge": "^5.4|^6.2|^7.1"
"drupal/coder": "^9.0.0",
"phpspec/prophecy": "^1.26.1",
"phpstan/phpstan": "^2.1.55",
"phpunit/phpunit": "^11.5.55"
},
"autoload": {
"psr-4": {"PNX\\Prometheus\\": "src/"}
Expand Down
20 changes: 1 addition & 19 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="php-prometheus">
<description>PHP CodeSniffer configuration for PHP Prometheus</description>
<!-- folders to scan -->
<file>./src</file>
<file>./tests</file>
<!-- extensions to scan -->
<arg name="extensions" value="php"/>
<!-- additional arguments -->
<arg name="report" value="full"/>
<!-- inherit from coder -->
<rule ref="./vendor/drupal/coder/coder_sniffer/Drupal"/>
<!-- Additional detailed sniff configuration -->
<!-- You can determine sniff names by running with -s flag -->
<!-- Example 1 - ignore Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
<rule ref="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps">
<severity>0</severity>
</rule>
// End example 1 -->
<!-- Example 2 - ignore rule for specific files
<rule ref="Drupal.NamingConventions.ValidVariableName.LowerCamelName">
<exclude-pattern>OfferNormalizerTrait.php</exclude-pattern>
<exclude-pattern>TimeOfUseValidationTrait.php</exclude-pattern>
</rule>
// End example 2 -->
<rule ref="Drupal"/>
</ruleset>
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 6
paths:
- src
- tests
36 changes: 13 additions & 23 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory suffix="Test.php">./</directory>
<directory suffix="TestBase.php">./</directory>
</exclude>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<const name="BOOTSTRAP_IS_PHPUNIT" value="true"/>
</php>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
11 changes: 8 additions & 3 deletions src/Counter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PNX\Prometheus;

/**
Expand All @@ -24,10 +26,13 @@ public function getType(): string {
*
* @param mixed $value
* The value.
* @param array $labels
* @param array<string, string|int|float> $labels
* The list of key value label pairs.
*
* @throws \InvalidArgumentException
* If the value is not a non-negative integer.
*/
public function set($value, array $labels = []) {
public function set(mixed $value, array $labels = []): void {
if (!$this->isValidValue($value)) {
throw new \InvalidArgumentException("A count value must be a positive integer.");
}
Comment thread
kimpepper marked this conversation as resolved.
Expand All @@ -44,7 +49,7 @@ public function set($value, array $labels = []) {
* @return bool
* TRUE if the value is valid. FALSE otherwise.
*/
protected function isValidValue($value) {
protected function isValidValue(mixed $value): bool {
return is_int($value) && $value >= 0;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Gauge.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PNX\Prometheus;

/**
Expand All @@ -24,10 +26,10 @@ public function getType(): string {
*
* @param mixed $value
* The value.
* @param array $labels
* @param array<string, string|int|float> $labels
* The list of key value label pairs.
*/
public function set($value, array $labels = []) {
public function set(mixed $value, array $labels = []): void {
$key = $this->getKey($labels);
$this->labelledValues[$key] = new LabelledValue($this->getName(), $value, $labels);
}
Expand Down
29 changes: 15 additions & 14 deletions src/LabelledValue.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PNX\Prometheus;

/**
Expand All @@ -14,24 +16,20 @@ class LabelledValue {

/**
* The metric value.
*
* @var mixed
*/
protected $value;
protected mixed $value;

/**
* The key value pairs of labels.
*
* @var array
* @var array<string, string|int|float>
*/
protected $labels;
protected array $labels;

/**
* The name override for this labelled value.
*
* @var string
*/
protected $name;
protected string $name;

/**
* Value constructor.
Expand All @@ -40,10 +38,13 @@ class LabelledValue {
* The name override for this label.
* @param mixed $value
* The metric value.
* @param array[] $labels
* @param array<string, string|int|float> $labels
* The key value pairs of labels.
*
* @throws \InvalidArgumentException
* If the name or label names are invalid.
*/
public function __construct($name, $value, array $labels = []) {
public function __construct(string $name, mixed $value, array $labels = []) {
$this->value = $value;
foreach ($labels as $labelKey => $labelValue) {
if (!preg_match(self::LABEL_NAME_REGEX, $labelKey)) {
Expand All @@ -63,14 +64,14 @@ public function __construct($name, $value, array $labels = []) {
* @return mixed
* The Value.
*/
public function getValue() {
public function getValue(): mixed {
return $this->value;
}

/**
* Gets the Labels.
*
* @return array[]
* @return array<string, string|int|float>
* The Labels.
*/
public function getLabels(): array {
Expand All @@ -80,10 +81,10 @@ public function getLabels(): array {
/**
* Gets the Name override.
*
* @return null|string
* @return string
* The Name.
*/
public function getName() {
public function getName(): string {
return $this->name;
}

Expand Down
Loading