This commit is contained in:
2025-02-04 12:40:43 +03:00
parent 4bcb4c60dd
commit 50343d5a87
372 changed files with 9019 additions and 6684 deletions

View File

@@ -2,12 +2,6 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [4.0.0] - 2025-02-07
### Removed
* This component is no longer supported on PHP 8.2
## [3.0.1] - 2024-07-03
### Changed
@@ -65,7 +59,6 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release
[4.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/3.0...main
[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

View File

@@ -1,6 +1,6 @@
BSD 3-Clause License
Copyright (c) 2020-2025, Sebastian Bergmann
Copyright (c) 2020-2024, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,4 +1,4 @@
[![Latest Stable Version](https://poser.pugx.org/sebastian/lines-of-code/v)](https://packagist.org/packages/sebastian/lines-of-code)
[![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)
[![codecov](https://codecov.io/gh/sebastianbergmann/lines-of-code/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/lines-of-code)

View File

@@ -15,18 +15,17 @@
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.3",
"php": ">=8.2",
"nikic/php-parser": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^12.0-dev"
"phpunit/phpunit": "^11.0"
},
"config": {
"platform": {
"php": "8.3"
"php": "8.2"
},
"optimize-autoloader": true,
"sort-packages": true
@@ -38,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "4.0-dev"
"dev-main": "3.0-dev"
}
}
}

View File

@@ -48,6 +48,7 @@ final class Counter
assert($nodes !== null);
return $this->countInAbstractSyntaxTree($linesOfCode, $nodes);
// @codeCoverageIgnoreStart
} catch (Error $error) {
throw new RuntimeException(

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/lines-of-code.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\LinesOfCode;
use InvalidArgumentException;
final class NegativeValueException extends InvalidArgumentException implements Exception
{
}

View File

@@ -43,17 +43,15 @@ final class LineCountingVisitor extends NodeVisitorAbstract
$this->linesOfCode = $linesOfCode;
}
public function enterNode(Node $node): null
public function enterNode(Node $node): void
{
$this->comments = array_merge($this->comments, $node->getComments());
if (!$node instanceof Expr) {
return null;
return;
}
$this->linesWithStatements[] = $node->getStartLine();
return null;
}
public function result(): LinesOfCode

View File

@@ -41,9 +41,30 @@ final readonly class LinesOfCode
* @param non-negative-int $logicalLinesOfCode
*
* @throws IllogicalValuesException
* @throws NegativeValueException
*/
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
{
/** @phpstan-ignore smaller.alwaysFalse */
if ($linesOfCode < 0) {
throw new NegativeValueException('$linesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($commentLinesOfCode < 0) {
throw new NegativeValueException('$commentLinesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($nonCommentLinesOfCode < 0) {
throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
}
/** @phpstan-ignore smaller.alwaysFalse */
if ($logicalLinesOfCode < 0) {
throw new NegativeValueException('$logicalLinesOfCode must not be negative');
}
if ($linesOfCode - $commentLinesOfCode !== $nonCommentLinesOfCode) {
throw new IllogicalValuesException('$linesOfCode !== $commentLinesOfCode + $nonCommentLinesOfCode');
}