Skip to content

Commit c0b2ee1

Browse files
committed
PHP 7.4 type hints; Added DocBlocks.
1 parent bf89127 commit c0b2ee1

File tree

5 files changed

+85
-81
lines changed

5 files changed

+85
-81
lines changed

src/DocFile.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010

1111
class DocFile
1212
{
13-
/**
14-
* @var string
15-
*/
16-
private $title;
17-
18-
/**
19-
* @var string
20-
*/
21-
private $path;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $id;
13+
private string $title;
14+
private string $path;
15+
private string $id;
2716

2817
/**
2918
* @param string $title

src/DocHeader.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
<?php
2+
/**
3+
* File containing the class {@see \Mistralys\MarkdownViewer\DocHeader}.
4+
*
5+
* @package MarkdownViewer
6+
* @see \Mistralys\MarkdownViewer\DocHeader
7+
*/
28

39
declare(strict_types=1);
410

511
namespace Mistralys\MarkdownViewer;
612

713
use AppUtils\ConvertHelper;
8-
14+
use AppUtils\OutputBuffering;
15+
16+
/**
17+
* Handles a single header in the document, with
18+
* information on the anchor to use to jump to it,
19+
* among other things.
20+
*
21+
* @package MarkdownViewer
22+
* @author Sebastian Mordziol <[email protected]>
23+
*/
924
class DocHeader
1025
{
11-
/**
12-
* @var string
13-
*/
14-
private $title;
15-
16-
/**
17-
* @var int
18-
*/
19-
private $level;
20-
21-
/**
22-
* @var string
23-
*/
24-
private $tag;
25-
26-
/**
27-
* @var string
28-
*/
29-
private $id;
26+
private string $title;
27+
private int $level;
28+
private string $tag;
29+
private string $id;
30+
private string $anchor;
3031

3132
/**
3233
* @var DocHeader[]
3334
*/
34-
private $headers = array();
35+
private array $headers = array();
3536

3637
/**
3738
* @var array<string,int>
3839
*/
39-
private static $anchors = array();
40-
41-
/**
42-
* @var string
43-
*/
44-
private $anchor;
40+
private static array $anchors = array();
4541

4642
public function __construct(string $title, int $level, string $matchedTag)
4743
{
@@ -136,7 +132,7 @@ public function replace(string $subject, DocFile $file) : string
136132

137133
public function render() : string
138134
{
139-
ob_start();
135+
OutputBuffering::start();
140136

141137
?>
142138
<li>
@@ -145,7 +141,7 @@ public function render() : string
145141
</li>
146142
<?php
147143

148-
return ob_get_clean();
144+
return OutputBuffering::get();
149145
}
150146

151147
private function renderSubheaders() : string
@@ -154,7 +150,7 @@ private function renderSubheaders() : string
154150
return '';
155151
}
156152

157-
ob_start();
153+
OutputBuffering::start();
158154
?>
159155
<ul class="nav-level-<?php echo $this->level ?>">
160156
<?php
@@ -166,6 +162,6 @@ private function renderSubheaders() : string
166162
</ul>
167163
<?php
168164

169-
return ob_get_clean();
165+
return OutputBuffering::get();
170166
}
171167
}

src/DocsException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
<?php
2+
/**
3+
* File containing the class {@see \Mistralys\MarkdownViewer\DocsException}.
4+
*
5+
* @package MarkdownViewer
6+
* @see \Mistralys\MarkdownViewer\DocsException
7+
*/
28

39
declare(strict_types=1);
410

511
namespace Mistralys\MarkdownViewer;
612

713
use AppUtils\BaseException;
814

15+
/**
16+
* Exception class for any exceptions thrown in the package.
17+
*
18+
* @package MarkdownViewer
19+
* @author Sebastian Mordziol <[email protected]>
20+
*/
921
class DocsException extends BaseException
1022
{
1123

src/DocsManager.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
/**
3+
* File containing the class {@see \Mistralys\MarkdownViewer\DocsManager}.
4+
*
5+
* @package MarkdownViewer
6+
* @see \Mistralys\MarkdownViewer\DocsManager
7+
*/
28

39
declare(strict_types=1);
410

@@ -7,15 +13,23 @@
713
use AppUtils\FileHelper;
814
use AppUtils\FileHelper_Exception;
915

16+
/**
17+
* Handles a collection of documentation files to use
18+
* in the viewer. Handles registering and reading the
19+
* list of files.
20+
*
21+
* @package MarkdownViewer
22+
* @author Sebastian Mordziol <[email protected]>
23+
*/
1024
class DocsManager
1125
{
12-
const ERROR_NO_FIRST_FILE_FOUND = 82101;
13-
const ERROR_UNKNOWN_FILE_ID = 82102;
26+
public const ERROR_NO_FIRST_FILE_FOUND = 82101;
27+
public const ERROR_UNKNOWN_FILE_ID = 82102;
1428

1529
/**
1630
* @var DocFile[]
1731
*/
18-
private $files = array();
32+
private array $files = array();
1933

2034
/**
2135
* Adds a documentation file to the collection.
@@ -122,7 +136,7 @@ public function getFirstFile() : DocFile
122136

123137
public function getFiles() : array
124138
{
125-
usort($this->files, function (DocFile $a, DocFile $b) {
139+
usort($this->files, static function (DocFile $a, DocFile $b) : int {
126140
return strnatcasecmp($a->getTitle(), $b->getTitle());
127141
});
128142

src/DocsViewer.php

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,34 @@
11
<?php
2+
/**
3+
* File containing the class {@see \Mistralys\MarkdownViewer\DocsViewer}.
4+
*
5+
* @package MarkdownViewer
6+
* @see \Mistralys\MarkdownViewer\DocsViewer
7+
*/
28

39
declare(strict_types=1);
410

511
namespace Mistralys\MarkdownViewer;
612

13+
use AppUtils\OutputBuffering;use AppUtils\OutputBuffering_Exception;
14+
15+
/**
16+
* Renders the documentation viewer UI, using the
17+
* list of documents contained in the manager instance.
18+
*
19+
* @package MarkdownViewer
20+
* @author Sebastian Mordziol <[email protected]>
21+
*/
722
class DocsViewer
823
{
9-
const ERROR_NO_DOCUMENTS_AVAILABLE = 82001;
10-
11-
/**
12-
* @var string
13-
*/
14-
private $title = 'Documentation';
15-
16-
/**
17-
* @var string
18-
*/
19-
private $menuLabel = 'Available documents';
20-
21-
/**
22-
* @var DocsManager
23-
*/
24-
private $docs;
24+
public const ERROR_NO_DOCUMENTS_AVAILABLE = 82001;
2525

26-
/**
27-
* @var bool
28-
*/
29-
private $darkMode = false;
30-
31-
/**
32-
* @var string
33-
*/
34-
private $vendorURL;
35-
36-
/**
37-
* @var string
38-
*/
39-
private $packageURL;
26+
private string $title = 'Documentation';
27+
private string $menuLabel = 'Available documents';
28+
private DocsManager $docs;
29+
private bool $darkMode = false;
30+
private string $vendorURL;
31+
private string $packageURL;
4032

4133
/**
4234
* @param DocsManager $manager
@@ -201,10 +193,11 @@ private function getPackageURL() : string
201193
/**
202194
* @param DocHeader[] $headers
203195
* @return string
196+
* @throws OutputBuffering_Exception
204197
*/
205198
private function renderMenu(array $headers) : string
206199
{
207-
ob_start();
200+
OutputBuffering::start();
208201

209202
?>
210203
<ul class="nav-level-0">
@@ -217,6 +210,6 @@ private function renderMenu(array $headers) : string
217210
</ul>
218211
<?php
219212

220-
return ob_get_clean();
213+
return OutputBuffering::get();
221214
}
222215
}

0 commit comments

Comments
 (0)