Skip to content
Snippets Groups Projects
Commit 609a7a94 authored by David Prévot's avatar David Prévot
Browse files

New upstream version 3.0.1

parents 5d7e5a50 d36ad0d7
No related branches found
No related tags found
No related merge requests found
......@@ -31,8 +31,8 @@ jobs:
- name: Run PHP-CS-Fixer
run: ./tools/php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose
type-checker:
name: Type Checker
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
......@@ -49,8 +49,8 @@ jobs:
- name: Install dependencies with Composer
run: ./tools/composer update --no-interaction --no-ansi --no-progress
- name: Run Psalm
run: ./tools/psalm --config=.psalm/config.xml --no-progress --shepherd --show-info=false --stats
- name: Run PHPStan
run: ./tools/phpstan analyse --no-progress --error-format=github
tests:
name: Tests
......
# https://docs.github.com/en/actions
on:
push:
tags:
- "**"
name: Release
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
extensions: none
tools: none
- name: Determine tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Parse ChangeLog
run: build/scripts/extract-release-notes.php ${{ env.RELEASE_TAG }} > release-notes.md
- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.RELEASE_TAG }}
name: sebastian/lines-of-code ${{ env.RELEASE_TAG }}
bodyFile: release-notes.md
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.0" installed="3.41.1" location="./tools/php-cs-fixer" copy="true"/>
<phar name="psalm" version="^5.0" installed="5.18.0" location="./tools/psalm" copy="true"/>
<phar name="infection" version="^0.24" installed="0.24.0" location="./tools/infection" copy="true"/>
<phar name="composer" version="^2.0.3" installed="2.6.6" location="./tools/composer" copy="true"/>
<phar name="php-cs-fixer" version="^3.59" installed="3.59.3" location="./tools/php-cs-fixer" copy="true"/>
<phar name="infection" version="^0.29" installed="0.29.6" location="./tools/infection" copy="true"/>
<phar name="composer" version="^2.7" installed="2.7.7" location="./tools/composer" copy="true"/>
<phar name="phpstan" version="^1.11" installed="1.11.5" location="./tools/phpstan" copy="true"/>
</phive>
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@"/>
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
resolveFromConfigFile="false"
errorBaseline=".psalm/baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
......@@ -2,6 +2,12 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [3.0.1] - 2024-07-03
### Changed
* This project now uses PHPStan instead of Psalm for static analysis
## [3.0.0] - 2024-02-02
### Removed
......@@ -53,6 +59,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[3.0.1]: https://github.com/sebastianbergmann/lines-of-code/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/2.0...3.0.0
[2.0.2]: https://github.com/sebastianbergmann/lines-of-code/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/sebastianbergmann/lines-of-code/compare/2.0.0...2.0.1
......
[![Latest Stable Version](https://poser.pugx.org/sebastian/lines-of-code/v/stable.png)](https://packagist.org/packages/sebastian/lines-of-code)
[![CI Status](https://github.com/sebastianbergmann/lines-of-code/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/lines-of-code/actions)
[![Type Coverage](https://shepherd.dev/github/sebastianbergmann/lines-of-code/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/lines-of-code)
[![codecov](https://codecov.io/gh/sebastianbergmann/lines-of-code/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/lines-of-code)
# sebastian/lines-of-code
......
#!/usr/bin/env php
<?php declare(strict_types=1);
if ($argc !== 2) {
print $argv[0] . ' <tag>' . PHP_EOL;
exit(1);
}
$version = $argv[1];
$file = __DIR__ . '/../../ChangeLog.md';
if (!is_file($file) || !is_readable($file)) {
print $file . ' cannot be read' . PHP_EOL;
exit(1);
}
$buffer = '';
$append = false;
foreach (file($file) as $line) {
if (str_starts_with($line, '## [' . $version . ']')) {
$append = true;
continue;
}
if ($append && (str_starts_with($line, '## ') || str_starts_with($line, '['))) {
break;
}
if ($append) {
$buffer .= $line;
}
}
$buffer = trim($buffer);
if ($buffer === '') {
print 'Unable to extract release notes' . PHP_EOL;
exit(1);
}
print $buffer . PHP_EOL;
parameters:
level: 9
paths:
- src
- tests/unit
- tests/integration
ignoreErrors:
-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\LinesOfCode\\\\LineCountingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
count: 1
path: src/LineCountingVisitor.php
-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\LinesOfCode\\\\LineCountingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
count: 1
path: src/LineCountingVisitor.php
......@@ -11,12 +11,16 @@
failOnWarning="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
<source>
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
......
......@@ -24,7 +24,11 @@ final class Counter
*/
public function countInSourceFile(string $sourceFile): LinesOfCode
{
return $this->countInSourceString(file_get_contents($sourceFile));
$source = file_get_contents($sourceFile);
assert($source !== false);
return $this->countInSourceString($source);
}
/**
......@@ -38,8 +42,6 @@ final class Counter
$linesOfCode = 1;
}
assert($linesOfCode >= 0);
try {
$nodes = (new ParserFactory)->createForHostVersion()->parse($source);
......@@ -59,9 +61,8 @@ final class Counter
}
/**
* @psalm-param non-negative-int $linesOfCode
*
* @param Node[] $nodes
* @param non-negative-int $linesOfCode
* @param Node[] $nodes
*
* @throws RuntimeException
*/
......
......@@ -21,7 +21,7 @@ use PhpParser\NodeVisitorAbstract;
final class LineCountingVisitor extends NodeVisitorAbstract
{
/**
* @psalm-var non-negative-int
* @var non-negative-int
*/
private readonly int $linesOfCode;
......@@ -36,7 +36,7 @@ final class LineCountingVisitor extends NodeVisitorAbstract
private array $linesWithStatements = [];
/**
* @psalm-param non-negative-int $linesOfCode
* @param non-negative-int $linesOfCode
*/
public function __construct(int $linesOfCode)
{
......@@ -67,7 +67,6 @@ final class LineCountingVisitor extends NodeVisitorAbstract
assert($commentLinesOfCode >= 0);
assert($nonCommentLinesOfCode >= 0);
assert($logicalLinesOfCode >= 0);
return new LinesOfCode(
$this->linesOfCode,
......
......@@ -10,57 +10,57 @@
namespace SebastianBergmann\LinesOfCode;
/**
* @psalm-immutable
* @immutable
*/
final readonly class LinesOfCode
{
/**
* @psalm-var non-negative-int
* @var non-negative-int
*/
private int $linesOfCode;
/**
* @psalm-var non-negative-int
* @var non-negative-int
*/
private int $commentLinesOfCode;
/**
* @psalm-var non-negative-int
* @var non-negative-int
*/
private int $nonCommentLinesOfCode;
/**
* @psalm-var non-negative-int
* @var non-negative-int
*/
private int $logicalLinesOfCode;
/**
* @psalm-param non-negative-int $linesOfCode
* @psalm-param non-negative-int $commentLinesOfCode
* @psalm-param non-negative-int $nonCommentLinesOfCode
* @psalm-param non-negative-int $logicalLinesOfCode
* @param non-negative-int $linesOfCode
* @param non-negative-int $commentLinesOfCode
* @param non-negative-int $nonCommentLinesOfCode
* @param non-negative-int $logicalLinesOfCode
*
* @throws IllogicalValuesException
* @throws NegativeValueException
*/
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
{
/** @psalm-suppress DocblockTypeContradiction */
/** @phpstan-ignore smaller.alwaysFalse */
if ($linesOfCode < 0) {
throw new NegativeValueException('$linesOfCode must not be negative');
}
/** @psalm-suppress DocblockTypeContradiction */
/** @phpstan-ignore smaller.alwaysFalse */
if ($commentLinesOfCode < 0) {
throw new NegativeValueException('$commentLinesOfCode must not be negative');
}
/** @psalm-suppress DocblockTypeContradiction */
/** @phpstan-ignore smaller.alwaysFalse */
if ($nonCommentLinesOfCode < 0) {
throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
}
/** @psalm-suppress DocblockTypeContradiction */
/** @phpstan-ignore smaller.alwaysFalse */
if ($logicalLinesOfCode < 0) {
throw new NegativeValueException('$logicalLinesOfCode must not be negative');
}
......@@ -76,7 +76,7 @@ final readonly class LinesOfCode
}
/**
* @psalm-return non-negative-int
* @return non-negative-int
*/
public function linesOfCode(): int
{
......@@ -84,7 +84,7 @@ final readonly class LinesOfCode
}
/**
* @psalm-return non-negative-int
* @return non-negative-int
*/
public function commentLinesOfCode(): int
{
......@@ -92,7 +92,7 @@ final readonly class LinesOfCode
}
/**
* @psalm-return non-negative-int
* @return non-negative-int
*/
public function nonCommentLinesOfCode(): int
{
......@@ -100,7 +100,7 @@ final readonly class LinesOfCode
}
/**
* @psalm-return non-negative-int
* @return non-negative-int
*/
public function logicalLinesOfCode(): int
{
......
......@@ -33,7 +33,11 @@ final class CounterTest extends TestCase
public function testCountsLinesOfCodeInSourceString(): void
{
$count = (new Counter)->countInSourceString(file_get_contents(__DIR__ . '/../_fixture/ExampleClass.php'));
$source = file_get_contents(__DIR__ . '/../_fixture/ExampleClass.php');
assert($source !== false);
$count = (new Counter)->countInSourceString($source);
$this->assertSame(43, $count->linesOfCode());
$this->assertSame(5, $count->commentLinesOfCode());
......@@ -43,9 +47,11 @@ final class CounterTest extends TestCase
public function testCountsLinesOfCodeInAbstractSyntaxTree(): void
{
$nodes = (new ParserFactory)->createForHostVersion()->parse(
file_get_contents(__DIR__ . '/../_fixture/ExampleClass.php'),
);
$source = file_get_contents(__DIR__ . '/../_fixture/ExampleClass.php');
assert($source !== false);
$nodes = (new ParserFactory)->createForHostVersion()->parse($source);
assert($nodes !== null);
......
......@@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\LinesOfCode;
use function assert;
use function file_get_contents;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
......@@ -23,6 +24,9 @@ use PHPUnit\Framework\TestCase;
#[Small]
final class LineCountingVisitorTest extends TestCase
{
/**
* @return non-empty-list<array{0: non-empty-string, 1: positive-int, 2: int, 3: int, 4: int}>
*/
public static function provideData(): array
{
return [
......@@ -50,12 +54,23 @@ final class LineCountingVisitorTest extends TestCase
];
}
/**
* @param non-empty-string $sourceFile
* @param positive-int $linesOfCode
* @param non-negative-int $commentLinesOfCode
* @param non-negative-int $nonCommentLinesOfCode
* @param non-negative-int $logicalLinesOfCode
*/
#[DataProvider('provideData')]
public function testCountsLinesOfCodeInAbstractSyntaxTree(string $sourceFile, int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode): void
{
$nodes = (new ParserFactory)->createForHostVersion()->parse(
file_get_contents($sourceFile),
);
$source = file_get_contents($sourceFile);
assert($source !== false);
$nodes = (new ParserFactory)->createForHostVersion()->parse($source);
assert($nodes !== null);
$traverser = new NodeTraverser;
......
......@@ -47,6 +47,7 @@ final class LinesOfCodeTest extends TestCase
$this->expectException(NegativeValueException::class);
$this->expectExceptionMessage('$linesOfCode must not be negative');
/** @phpstan-ignore argument.type */
new LinesOfCode(-1, 0, 0, 0);
}
......@@ -55,6 +56,7 @@ final class LinesOfCodeTest extends TestCase
$this->expectException(NegativeValueException::class);
$this->expectExceptionMessage('$commentLinesOfCode must not be negative');
/** @phpstan-ignore argument.type */
new LinesOfCode(0, -1, 0, 0);
}
......@@ -63,6 +65,7 @@ final class LinesOfCodeTest extends TestCase
$this->expectException(NegativeValueException::class);
$this->expectExceptionMessage('$nonCommentLinesOfCode must not be negative');
/** @phpstan-ignore argument.type */
new LinesOfCode(0, 0, -1, 0);
}
......@@ -71,6 +74,7 @@ final class LinesOfCodeTest extends TestCase
$this->expectException(NegativeValueException::class);
$this->expectExceptionMessage('$logicalLinesOfCode must not be negative');
/** @phpstan-ignore argument.type */
new LinesOfCode(0, 0, 0, -1);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment