summaryrefslogtreecommitdiff
path: root/vendor/sebastian/lines-of-code
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-03-22 12:24:31 +0300
committerAndrew Dolgov <[email protected]>2022-03-22 12:24:31 +0300
commit1c4f7ab3b838b23afb2ee4dab14acbf75956e952 (patch)
tree0a19274107d717efe92d2c0376cd3105fead5a11 /vendor/sebastian/lines-of-code
parent711662948768492e8d05b778a7d80eacaec368d2 (diff)
* add phpunit as a dev dependency
* add some basic tests for UrlHelper::rewrite_relative() * fix UrlHelper::rewrite_relative() to work better on non-absolute relative URL paths
Diffstat (limited to 'vendor/sebastian/lines-of-code')
-rw-r--r--vendor/sebastian/lines-of-code/.psalm/baseline.xml2
-rw-r--r--vendor/sebastian/lines-of-code/.psalm/config.xml16
-rw-r--r--vendor/sebastian/lines-of-code/ChangeLog.md34
-rw-r--r--vendor/sebastian/lines-of-code/LICENSE33
-rw-r--r--vendor/sebastian/lines-of-code/README.md22
-rw-r--r--vendor/sebastian/lines-of-code/composer.json42
-rw-r--r--vendor/sebastian/lines-of-code/src/Counter.php91
-rw-r--r--vendor/sebastian/lines-of-code/src/Exception/Exception.php16
-rw-r--r--vendor/sebastian/lines-of-code/src/Exception/IllogicalValuesException.php16
-rw-r--r--vendor/sebastian/lines-of-code/src/Exception/NegativeValueException.php16
-rw-r--r--vendor/sebastian/lines-of-code/src/Exception/RuntimeException.php14
-rw-r--r--vendor/sebastian/lines-of-code/src/LineCountingVisitor.php82
-rw-r--r--vendor/sebastian/lines-of-code/src/LinesOfCode.php98
13 files changed, 482 insertions, 0 deletions
diff --git a/vendor/sebastian/lines-of-code/.psalm/baseline.xml b/vendor/sebastian/lines-of-code/.psalm/baseline.xml
new file mode 100644
index 000000000..77e688e07
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/.psalm/baseline.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<files psalm-version="4.0.1@b1e2e30026936ef8d5bf6a354d1c3959b6231f44"/>
diff --git a/vendor/sebastian/lines-of-code/.psalm/config.xml b/vendor/sebastian/lines-of-code/.psalm/config.xml
new file mode 100644
index 000000000..15abef058
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/.psalm/config.xml
@@ -0,0 +1,16 @@
+<?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"
+ totallyTyped="true"
+ errorBaseline=".psalm/baseline.xml"
+>
+ <projectFiles>
+ <directory name="src" />
+ <ignoreFiles>
+ <directory name="vendor" />
+ </ignoreFiles>
+ </projectFiles>
+</psalm>
diff --git a/vendor/sebastian/lines-of-code/ChangeLog.md b/vendor/sebastian/lines-of-code/ChangeLog.md
new file mode 100644
index 000000000..39bcaad49
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/ChangeLog.md
@@ -0,0 +1,34 @@
+# ChangeLog
+
+All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
+
+## [1.0.3] - 2020-11-28
+
+### Fixed
+
+* Files that do not contain a newline were not handled correctly
+
+### Changed
+
+* A line of code is no longer considered to be a Logical Line of Code if it does not contain an `Expr` node
+
+## [1.0.2] - 2020-10-26
+
+### Fixed
+
+* `SebastianBergmann\LinesOfCode\Exception` now correctly extends `\Throwable`
+
+## [1.0.1] - 2020-09-28
+
+### Changed
+
+* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`
+
+## [1.0.0] - 2020-07-22
+
+* Initial release
+
+[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
+[1.0.1]: https://github.com/sebastianbergmann/lines-of-code/compare/1.0.0...1.0.1
+[1.0.0]: https://github.com/sebastianbergmann/lines-of-code/compare/f959e71f00e591288acc024afe9cb966c6cf9bd6...1.0.0
diff --git a/vendor/sebastian/lines-of-code/LICENSE b/vendor/sebastian/lines-of-code/LICENSE
new file mode 100644
index 000000000..d170181fa
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/LICENSE
@@ -0,0 +1,33 @@
+sebastian/lines-of-code
+
+Copyright (c) 2020, Sebastian Bergmann <[email protected]>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of Sebastian Bergmann nor the names of his
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/sebastian/lines-of-code/README.md b/vendor/sebastian/lines-of-code/README.md
new file mode 100644
index 000000000..9457ef5a7
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/README.md
@@ -0,0 +1,22 @@
+# sebastian/lines-of-code
+
+Library for counting the lines of code in PHP source code.
+
+[![Latest Stable Version](https://img.shields.io/packagist/v/sebastian/lines-of-code.svg?style=flat-square)](https://packagist.org/packages/sebastian/lines-of-code)
+[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg?style=flat-square)](https://php.net/)
+[![CI Status](https://github.com/sebastianbergmann/lines-of-code/workflows/CI/badge.svg?branch=master&event=push)](https://phpunit.de/build-status.html)
+[![Type Coverage](https://shepherd.dev/github/sebastianbergmann/lines-of-code/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/lines-of-code)
+
+## Installation
+
+You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
+
+```
+composer require sebastian/lines-of-code
+```
+
+If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
+
+```
+composer require --dev sebastian/lines-of-code
+```
diff --git a/vendor/sebastian/lines-of-code/composer.json b/vendor/sebastian/lines-of-code/composer.json
new file mode 100644
index 000000000..95bb9e363
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/composer.json
@@ -0,0 +1,42 @@
+{
+ "name": "sebastian/lines-of-code",
+ "description": "Library for counting the lines of code in PHP source code",
+ "type": "library",
+ "homepage": "https://github.com/sebastianbergmann/lines-of-code",
+ "license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "[email protected]",
+ "role": "lead"
+ }
+ ],
+ "support": {
+ "issues": "https://github.com/sebastianbergmann/lines-of-code/issues"
+ },
+ "prefer-stable": true,
+ "require": {
+ "php": ">=7.3",
+ "nikic/php-parser": "^4.6"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.3"
+ },
+ "config": {
+ "platform": {
+ "php": "7.3.0"
+ },
+ "optimize-autoloader": true,
+ "sort-packages": true
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ }
+}
diff --git a/vendor/sebastian/lines-of-code/src/Counter.php b/vendor/sebastian/lines-of-code/src/Counter.php
new file mode 100644
index 000000000..cfe5e20a7
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/Counter.php
@@ -0,0 +1,91 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+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
+{
+ /**
+ * @throws RuntimeException
+ */
+ public function countInSourceFile(string $sourceFile): LinesOfCode
+ {
+ return $this->countInSourceString(file_get_contents($sourceFile));
+ }
+
+ /**
+ * @throws RuntimeException
+ */
+ public function countInSourceString(string $source): LinesOfCode
+ {
+ $linesOfCode = substr_count($source, "\n");
+
+ if ($linesOfCode === 0 && !empty($source)) {
+ $linesOfCode = 1;
+ }
+
+ try {
+ $nodes = $this->parser()->parse($source);
+
+ assert($nodes !== null);
+
+ return $this->countInAbstractSyntaxTree($linesOfCode, $nodes);
+
+ // @codeCoverageIgnoreStart
+ } catch (Error $error) {
+ throw new RuntimeException(
+ $error->getMessage(),
+ (int) $error->getCode(),
+ $error
+ );
+ }
+ // @codeCoverageIgnoreEnd
+ }
+
+ /**
+ * @param Node[] $nodes
+ *
+ * @throws RuntimeException
+ */
+ public function countInAbstractSyntaxTree(int $linesOfCode, array $nodes): LinesOfCode
+ {
+ $traverser = new NodeTraverser;
+ $visitor = new LineCountingVisitor($linesOfCode);
+
+ $traverser->addVisitor($visitor);
+
+ try {
+ /* @noinspection UnusedFunctionResultInspection */
+ $traverser->traverse($nodes);
+ // @codeCoverageIgnoreStart
+ } catch (Error $error) {
+ throw new RuntimeException(
+ $error->getMessage(),
+ (int) $error->getCode(),
+ $error
+ );
+ }
+ // @codeCoverageIgnoreEnd
+
+ return $visitor->result();
+ }
+
+ private function parser(): Parser
+ {
+ return (new ParserFactory)->create(ParserFactory::PREFER_PHP7, new Lexer);
+ }
+}
diff --git a/vendor/sebastian/lines-of-code/src/Exception/Exception.php b/vendor/sebastian/lines-of-code/src/Exception/Exception.php
new file mode 100644
index 000000000..11d543aa7
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/Exception/Exception.php
@@ -0,0 +1,16 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+use Throwable;
+
+interface Exception extends Throwable
+{
+}
diff --git a/vendor/sebastian/lines-of-code/src/Exception/IllogicalValuesException.php b/vendor/sebastian/lines-of-code/src/Exception/IllogicalValuesException.php
new file mode 100644
index 000000000..46a5c1b1f
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/Exception/IllogicalValuesException.php
@@ -0,0 +1,16 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+use LogicException;
+
+final class IllogicalValuesException extends LogicException implements Exception
+{
+}
diff --git a/vendor/sebastian/lines-of-code/src/Exception/NegativeValueException.php b/vendor/sebastian/lines-of-code/src/Exception/NegativeValueException.php
new file mode 100644
index 000000000..40d27e1f0
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/Exception/NegativeValueException.php
@@ -0,0 +1,16 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * 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
+{
+}
diff --git a/vendor/sebastian/lines-of-code/src/Exception/RuntimeException.php b/vendor/sebastian/lines-of-code/src/Exception/RuntimeException.php
new file mode 100644
index 000000000..4e6d66d0d
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/Exception/RuntimeException.php
@@ -0,0 +1,14 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+final class RuntimeException extends \RuntimeException implements Exception
+{
+}
diff --git a/vendor/sebastian/lines-of-code/src/LineCountingVisitor.php b/vendor/sebastian/lines-of-code/src/LineCountingVisitor.php
new file mode 100644
index 000000000..ff433b2fc
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/LineCountingVisitor.php
@@ -0,0 +1,82 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+use function array_merge;
+use function array_unique;
+use function count;
+use PhpParser\Comment;
+use PhpParser\Node;
+use PhpParser\Node\Expr;
+use PhpParser\NodeVisitorAbstract;
+
+final class LineCountingVisitor extends NodeVisitorAbstract
+{
+ /**
+ * @var int
+ */
+ private $linesOfCode;
+
+ /**
+ * @var Comment[]
+ */
+ private $comments = [];
+
+ /**
+ * @var int[]
+ */
+ private $linesWithStatements = [];
+
+ public function __construct(int $linesOfCode)
+ {
+ $this->linesOfCode = $linesOfCode;
+ }
+
+ public function enterNode(Node $node): void
+ {
+ $this->comments = array_merge($this->comments, $node->getComments());
+
+ if (!$node instanceof Expr) {
+ return;
+ }
+
+ $this->linesWithStatements[] = $node->getStartLine();
+ }
+
+ public function result(): LinesOfCode
+ {
+ $commentLinesOfCode = 0;
+
+ foreach ($this->comments() as $comment) {
+ $commentLinesOfCode += ($comment->getEndLine() - $comment->getStartLine() + 1);
+ }
+
+ return new LinesOfCode(
+ $this->linesOfCode,
+ $commentLinesOfCode,
+ $this->linesOfCode - $commentLinesOfCode,
+ count(array_unique($this->linesWithStatements))
+ );
+ }
+
+ /**
+ * @return Comment[]
+ */
+ private function comments(): array
+ {
+ $comments = [];
+
+ foreach ($this->comments as $comment) {
+ $comments[$comment->getStartLine() . '_' . $comment->getStartTokenPos() . '_' . $comment->getEndLine() . '_' . $comment->getEndTokenPos()] = $comment;
+ }
+
+ return $comments;
+ }
+}
diff --git a/vendor/sebastian/lines-of-code/src/LinesOfCode.php b/vendor/sebastian/lines-of-code/src/LinesOfCode.php
new file mode 100644
index 000000000..41829981a
--- /dev/null
+++ b/vendor/sebastian/lines-of-code/src/LinesOfCode.php
@@ -0,0 +1,98 @@
+<?php declare(strict_types=1);
+/*
+ * This file is part of sebastian/lines-of-code.
+ *
+ * (c) Sebastian Bergmann <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace SebastianBergmann\LinesOfCode;
+
+/**
+ * @psalm-immutable
+ */
+final class LinesOfCode
+{
+ /**
+ * @var int
+ */
+ private $linesOfCode;
+
+ /**
+ * @var int
+ */
+ private $commentLinesOfCode;
+
+ /**
+ * @var int
+ */
+ private $nonCommentLinesOfCode;
+
+ /**
+ * @var int
+ */
+ private $logicalLinesOfCode;
+
+ /**
+ * @throws IllogicalValuesException
+ * @throws NegativeValueException
+ */
+ public function __construct(int $linesOfCode, int $commentLinesOfCode, int $nonCommentLinesOfCode, int $logicalLinesOfCode)
+ {
+ if ($linesOfCode < 0) {
+ throw new NegativeValueException('$linesOfCode must not be negative');
+ }
+
+ if ($commentLinesOfCode < 0) {
+ throw new NegativeValueException('$commentLinesOfCode must not be negative');
+ }
+
+ if ($nonCommentLinesOfCode < 0) {
+ throw new NegativeValueException('$nonCommentLinesOfCode must not be negative');
+ }
+
+ if ($logicalLinesOfCode < 0) {
+ throw new NegativeValueException('$logicalLinesOfCode must not be negative');
+ }
+
+ if ($linesOfCode - $commentLinesOfCode !== $nonCommentLinesOfCode) {
+ throw new IllogicalValuesException('$linesOfCode !== $commentLinesOfCode + $nonCommentLinesOfCode');
+ }
+
+ $this->linesOfCode = $linesOfCode;
+ $this->commentLinesOfCode = $commentLinesOfCode;
+ $this->nonCommentLinesOfCode = $nonCommentLinesOfCode;
+ $this->logicalLinesOfCode = $logicalLinesOfCode;
+ }
+
+ public function linesOfCode(): int
+ {
+ return $this->linesOfCode;
+ }
+
+ public function commentLinesOfCode(): int
+ {
+ return $this->commentLinesOfCode;
+ }
+
+ public function nonCommentLinesOfCode(): int
+ {
+ return $this->nonCommentLinesOfCode;
+ }
+
+ public function logicalLinesOfCode(): int
+ {
+ return $this->logicalLinesOfCode;
+ }
+
+ public function plus(self $other): self
+ {
+ return new self(
+ $this->linesOfCode() + $other->linesOfCode(),
+ $this->commentLinesOfCode() + $other->commentLinesOfCode(),
+ $this->nonCommentLinesOfCode() + $other->nonCommentLinesOfCode(),
+ $this->logicalLinesOfCode() + $other->logicalLinesOfCode(),
+ );
+ }
+}