Skip to content

Commit 40a576a

Browse files
authored
Merge pull request #515 from phpmetrics/update/3.x-qa
Make sure OpenMetrics format is available and upgrade QA.
2 parents 383e4bf + 8b958b8 commit 40a576a

File tree

9 files changed

+50
-58
lines changed

9 files changed

+50
-58
lines changed

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@
2929
"require": {
3030
"php": ">=8.1",
3131
"ext-tokenizer": "*",
32-
"nikic/php-parser": "^5.0"
32+
"nikic/php-parser": "^5.4",
33+
"openmetrics-php/exposition-text": "^0.4.1"
3334
},
3435
"require-dev": {
35-
"openmetrics-php/exposition-text": "^0.4.1",
36-
"phake/phake": "^4.4.0",
37-
"phpstan/extension-installer": "^1.3",
38-
"phpstan/phpstan": "^1.10",
39-
"phpstan/phpstan-deprecation-rules": "^1.1",
40-
"phpstan/phpstan-phpunit": "^1.3",
41-
"phpstan/phpstan-strict-rules": "^1.5",
36+
"phake/phake": "^4.5.3",
37+
"phpstan/extension-installer": "^1.4",
38+
"phpstan/phpstan": "^2.1",
39+
"phpstan/phpstan-deprecation-rules": "^2.0",
40+
"phpstan/phpstan-phpunit": "^2.0",
41+
"phpstan/phpstan-strict-rules": "^2.0",
4242
"phpunit/phpunit": "^10.5",
4343
"sebastian/comparator": ">=5.0.0",
44-
"squizlabs/php_codesniffer": "^3.8",
44+
"squizlabs/php_codesniffer": "^3.11",
4545
"symfony/dom-crawler": "^6.4",
46-
"roave/security-advisories": "dev-latest"
46+
"roave/security-advisories": "dev-latest",
47+
"vimeo/psalm": "^6.2"
4748
},
4849
"bin": [
4950
"bin/phpmetrics"
@@ -57,7 +58,6 @@
5758
},
5859
"suggest": {
5960
"ext-dom": "To allow XML parsing and report results.",
60-
"ext-yaml": "To allow yaml parsing of configuration files.",
61-
"openmetrics-php/exposition-text": "To allow OpenMetrics report."
61+
"ext-yaml": "To allow yaml parsing of configuration files."
6262
}
6363
}

qa/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM php:8.1-alpine
22

3-
ENV COMPOSER_VENDOR_DIR=vendor COMPOSER_CACHE_DIR=/tmp/.composer COMPOSER_ALLOW_SUPERUSER=1
3+
ENV COMPOSER_VENDOR_DIR=vendor COMPOSER_CACHE_DIR=/tmp/.composer COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_ROOT_VERSION=3.0.0
44

55
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
66

@@ -35,10 +35,10 @@ RUN apk update && \
3535
# Allow phar writing.
3636
echo 'phar.readonly=0' >> ${PHP_INI_DIR}/conf.d/docker-php-phar-readonly.ini && \
3737
# Fetching the PHP Infection from release to fetch.
38-
echo "Looking for the latest PHP Infection 0.26.x version…" && \
39-
RELEASES=$(curl -sS https://api.github.com/repos/infection/infection/releases | jq --compact-output --raw-output 'map(select( .tag_name | test("^0.26.[0-9]+$") ))') && \
38+
echo "Looking for the latest PHP Infection 0.29.x version…" && \
39+
RELEASES=$(curl -sS https://api.github.com/repos/infection/infection/releases | jq --compact-output --raw-output 'map(select( .tag_name | test("^0.29.[0-9]+$") ))') && \
4040
NB_RELEASES=$(echo "${RELEASES}" | jq --compact-output --raw-output 'length') && \
41-
if [ "${NB_RELEASES}" == "0" ]; then echo "ERROR: Not a single patch version found for minor version 0.26 of PHP Infection."; exit 1; fi && \
41+
if [ "${NB_RELEASES}" == "0" ]; then echo "ERROR: Not a single patch version found for minor version 0.29 of PHP Infection."; exit 1; fi && \
4242
LATEST_FOR_MINOR=$(echo "${RELEASES}" | jq --compact-output --raw-output '. | max_by( .tag_name | split(".") | map(tonumber) ) | {tag: .tag_name, src: .assets[]|select(.name == "infection.phar").browser_download_url}') && \
4343
INFECTION_TAG=$(echo "${LATEST_FOR_MINOR}" | jq --compact-output --raw-output '.tag') && \
4444
URL_SRC=$(echo "${LATEST_FOR_MINOR}" | jq --compact-output --raw-output '.src') && \

qa/phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ parameters:
55
tmpDir: /opt/project/qa/cache/phpstan
66
paths:
77
- ../src
8-
featureToggles:
9-
disableRuntimeReflectionProvider: true

qa/psalm-baseline.xml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
<code>stdClass</code>
1414
</MoreSpecificReturnType>
1515
</file>
16-
<file src="../src/Hal/Component/Tree/Edge.php">
17-
<ImplicitToStringCast>
18-
<code><![CDATA[$this->from]]></code>
19-
<code><![CDATA[$this->to]]></code>
20-
</ImplicitToStringCast>
21-
</file>
22-
<file src="../src/Hal/Component/Tree/Graph.php">
23-
<ImplicitToStringCast>
24-
<code>$edge</code>
25-
</ImplicitToStringCast>
26-
</file>
2716
<file src="../src/Hal/Metric/BagTrait.php">
2817
<LessSpecificImplementedReturnType>
2918
<code>array</code>
@@ -46,15 +35,26 @@
4635
</PropertyTypeCoercion>
4736
</file>
4837
<file src="../src/Hal/Metric/Class_/Coupling/ExternalsVisitor.php">
38+
<PossiblyUndefinedArrayOffset>
39+
<code><![CDATA[$resolvedClassName]]></code>
40+
</PossiblyUndefinedArrayOffset>
4941
<UndefinedPropertyFetch>
5042
<code><![CDATA[$node->class]]></code>
5143
</UndefinedPropertyFetch>
5244
</file>
5345
<file src="../src/Hal/Metric/Class_/Structural/LcomVisitor.php">
46+
<DocblockTypeContradiction>
47+
<code><![CDATA[isset($node->name)]]></code>
48+
</DocblockTypeContradiction>
5449
<UndefinedPropertyFetch>
5550
<code><![CDATA[$node->var->name]]></code>
5651
</UndefinedPropertyFetch>
5752
</file>
53+
<file src="../src/Hal/Metric/Class_/Structural/SystemComplexityVisitor.php">
54+
<InvalidOperand>
55+
<code><![CDATA[null !== $node->expr]]></code>
56+
</InvalidOperand>
57+
</file>
5858
<file src="../src/Hal/Metric/Class_/Text/HalsteadVisitor.php">
5959
<UndefinedPropertyFetch>
6060
<code><![CDATA[$node->name]]></code>
@@ -66,6 +66,11 @@
6666
<code><![CDATA[$node->value]]></code>
6767
</UndefinedPropertyFetch>
6868
</file>
69+
<file src="../src/Hal/Metric/Class_/Text/LengthVisitor.php">
70+
<InvalidOperand>
71+
<code><![CDATA[null !== $commentedCode]]></code>
72+
</InvalidOperand>
73+
</file>
6974
<file src="../src/Hal/Metric/Consolidated.php">
7075
<PropertyTypeCoercion>
7176
<code>$avg</code>
@@ -85,6 +90,11 @@
8590
<code><![CDATA[$edge->getTo()->getKey() === $node->getKey()]]></code>
8691
</InvalidOperand>
8792
</file>
93+
<file src="../src/Hal/Metric/System/Packages/Composer/Composer.php">
94+
<ReferenceConstraintViolation>
95+
<code>$packageVersion</code>
96+
</ReferenceConstraintViolation>
97+
</file>
8898
<file src="../src/Hal/Metric/System/Packages/Composer/Packagist.php">
8999
<LessSpecificReturnStatement>
90100
<code>(object)$response</code>

src/Hal/Exception/NotInstalledOpenMetricsPhpExpositionTextException.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Hal/Metric/Class_/Coupling/ExternalsVisitor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpParser\NodeVisitorAbstract;
1414
use Stringable;
1515
use function array_map;
16+
use function explode;
1617
use function in_array;
1718
use function ltrim;
1819
use function preg_match_all;
@@ -236,8 +237,9 @@ private function resolveClassName(string $classNameToResolve): null|string
236237
if ($useAlias === $classNameToResolve && !str_contains($classNameToResolve, '\\')) {
237238
return (string)$use->name;
238239
}
239-
if ($useAlias === strstr($classNameToResolve, '\\', true)) {
240-
return $use->name . strstr($classNameToResolve, '\\');
240+
[$resolvedAlias, $resolvedClassName] = explode('\\', $classNameToResolve, 2);
241+
if ($useAlias === $resolvedAlias) {
242+
return $use->name . '\\' . $resolvedClassName;
241243
}
242244
}
243245

src/Hal/Metric/System/Packages/Composer/Packagist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function get(string $package): stdClass
6767
$latest = '0.0.0';
6868

6969
foreach ((array)$json->package->versions as $version => $packageDataAtSpecificVersion) {
70-
$version = ltrim((string) $version, 'v');
70+
$version = ltrim((string)$version, 'v');
7171
if (0 === preg_match('#^(\d|\.)+$#', $version) || version_compare($version, $latest, '<')) {
7272
continue;
7373
}

src/Hal/Report/OpenMetrics/SummaryWriter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
use Hal\Application\Config\ConfigBagInterface;
77
use Hal\Component\File\WriterInterface;
8-
use Hal\Exception\NotInstalledOpenMetricsPhpExpositionTextException;
98
use Hal\Exception\NotWritableOpenMetricsReportException;
109
use Hal\Report\SummaryProvider;
1110
use OpenMetricsPhp\Exposition\Text\Collections\GaugeCollection;
1211
use OpenMetricsPhp\Exposition\Text\Metrics\Gauge;
1312
use OpenMetricsPhp\Exposition\Text\Types\MetricName;
1413

14+
use function dirname;
15+
use function implode;
16+
1517
/**
1618
* Dedicated writer that defines the content to write in a file when exporting the OpenMetrics summary of the metrics.
1719
*/
@@ -31,10 +33,6 @@ public function __construct(
3133
*/
3234
public function getReport(): string
3335
{
34-
if (!class_exists(GaugeCollection::class)) {
35-
throw NotInstalledOpenMetricsPhpExpositionTextException::notInstalled();
36-
}
37-
3836
$reportMetrics = [
3937
// LOC
4038
'lines_of_code' => [$this->sum->loc, 'Lines of code'],

tests/Component/File/SystemTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ public function testGlob(string $pattern, array|false $expectedContent): void
105105

106106
public static function tearDownAfterClass(): void
107107
{
108-
self::rm(self::getAbsoluteRandomFolderPath());
108+
$path = self::getAbsoluteRandomFolderPath();
109+
// Reset permissions on specific folder to be able to remove it.
110+
chmod($path . '/providerExists/subfolder', 0o777);
111+
112+
self::rm($path);
109113
parent::tearDownAfterClass();
110114
}
111115
}

0 commit comments

Comments
 (0)