Skip to content

Commit 4a387c2

Browse files
committed
Making suggested changes;
1 parent 0fa0b4b commit 4a387c2

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

src/Drivers/LocalDriver.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@
77

88
class LocalDriver extends BaseDriver
99
{
10-
protected ?string $baseFileName;
10+
protected ?string $mainFilePath;
1111
private ?array $config;
1212

1313
public function __construct()
1414
{
1515
parent::__construct();
16+
1617
$this->config = config('auto-doc.drivers.local');
1718

18-
$directory = $this->config['directory'];
19-
if (!str_ends_with($directory, DIRECTORY_SEPARATOR)) {
20-
$directory .= DIRECTORY_SEPARATOR;
21-
}
19+
$directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR)
20+
? $this->config['directory']
21+
: $this->config['directory'] . DIRECTORY_SEPARATOR;
2222

23-
$this->baseFileName = storage_path($directory.$this->config['base_file_name'].'.json');
23+
$this->mainFilePath = storage_path("$directory{$this->config['base_file_name']}.json");
2424

25-
if (!preg_match('/\/[\w]+\.json/ms', $this->baseFileName)) {
25+
if (!preg_match('/\/[\w]+\.json/ms', $this->mainFilePath)) {
2626
throw new MissedProductionFilePathException();
2727
}
2828
}
2929

3030
public function saveData(): void
3131
{
32-
$prodDir = storage_path($this->config['directory']);
33-
if (!is_dir($prodDir)) {
34-
mkdir($prodDir);
32+
$documentationDirectory = storage_path($this->config['directory']);
33+
if (!is_dir($documentationDirectory)) {
34+
mkdir($documentationDirectory);
3535
}
3636

37-
file_put_contents($this->baseFileName, json_encode($this->getTmpData()));
37+
file_put_contents($this->mainFilePath, json_encode($this->getTmpData()));
3838

3939
$this->clearTmpData();
4040
}
4141

4242
public function getDocumentation(): array
4343
{
44-
if (!file_exists($this->baseFileName)) {
44+
if (!file_exists($this->mainFilePath)) {
4545
throw new FileNotFoundException();
4646
}
4747

48-
$fileContent = file_get_contents($this->baseFileName);
48+
$fileContent = file_get_contents($this->mainFilePath);
4949

5050
return json_decode($fileContent, true);
5151
}

src/Drivers/StorageDriver.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class StorageDriver extends BaseDriver
1111
{
1212
protected Filesystem $disk;
13-
protected ?string $baseFileName;
13+
protected ?string $mainFilePath;
1414
protected array $config;
1515

1616
public function __construct()
@@ -19,31 +19,32 @@ public function __construct()
1919

2020
$this->config = config('auto-doc.drivers.storage');
2121
$this->disk = Storage::disk($this->config['disk']);
22-
$directory = $this->config['directory'];
23-
if (!str_ends_with($directory, DIRECTORY_SEPARATOR)) {
24-
$directory .= DIRECTORY_SEPARATOR;
25-
}
26-
$this->baseFileName = $directory.$this->config['base_file_name'].'.json';
2722

28-
if (!preg_match('/\/[\w]+\.json/ms', $this->baseFileName)) {
23+
$directory = str_ends_with($this->config['directory'], DIRECTORY_SEPARATOR)
24+
? $this->config['directory']
25+
: $this->config['directory'] . DIRECTORY_SEPARATOR;
26+
27+
$this->mainFilePath = "$directory{$this->config['base_file_name']}.json";
28+
29+
if (!preg_match('/\/[\w]+\.json/ms', $this->mainFilePath)) {
2930
throw new MissedProductionFilePathException();
3031
}
3132
}
3233

3334
public function saveData(): void
3435
{
35-
$this->disk->put($this->baseFileName, json_encode($this->getTmpData()));
36+
$this->disk->put($this->mainFilePath, json_encode($this->getTmpData()));
3637

3738
$this->clearTmpData();
3839
}
3940

4041
public function getDocumentation(): array
4142
{
42-
if (!$this->disk->exists($this->baseFileName)) {
43+
if (!$this->disk->exists($this->mainFilePath)) {
4344
throw new FileNotFoundException();
4445
}
4546

46-
$fileContent = $this->disk->get($this->baseFileName);
47+
$fileContent = $this->disk->get($this->mainFilePath);
4748

4849
return json_decode($fileContent, true);
4950
}

tests/AutoDocControllerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class AutoDocControllerTest extends TestCase
1212
use PHPMock;
1313

1414
protected static array $documentation;
15-
protected static string $baseFileName;
1615
protected static string $baseFile;
1716

1817
public function setUp(): void
@@ -24,16 +23,16 @@ public function setUp(): void
2423
$documentationDirectory .= DIRECTORY_SEPARATOR;
2524
}
2625

27-
self::$baseFileName ??= 'documentation';
28-
self::$baseFile ??= $documentationDirectory.self::$baseFileName.'.json';
26+
self::$baseFile ??= $documentationDirectory.'documentation.json';
2927
self::$documentation ??= $this->getJsonFixture('tmp_data');
3028

3129
if (!is_dir(storage_path($documentationDirectory))) {
3230
mkdir(storage_path($documentationDirectory));
3331
}
32+
3433
file_put_contents(storage_path(self::$baseFile), json_encode(self::$documentation));
3534

36-
config(['auto-doc.drivers.local.base_file_name' => self::$baseFileName]);
35+
config(['auto-doc.drivers.local.base_file_name' => 'documentation']);
3736
}
3837

3938
public function tearDown(): void

tests/LocalDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function setUp(): void
2424
}
2525

2626
self::$baseFileName ??= 'documentation';
27-
self::$baseFile ??= storage_path($documentationDirectory.self::$baseFileName.'.json');
27+
self::$baseFile ??= storage_path($documentationDirectory . self::$baseFileName . '.json');
2828
self::$tmpDocumentationFilePath ??= storage_path('temp_documentation.json');
2929

3030
self::$tmpData ??= $this->getJsonFixture('tmp_data');

0 commit comments

Comments
 (0)