Skip to content

Commit b90d8d9

Browse files
committed
fix: resolved review conversations;
Return removed SwaggerDriverInterface.
1 parent f862f2b commit b90d8d9

File tree

7 files changed

+59
-24
lines changed

7 files changed

+59
-24
lines changed

config/auto-doc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
|
101101
| The name of driver, which will collect and save documentation
102102
| Feel free to use your own driver class which should be inherited from
103-
| `RonasIT\Support\AutoDoc\Drivers\BaseDriver` class,
103+
| `RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface` interface,
104104
| or one of our drivers from the `drivers` config:
105105
*/
106106
'driver' => env('SWAGGER_DRIVER', 'local'),

src/Drivers/BaseDriver.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
namespace RonasIT\Support\AutoDoc\Drivers;
44

5-
abstract class BaseDriver
5+
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
6+
7+
abstract class BaseDriver implements SwaggerDriverInterface
68
{
79
protected $tempFilePath;
810

11+
public function __construct()
12+
{
13+
$this->tempFilePath = storage_path('temp_documentation.json');
14+
}
15+
916
public function saveTmpData($data): void
1017
{
1118
file_put_contents($this->tempFilePath, json_encode($data));
@@ -22,7 +29,10 @@ public function getTmpData(): ?array
2229
return null;
2330
}
2431

25-
abstract public function saveData(): void;
26-
27-
abstract public function getDocumentation(): array;
32+
protected function clearTmpData(): void
33+
{
34+
if (file_exists($this->tempFilePath)) {
35+
unlink($this->tempFilePath);
36+
}
37+
}
2838
}

src/Drivers/LocalDriver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class LocalDriver extends BaseDriver
1111

1212
public function __construct()
1313
{
14+
parent::__construct();
15+
1416
$this->prodFilePath = config('auto-doc.drivers.local.production_path');
15-
$this->tempFilePath = storage_path('temp_documentation.json');
1617

1718
if (empty($this->prodFilePath)) {
1819
throw new MissedProductionFilePathException();
@@ -23,9 +24,7 @@ public function saveData(): void
2324
{
2425
file_put_contents($this->prodFilePath, json_encode($this->getTmpData()));
2526

26-
if (file_exists($this->tempFilePath)) {
27-
unlink($this->tempFilePath);
28-
}
27+
$this->clearTmpData();
2928
}
3029

3130
public function getDocumentation(): array

src/Drivers/RemoteDriver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class RemoteDriver extends BaseDriver
1212

1313
public function __construct()
1414
{
15+
parent::__construct();
16+
1517
$this->key = config('auto-doc.drivers.remote.key');
1618
$this->remoteUrl = config('auto-doc.drivers.remote.url');
17-
$this->tempFilePath = storage_path('temp_documentation.json');
1819

1920
if (empty($this->remoteUrl)) {
2021
throw new MissedRemoteDocumentationUrlException();
@@ -27,9 +28,7 @@ public function saveData(): void
2728
'Content-Type: application/json'
2829
]);
2930

30-
if (file_exists($this->tempFilePath)) {
31-
unlink($this->tempFilePath);
32-
}
31+
$this->clearTmpData();
3332
}
3433

3534
public function getDocumentation(): array

src/Drivers/StorageDriver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class StorageDriver extends BaseDriver
1313

1414
public function __construct()
1515
{
16+
parent::__construct();
17+
1618
$this->disk = Storage::disk(config('auto-doc.drivers.storage.disk'));
1719
$this->prodFilePath = config('auto-doc.drivers.storage.production_path');
18-
$this->tempFilePath = storage_path('temp_documentation.json');
1920

2021
if (empty($this->prodFilePath)) {
2122
throw new MissedProductionFilePathException();
@@ -26,9 +27,7 @@ public function saveData(): void
2627
{
2728
$this->disk->put($this->prodFilePath, json_encode($this->getTmpData()));
2829

29-
if (file_exists($this->tempFilePath)) {
30-
unlink($this->tempFilePath);
31-
}
30+
$this->clearTmpData();
3231
}
3332

3433
public function getDocumentation(): array
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace RonasIT\Support\AutoDoc\Interfaces;
4+
5+
interface SwaggerDriverInterface
6+
{
7+
/**
8+
* Save temporary data
9+
*
10+
* @param array $data
11+
*/
12+
public function saveTmpData($data);
13+
14+
/**
15+
* Get temporary data
16+
*/
17+
public function getTmpData();
18+
19+
/**
20+
* Save production data
21+
*/
22+
public function saveData();
23+
24+
/**
25+
* Get production documentation
26+
*/
27+
public function getDocumentation(): array;
28+
}

src/Services/SwaggerService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
namespace RonasIT\Support\AutoDoc\Services;
44

55
use Illuminate\Container\Container;
6+
use Illuminate\Http\Request;
67
use Illuminate\Http\Testing\File;
78
use Illuminate\Support\Arr;
89
use Illuminate\Support\Str;
910
use ReflectionClass;
10-
use Illuminate\Http\Request;
11-
use RonasIT\Support\AutoDoc\Drivers\BaseDriver;
11+
use RonasIT\Support\AutoDoc\Exceptions\InvalidDriverClassException;
1212
use RonasIT\Support\AutoDoc\Exceptions\LegacyConfigException;
13+
use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException;
1314
use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException;
15+
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
1416
use RonasIT\Support\AutoDoc\Traits\GetDependenciesTrait;
1517
use Symfony\Component\HttpFoundation\Response;
16-
use RonasIT\Support\AutoDoc\Exceptions\InvalidDriverClassException;
17-
use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException;
1818

1919
/**
20-
* @property BaseDriver $driver
20+
* @property SwaggerDriverInterface $driver
2121
*/
2222
class SwaggerService
2323
{
@@ -97,7 +97,7 @@ protected function setDriver()
9797
$this->driver = app($className);
9898
}
9999

100-
if (!$this->driver instanceof BaseDriver) {
100+
if (!$this->driver instanceof SwaggerDriverInterface) {
101101
throw new InvalidDriverClassException($driver);
102102
}
103103
}
@@ -653,7 +653,7 @@ public function getDocFileContent()
653653
$paths = array_keys($fileContent['paths']);
654654

655655
foreach ($paths as $path) {
656-
$additionalDocPath = $fileContent['paths'][$path];
656+
$additionalDocPath = $fileContent['paths'][$path];
657657

658658
if (empty($documentation['paths'][$path])) {
659659
$documentation['paths'][$path] = $additionalDocPath;

0 commit comments

Comments
 (0)