Bladeren bron

Added badges to README, modified fancy implode

Marcel Pociot 9 jaren geleden
bovenliggende
commit
beef54c5ed
4 gewijzigde bestanden met toevoegingen van 45 en 20 verwijderingen
  1. 18 0
      .travis.yml
  2. 7 1
      README.md
  3. 11 10
      src/Mpociot/ApiDoc/ApiDocGenerator.php
  4. 9 9
      tests/ApiDocGeneratorTest.php

+ 18 - 0
.travis.yml

@@ -0,0 +1,18 @@
+language: php
+
+php:
+  - 5.5
+  - 5.6
+  - 7.0
+
+before_script:
+  - travis_retry composer self-update
+  - travis_retry composer install --prefer-source --no-interaction
+
+script:
+  - vendor/bin/phpunit --coverage-clover=coverage.xml
+
+before_install:
+  - pip install --user codecov
+after_success:
+  - codecov

+ 7 - 1
README.md

@@ -1,7 +1,13 @@
-## Laravel API Documentation Generator (WIP)
+## Laravel API Documentation Generator
 
 `php artisan api:gen --routePrefix=settings/api/*`
 
+![image](http://img.shields.io/packagist/v/mpociot/laravel-apidoc-generator.svg?style=flat)
+![image](http://img.shields.io/packagist/l/mpociot/laravel-apidoc-generator.svg?style=flat)
+[![codecov.io](https://codecov.io/github/mpociot/laravel-apidoc-generator/coverage.svg?branch=master)](https://codecov.io/github/mpociot/laravel-apidoc-generator?branch=master)
+[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/?branch=master)
+[![Build Status](https://travis-ci.org/mpociot/laravel-apidoc-generator.svg?branch=master)](https://travis-ci.org/mpociot/laravel-apidoc-generator)
+
 
 ### Install
 

+ 11 - 10
src/Mpociot/ApiDoc/ApiDocGenerator.php

@@ -113,8 +113,11 @@ class ApiDocGenerator
      * @param $last
      * @return string
      */
-    protected function fancy_implode($arr, $first, $last)
+    protected function fancyImplode($arr, $first, $last)
     {
+        $arr = array_map(function ($value) {
+            return '`' . $value . '`';
+        }, $arr);
         array_push($arr, implode($last, array_splice($arr, -2)));
         return implode($first, $arr);
     }
@@ -150,17 +153,15 @@ class ApiDocGenerator
                 $attributeData['description'][] = 'Only alpha-numeric characters allowed';
                 break;
             case 'in':
-                $attributeData['description'][] = $this->fancy_implode($parameters, ', ', ' or ');
+                $attributeData['description'][] = $this->fancyImplode($parameters, ', ', ' or ');
                 break;
             case 'not_in':
-                $attributeData['description'][] = 'Not in: ' . $this->fancy_implode($parameters, ', ', ' or ');
+                $attributeData['description'][] = 'Not in: ' . $this->fancyImplode($parameters, ', ', ' or ');
                 break;
             case 'min':
-                $attributeData['type'] = 'numeric';
                 $attributeData['description'][] = 'Minimum: `' . $parameters[0] . '`';
                 break;
             case 'max':
-                $attributeData['type'] = 'numeric';
                 $attributeData['description'][] = 'Maximum: `' . $parameters[0] . '`';
                 break;
             case 'between':
@@ -195,7 +196,7 @@ class ApiDocGenerator
                 break;
             case 'mimetypes':
             case 'mimes':
-                $attributeData['description'][] = 'Allowed mime types: ' . $this->fancy_implode($parameters, ', ', ' or ');
+                $attributeData['description'][] = 'Allowed mime types: ' . $this->fancyImplode($parameters, ', ', ' or ');
                 break;
             case 'required_if':
                 $attributeData['description'][] = 'Required if `' . $parameters[0] . '` is `' . $parameters[1] . '`';
@@ -204,16 +205,16 @@ class ApiDocGenerator
                 $attributeData['description'][] = 'Required unless `' . $parameters[0] . '` is `' . $parameters[1] . '`';
                 break;
             case 'required_with':
-                $attributeData['description'][] = 'Required if the parameters ' . $this->fancy_implode($parameters, ', ', ' or ') . ' are present.';
+                $attributeData['description'][] = 'Required if the parameters ' . $this->fancyImplode($parameters, ', ', ' or ') . ' are present.';
                 break;
             case 'required_with_all':
-                $attributeData['description'][] = 'Required if the parameters ' . $this->fancy_implode($parameters, ', ', ' and ') . ' are present.';
+                $attributeData['description'][] = 'Required if the parameters ' . $this->fancyImplode($parameters, ', ', ' and ') . ' are present.';
                 break;
             case 'required_without':
-                $attributeData['description'][] = 'Required if the parameters ' . $this->fancy_implode($parameters, ', ', ' or ') . ' are not present.';
+                $attributeData['description'][] = 'Required if the parameters ' . $this->fancyImplode($parameters, ', ', ' or ') . ' are not present.';
                 break;
             case 'required_without_all':
-                $attributeData['description'][] = 'Required if the parameters ' . $this->fancy_implode($parameters, ', ', ' and ') . ' are not present.';
+                $attributeData['description'][] = 'Required if the parameters ' . $this->fancyImplode($parameters, ', ', ' and ') . ' are not present.';
                 break;
             case 'same':
                 $attributeData['description'][] = 'Must be the same as `' . $parameters[0] . '`';

+ 9 - 9
tests/ApiDocGeneratorTest.php

@@ -179,7 +179,7 @@ class ApiDocGeneratorTest extends Orchestra\Testbench\TestCase
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('jpeg, png, bmp, gif or svg', $attribute['description'][0]);
+                    $this->assertEquals('`jpeg`, `png`, `bmp`, `gif` or `svg`', $attribute['description'][0]);
                     break;
                 case 'integer':
                     $this->assertFalse( $attribute['required'] );
@@ -199,13 +199,13 @@ class ApiDocGeneratorTest extends Orchestra\Testbench\TestCase
                     break;
                 case 'max':
                     $this->assertFalse( $attribute['required'] );
-                    $this->assertEquals( 'numeric', $attribute['type'] );
+                    $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
                     $this->assertEquals('Maximum: `10`', $attribute['description'][0]);
                     break;
                 case 'min':
                     $this->assertFalse( $attribute['required'] );
-                    $this->assertEquals( 'numeric', $attribute['type'] );
+                    $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
                     $this->assertEquals('Minimum: `20`', $attribute['description'][0]);
                     break;
@@ -213,13 +213,13 @@ class ApiDocGeneratorTest extends Orchestra\Testbench\TestCase
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Allowed mime types: jpeg, bmp or png', $attribute['description'][0]);
+                    $this->assertEquals('Allowed mime types: `jpeg`, `bmp` or `png`', $attribute['description'][0]);
                     break;
                 case 'not_in':
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Not in: foo or bar', $attribute['description'][0]);
+                    $this->assertEquals('Not in: `foo` or `bar`', $attribute['description'][0]);
                     break;
                 case 'numeric':
                     $this->assertFalse( $attribute['required'] );
@@ -248,25 +248,25 @@ class ApiDocGeneratorTest extends Orchestra\Testbench\TestCase
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Required if the parameters foo, bar or baz are present.', $attribute['description'][0]);
+                    $this->assertEquals('Required if the parameters `foo`, `bar` or `baz` are present.', $attribute['description'][0]);
                     break;
                 case 'required_with_all':
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Required if the parameters foo, bar and baz are present.', $attribute['description'][0]);
+                    $this->assertEquals('Required if the parameters `foo`, `bar` and `baz` are present.', $attribute['description'][0]);
                     break;
                 case 'required_without':
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Required if the parameters foo, bar or baz are not present.', $attribute['description'][0]);
+                    $this->assertEquals('Required if the parameters `foo`, `bar` or `baz` are not present.', $attribute['description'][0]);
                     break;
                 case 'required_without_all':
                     $this->assertFalse( $attribute['required'] );
                     $this->assertEquals( 'string', $attribute['type'] );
                     $this->assertCount( 1, $attribute['description'] );
-                    $this->assertEquals('Required if the parameters foo, bar and baz are not present.', $attribute['description'][0]);
+                    $this->assertEquals('Required if the parameters `foo`, `bar` and `baz` are not present.', $attribute['description'][0]);
                     break;
                 case 'same':
                     $this->assertFalse( $attribute['required'] );