Преглед на файлове

Merge pull request #162 from knuckleswtf/php8

PHP 8 compatibility
Shalvah преди 4 години
родител
ревизия
5b571f4971

+ 1 - 0
.travis.yml

@@ -22,6 +22,7 @@ matrix:
     - php: 7.4
     - php: 7.4
       env: SETUP=lowest
+    - php: 8.0
 
 cache:
   directories:

+ 1 - 1
README.md

@@ -10,7 +10,7 @@ Generate API documentation for humans from your Laravel codebase. [Here's what t
 
 [![Latest Stable Version](https://poser.pugx.org/knuckleswtf/scribe/v/stable)](https://packagist.org/packages/knuckleswtf/scribe) [![Total Downloads](https://poser.pugx.org/knuckleswtf/scribe/downloads)](https://packagist.org/packages/knuckleswtf/scribe) [![Build Status](https://travis-ci.com/knuckleswtf/scribe.svg?branch=master)](https://travis-ci.com/knuckleswtf/scribe)
 
-> 👋 Scribe helps you generate docs automatically, but if you really want to make friendly, maintainable and testable API docs, there's some more things you need to know. So I made [a course](https://apidocsfordevs.com?utm_source=scribe-laravel&utm_medium=referral&utm_campaign=launch) for you.🤗
+> 👋 Scribe helps you generate docs automatically, but if you really want to make friendly, maintainable and testable API docs, there's some more things you need to know. So I made [a course](https://apidocsfordevs.com?utm_source=scribe-laravel&utm_medium=referral&utm_campaign=none) for you.🤗
 
 ## Features
 - Pretty HTML documentation page, with included code samples and friendly text

+ 3 - 3
composer.dingo.json

@@ -36,14 +36,14 @@
         "symfony/yaml": "^4.0|^5.0"
     },
     "require-dev": {
-        "dms/phpunit-arraysubset-asserts": "^0.1.0",
-        "brianium/paratest": "^4.0",
+        "brianium/paratest": "^5.0|^6.0",
+        "dms/phpunit-arraysubset-asserts": "^0.2.0",
         "league/fractal": "^0.19.0",
         "laravel/legacy-factories": "^1.0.4",
         "laravel/lumen-framework": "^6.0|^7.0|^8.0",
         "orchestra/testbench": "^4.0|^5.0|^6.0",
         "phpstan/phpstan": "^0.12.19",
-        "phpunit/phpunit": "^8.0|^9.0"
+        "phpunit/phpunit": "^9.0"
     },
     "suggest": {
         "league/fractal": "Required for transformers support"

+ 4 - 4
composer.json

@@ -35,15 +35,15 @@
     "symfony/yaml": "^4.0|^5.0"
   },
   "require-dev": {
-    "brianium/paratest": "^4.0",
-    "dms/phpunit-arraysubset-asserts": "^0.1.0",
+    "brianium/paratest": "^5.0|^6.0",
+    "dms/phpunit-arraysubset-asserts": "^0.2.0",
     "laravel/legacy-factories": "^1.0.4",
     "laravel/lumen-framework": "^6.0|^7.0|^8.0",
     "league/fractal": "^0.19.0",
     "nikic/fast-route": "^1.3",
-    "orchestra/testbench": "^4.0|^5.0",
+    "orchestra/testbench": "^4.0|^5.0|^6.0",
     "phpstan/phpstan": "^0.12.19",
-    "phpunit/phpunit": "^8.0|^9.0"
+    "phpunit/phpunit": "^9.0"
   },
   "suggest": {
     "league/fractal": "Required for transformers support"

+ 1 - 1
docs/index.md

@@ -11,7 +11,7 @@ Generate API documentation for humans from your Laravel/Lumen/[Dingo](https://gi
 ```
 
 ```eval_rst
-.. Tip:: Scribe helps you generate docs automatically, but if you really want to make friendly, maintainable and testable API docs, there's some more stuff you need to know. So I made `a course <https://apidocsfordevs.com?utm_source=scribe-laravel-docs&utm_medium=referral&utm_campaign=launch>`_ for you.🤗
+.. Tip:: Scribe helps you generate docs automatically, but if you really want to make friendly, maintainable and testable API docs, there's some more stuff you need to know. So I made `a course <https://apidocsfordevs.com?utm_source=scribe-laravel-docs&utm_medium=referral&utm_campaign=none>`_ for you.🤗
 ```
 
 ## Features

+ 13 - 11
phpunit.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<phpunit backupGlobals="false"
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         backupGlobals="false"
          backupStaticAttributes="false"
          bootstrap="vendor/autoload.php"
          cacheResult="true"
@@ -8,7 +9,17 @@
          convertNoticesToExceptions="true"
          convertWarningsToExceptions="true"
          processIsolation="false"
-         stopOnFailure="false">
+         stopOnFailure="false"
+         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
+    <coverage>
+        <include>
+            <directory suffix=".php">src/</directory>
+        </include>
+        <exclude>
+            <file>src/ScribeServiceProvider.php</file>
+            <file>resources/views/pastel.blade.php</file>
+        </exclude>
+    </coverage>
     <testsuites>
         <testsuite name="Full Test">
             <file>tests/GenerateDocumentationTest.php</file>
@@ -30,13 +41,4 @@
             <file>tests/Unit/PostmanCollectionWriterTest.php</file>
         </testsuite>
     </testsuites>
-    <filter>
-        <whitelist>
-            <directory suffix=".php">src/</directory>
-            <exclude>
-                <file>src/ScribeServiceProvider.php</file>
-                <file>resources/views/pastel.blade.php</file>
-            </exclude>
-        </whitelist>
-    </filter>
 </phpunit>

+ 2 - 2
src/Commands/GenerateDocumentation.php

@@ -8,7 +8,7 @@ use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Str;
 use Knuckles\Scribe\Extracting\Generator;
-use Knuckles\Scribe\Matching\Match;
+use Knuckles\Scribe\Matching\MatchedRoute;
 use Knuckles\Scribe\Matching\RouteMatcherInterface;
 use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
 use Knuckles\Scribe\Tools\DocumentationConfig;
@@ -84,7 +84,7 @@ class GenerateDocumentation extends Command
     }
 
     /**
-     * @param Match[] $matches
+     * @param MatchedRoute[] $matches
      *
      * @return array
      * @throws \ReflectionException

+ 6 - 0
src/Extracting/Strategies/BodyParameters/GetFromBodyParamTag.php

@@ -13,6 +13,7 @@ use Mpociot\Reflection\DocBlock\Tag;
 use ReflectionClass;
 use ReflectionException;
 use ReflectionFunctionAbstract;
+use ReflectionUnionType;
 
 class GetFromBodyParamTag extends Strategy
 {
@@ -33,6 +34,11 @@ class GetFromBodyParamTag extends Strategy
                 continue;
             }
 
+            if (class_exists(ReflectionUnionType::class)
+                && $paramType instanceof ReflectionUnionType) {
+                continue;
+            }
+
             $parameterClassName = $paramType->getName();
 
             try {

+ 6 - 0
src/Extracting/Strategies/BodyParameters/GetFromFormRequest.php

@@ -20,6 +20,7 @@ use ReflectionClass;
 use ReflectionException;
 use ReflectionFunctionAbstract;
 use Illuminate\Contracts\Validation\Factory as ValidationFactory;
+use ReflectionUnionType;
 
 class GetFromFormRequest extends Strategy
 {
@@ -42,6 +43,11 @@ class GetFromFormRequest extends Strategy
                 continue;
             }
 
+            if (class_exists(ReflectionUnionType::class)
+                && $paramType instanceof ReflectionUnionType) {
+                continue;
+            }
+
             $parameterClassName = $paramType->getName();
 
             if (!class_exists($parameterClassName)) {

+ 6 - 0
src/Extracting/Strategies/Headers/GetFromHeaderTag.php

@@ -12,6 +12,7 @@ use Mpociot\Reflection\DocBlock;
 use Mpociot\Reflection\DocBlock\Tag;
 use ReflectionClass;
 use ReflectionFunctionAbstract;
+use ReflectionUnionType;
 
 class GetFromHeaderTag extends Strategy
 {
@@ -27,6 +28,11 @@ class GetFromHeaderTag extends Strategy
                 continue;
             }
 
+            if (class_exists(ReflectionUnionType::class)
+                && $paramType instanceof ReflectionUnionType) {
+                continue;
+            }
+
             $parameterClassName = $paramType->getName();
 
             try {

+ 6 - 0
src/Extracting/Strategies/QueryParameters/GetFromQueryParamTag.php

@@ -13,6 +13,7 @@ use Mpociot\Reflection\DocBlock;
 use Mpociot\Reflection\DocBlock\Tag;
 use ReflectionClass;
 use ReflectionFunctionAbstract;
+use ReflectionUnionType;
 
 class GetFromQueryParamTag extends Strategy
 {
@@ -33,6 +34,11 @@ class GetFromQueryParamTag extends Strategy
                 continue;
             }
 
+            if (class_exists(ReflectionUnionType::class)
+                && $paramType instanceof ReflectionUnionType) {
+                continue;
+            }
+
             $parameterClassName = $paramType->getName();
 
             try {

+ 6 - 0
src/Extracting/Strategies/UrlParameters/GetFromUrlParamTag.php

@@ -13,6 +13,7 @@ use Mpociot\Reflection\DocBlock;
 use Mpociot\Reflection\DocBlock\Tag;
 use ReflectionClass;
 use ReflectionFunctionAbstract;
+use ReflectionUnionType;
 
 class GetFromUrlParamTag extends Strategy
 {
@@ -28,6 +29,11 @@ class GetFromUrlParamTag extends Strategy
                 continue;
             }
 
+            if (class_exists(ReflectionUnionType::class)
+                && $paramType instanceof ReflectionUnionType) {
+                continue;
+            }
+
             $parameterClassName = $paramType->getName();
 
             try {

+ 1 - 1
src/Matching/Match.php → src/Matching/MatchedRoute.php

@@ -4,7 +4,7 @@ namespace Knuckles\Scribe\Matching;
 
 use Illuminate\Routing\Route;
 
-class Match implements \ArrayAccess
+class MatchedRoute implements \ArrayAccess
 {
     /**
      * @var Route

+ 1 - 1
src/Matching/RouteMatcher.php

@@ -35,7 +35,7 @@ class RouteMatcher implements RouteMatcherInterface
                 }
 
                 if ($this->shouldIncludeRoute($route, $routeRule, $includes, $usingDingoRouter)) {
-                    $matchedRoutes[] = new Match($route, $routeRule['apply'] ?? []);
+                    $matchedRoutes[] = new MatchedRoute($route, $routeRule['apply'] ?? []);
                 }
             }
         }

+ 1 - 1
src/Matching/RouteMatcherInterface.php

@@ -10,7 +10,7 @@ interface RouteMatcherInterface
      * @param array $routeRules Route rules defined under the "routes" section in config
      * @param string $router
      *
-     * @return Match[]
+     * @return MatchedRoute[]
      */
     public function getRoutes(array $routeRules = [], string $router = 'laravel');
 }

+ 3 - 3
tests/Unit/PostmanCollectionWriterTest.php

@@ -169,7 +169,7 @@ class PostmanCollectionWriterTest extends TestCase
     }
 
     /** @test */
-    public function query_parameters_are_disabled_with_no_value_when_notRequired()
+    public function query_parameters_are_disabled_with_no_value_when_not_required()
     {
         $fakeRoute = $this->createMockRouteData('fake/path');
         $fakeRoute['queryParameters'] = [
@@ -198,13 +198,13 @@ class PostmanCollectionWriterTest extends TestCase
         $this->assertCount(2, $variableData);
         $this->assertContains([
             'key' => 'required',
-            'value' => null,
+            'value' => '',
             'description' => 'A required param with a null value',
             'disabled' => false,
         ], $variableData);
         $this->assertContains([
             'key' => 'not_required',
-            'value' => null,
+            'value' => '',
             'description' => 'A not required param with a null value',
             'disabled' => true,
         ], $variableData);