composer update
This commit is contained in:
+14
@@ -2,6 +2,18 @@
|
||||
|
||||
All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
|
||||
|
||||
## [2.0.2] - 2023-12-21
|
||||
|
||||
### Changed
|
||||
|
||||
* This component is now compatible with `nikic/php-parser` 5.0
|
||||
|
||||
## [2.0.1] - 2023-08-31
|
||||
|
||||
### Changed
|
||||
|
||||
* Improved type information
|
||||
|
||||
## [2.0.0] - 2023-02-03
|
||||
|
||||
### Removed
|
||||
@@ -34,6 +46,8 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
|
||||
|
||||
* Initial release
|
||||
|
||||
[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
|
||||
[2.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/1.0.3...2.0.0
|
||||
[1.0.3]: https://github.com/sebastianbergmann/lines-of-code/compare/1.0.2...1.0.3
|
||||
[1.0.2]: https://github.com/sebastianbergmann/lines-of-code/compare/1.0.1...1.0.2
|
||||
|
||||
+25
-4
@@ -1,9 +1,30 @@
|
||||
# Security Policy
|
||||
|
||||
This library is intended to be used in development environments only. For instance, it is used by the testing framework PHPUnit. There is no reason why this library should be installed on a webserver.
|
||||
If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure.
|
||||
|
||||
**If you upload this library to a webserver then your deployment process is broken. On a more general note, if your `vendor` directory is publicly accessible on your webserver then your deployment process is also broken.**
|
||||
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
|
||||
|
||||
## Security Contact Information
|
||||
Instead, please email `sebastian@phpunit.de`.
|
||||
|
||||
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
|
||||
|
||||
* The type of issue
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
## Web Context
|
||||
|
||||
The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit.
|
||||
|
||||
The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in an HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes.
|
||||
|
||||
If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context.
|
||||
|
||||
Vulnerabilities specific to the use outside a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes.
|
||||
|
||||
After the above, if you still would like to report a security vulnerability, please email `sebastian@phpunit.de`.
|
||||
|
||||
+3
-2
@@ -12,12 +12,13 @@
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues"
|
||||
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
|
||||
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy"
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"nikic/php-parser": "^4.10"
|
||||
"nikic/php-parser": "^4.18 || ^5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.0"
|
||||
|
||||
+7
-10
@@ -13,10 +13,8 @@ use function assert;
|
||||
use function file_get_contents;
|
||||
use function substr_count;
|
||||
use PhpParser\Error;
|
||||
use PhpParser\Lexer;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\Parser;
|
||||
use PhpParser\ParserFactory;
|
||||
|
||||
final class Counter
|
||||
@@ -40,8 +38,10 @@ final class Counter
|
||||
$linesOfCode = 1;
|
||||
}
|
||||
|
||||
assert($linesOfCode >= 0);
|
||||
|
||||
try {
|
||||
$nodes = $this->parser()->parse($source);
|
||||
$nodes = (new ParserFactory)->createForHostVersion()->parse($source);
|
||||
|
||||
assert($nodes !== null);
|
||||
|
||||
@@ -52,13 +52,15 @@ final class Counter
|
||||
throw new RuntimeException(
|
||||
$error->getMessage(),
|
||||
$error->getCode(),
|
||||
$error
|
||||
$error,
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param non-negative-int $linesOfCode
|
||||
*
|
||||
* @param Node[] $nodes
|
||||
*
|
||||
* @throws RuntimeException
|
||||
@@ -78,16 +80,11 @@ final class Counter
|
||||
throw new RuntimeException(
|
||||
$error->getMessage(),
|
||||
$error->getCode(),
|
||||
$error
|
||||
$error,
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $visitor->result();
|
||||
}
|
||||
|
||||
private function parser(): Parser
|
||||
{
|
||||
return (new ParserFactory)->create(ParserFactory::PREFER_PHP7, new Lexer);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -11,6 +11,7 @@ namespace SebastianBergmann\LinesOfCode;
|
||||
|
||||
use function array_merge;
|
||||
use function array_unique;
|
||||
use function assert;
|
||||
use function count;
|
||||
use PhpParser\Comment;
|
||||
use PhpParser\Node;
|
||||
@@ -19,7 +20,10 @@ use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
final class LineCountingVisitor extends NodeVisitorAbstract
|
||||
{
|
||||
private int $linesOfCode;
|
||||
/**
|
||||
* @psalm-var non-negative-int
|
||||
*/
|
||||
private readonly int $linesOfCode;
|
||||
|
||||
/**
|
||||
* @var Comment[]
|
||||
@@ -31,6 +35,9 @@ final class LineCountingVisitor extends NodeVisitorAbstract
|
||||
*/
|
||||
private array $linesWithStatements = [];
|
||||
|
||||
/**
|
||||
* @psalm-param non-negative-int $linesOfCode
|
||||
*/
|
||||
public function __construct(int $linesOfCode)
|
||||
{
|
||||
$this->linesOfCode = $linesOfCode;
|
||||
@@ -55,11 +62,18 @@ final class LineCountingVisitor extends NodeVisitorAbstract
|
||||
$commentLinesOfCode += ($comment->getEndLine() - $comment->getStartLine() + 1);
|
||||
}
|
||||
|
||||
$nonCommentLinesOfCode = $this->linesOfCode - $commentLinesOfCode;
|
||||
$logicalLinesOfCode = count(array_unique($this->linesWithStatements));
|
||||
|
||||
assert($commentLinesOfCode >= 0);
|
||||
assert($nonCommentLinesOfCode >= 0);
|
||||
assert($logicalLinesOfCode >= 0);
|
||||
|
||||
return new LinesOfCode(
|
||||
$this->linesOfCode,
|
||||
$commentLinesOfCode,
|
||||
$this->linesOfCode - $commentLinesOfCode,
|
||||
count(array_unique($this->linesWithStatements))
|
||||
$nonCommentLinesOfCode,
|
||||
$logicalLinesOfCode,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+40
-4
@@ -14,29 +14,53 @@ namespace SebastianBergmann\LinesOfCode;
|
||||
*/
|
||||
final class LinesOfCode
|
||||
{
|
||||
private int $linesOfCode;
|
||||
private int $commentLinesOfCode;
|
||||
private int $nonCommentLinesOfCode;
|
||||
private int $logicalLinesOfCode;
|
||||
/**
|
||||
* @psalm-var non-negative-int
|
||||
*/
|
||||
private readonly int $linesOfCode;
|
||||
|
||||
/**
|
||||
* @psalm-var non-negative-int
|
||||
*/
|
||||
private readonly int $commentLinesOfCode;
|
||||
|
||||
/**
|
||||
* @psalm-var non-negative-int
|
||||
*/
|
||||
private readonly int $nonCommentLinesOfCode;
|
||||
|
||||
/**
|
||||
* @psalm-var non-negative-int
|
||||
*/
|
||||
private readonly 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
|
||||
*
|
||||
* @throws IllogicalValuesException
|
||||
* @throws NegativeValueException
|
||||
*/
|
||||
public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
|
||||
{
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if ($linesOfCode < 0) {
|
||||
throw new NegativeValueException('$linesOfCode must not be negative');
|
||||
}
|
||||
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if ($commentLinesOfCode < 0) {
|
||||
throw new NegativeValueException('$commentLinesOfCode must not be negative');
|
||||
}
|
||||
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if ($nonCommentLinesOfCode < 0) {
|
||||
throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
|
||||
}
|
||||
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if ($logicalLinesOfCode < 0) {
|
||||
throw new NegativeValueException('$logicalLinesOfCode must not be negative');
|
||||
}
|
||||
@@ -51,21 +75,33 @@ final class LinesOfCode
|
||||
$this->logicalLinesOfCode = $logicalLinesOfCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-negative-int
|
||||
*/
|
||||
public function linesOfCode(): int
|
||||
{
|
||||
return $this->linesOfCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-negative-int
|
||||
*/
|
||||
public function commentLinesOfCode(): int
|
||||
{
|
||||
return $this->commentLinesOfCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-negative-int
|
||||
*/
|
||||
public function nonCommentLinesOfCode(): int
|
||||
{
|
||||
return $this->nonCommentLinesOfCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-negative-int
|
||||
*/
|
||||
public function logicalLinesOfCode(): int
|
||||
{
|
||||
return $this->logicalLinesOfCode;
|
||||
|
||||
Reference in New Issue
Block a user