Skip to content

Commit 5938677

Browse files
committed
refactor
1 parent 1f2eefb commit 5938677

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

src/Contracts/Presenter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Bekwoh\LaravelDbDoc\Contracts;
4+
5+
interface Presenter {
6+
public function getDisk();
7+
public function getFilename();
8+
public function getContents();
9+
public function getStub();
10+
public function write();
11+
public function read();
12+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Bekwoh\LaravelDbDoc\Presentation;
4+
5+
use Bekwoh\LaravelDbDoc\Contracts\Presenter;
6+
use Bekwoh\LaravelDbDoc\Facades\LaravelDbDoc;
7+
use Illuminate\Support\Facades\Storage;
8+
use Illuminate\Support\Str;
9+
10+
abstract class AbstractPresenter implements Presenter
11+
{
12+
abstract public function getContents();
13+
14+
public function __construct(protected array $contents)
15+
{
16+
}
17+
18+
public function getDisk()
19+
{
20+
return LaravelDbDoc::disk(strtolower(basename(__CLASS__));
21+
}
22+
23+
public function getFilename()
24+
{
25+
return LaravelDbDoc::filename(strtolower(basename(__CLASS__));
26+
}
27+
28+
public function getStub()
29+
{
30+
return file_get_contents(
31+
base_path('stubs/db-doc.stub')
32+
);
33+
}
34+
35+
public function write()
36+
{
37+
Storage::disk($this->getDisk())
38+
->put(
39+
$this->getFilename(),
40+
$this->getContents()
41+
);
42+
}
43+
44+
public function read()
45+
{
46+
return Storage::disk($this->getDisk())
47+
->get($this->getFilename());
48+
}
49+
}

src/Presentation/Json.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,12 @@
22

33
namespace Bekwoh\LaravelDbDoc\Presentation;
44

5-
use Illuminate\Support\Facades\Storage;
5+
use Bekwoh\LaravelDbDoc\Contracts\Presenter;
66

7-
class Json
7+
class Json extends AbstractPresenter implements Presenter
88
{
9-
public function __construct(protected array $contents)
10-
{
11-
}
12-
13-
public function getDisk()
14-
{
15-
return config('db-doc.presentations.json.disk');
16-
}
17-
189
public function getContents()
1910
{
2011
return json_encode($this->contents, JSON_PRETTY_PRINT);
2112
}
22-
23-
public function write()
24-
{
25-
Storage::disk($this->getDisk())
26-
->put(
27-
config('app.name').' Database Schema.json',
28-
$this->getContents(),
29-
);
30-
}
3113
}

src/Presentation/Markdown.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,11 @@
22

33
namespace Bekwoh\LaravelDbDoc\Presentation;
44

5-
use Bekwoh\LaravelDbDoc\Facades\LaravelDbDoc;
6-
use Illuminate\Support\Facades\Storage;
5+
use Bekwoh\LaravelDbDoc\Contracts\Presenter;
76
use Illuminate\Support\Str;
87

9-
class Markdown
8+
class Markdown extends AbstractPresenter implements Presenter
109
{
11-
public function __construct(protected array $contents)
12-
{
13-
}
14-
15-
public function getDisk()
16-
{
17-
return LaravelDbDoc::disk('markdown');
18-
}
19-
20-
public function getFilename()
21-
{
22-
return LaravelDbDoc::filename('markdown');
23-
}
24-
2510
public function getContents()
2611
{
2712
$contents = $this->contents;
@@ -57,26 +42,4 @@ public function getContents()
5742
$schema,
5843
], $stub);
5944
}
60-
61-
private function getStub()
62-
{
63-
return file_get_contents(
64-
base_path('stubs/db-doc.stub')
65-
);
66-
}
67-
68-
public function write()
69-
{
70-
Storage::disk($this->getDisk())
71-
->put(
72-
$this->getFilename(),
73-
$this->getContents()
74-
);
75-
}
76-
77-
public function read()
78-
{
79-
return Storage::disk($this->getDisk())
80-
->get($this->getFilename());
81-
}
8245
}

0 commit comments

Comments
 (0)