Skip to content

Commit 5df341b

Browse files
committed
phpstan level 6
1 parent f675ef9 commit 5df341b

File tree

11 files changed

+109
-31
lines changed

11 files changed

+109
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHPFUI\InstaDoc Library [![Tests](https://github.com/phpfui/InstaDoc/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/InstaDoc/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/InstaDoc.svg)](https://packagist.org/packages/phpfui/InstaDoc) ![](https://img.shields.io/badge/PHPStan-level%205-brightgreen.svg?style=flat)
1+
# PHPFUI\InstaDoc Library [![Tests](https://github.com/phpfui/InstaDoc/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/InstaDoc/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/InstaDoc.svg)](https://packagist.org/packages/phpfui/InstaDoc) ![](https://img.shields.io/badge/PHPStan-level%206-brightgreen.svg?style=flat)
22

33
## A quick and easy way to add documentation to your PHP project
44

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 6
33
errorFormat: raw
44
editorUrl: '%%file%% %%line%% %%column%%: %%error%%'
55
paths:

src/PHPFUI/InstaDoc/ChildClasses.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class ChildClasses
99
{
1010
/**
11-
* @var array indexed by fqn of class containing array of fqn of children
11+
* @var array<string, array<string>> indexed by fqn of class containing array of fqn of children
1212
*/
1313
private static array $children = [];
1414

@@ -47,7 +47,7 @@ public static function generate() : void
4747
}
4848

4949
/**
50-
* Return the child classes for the passed fully qualified name
50+
* @return array<string> the child classes for the passed fully qualified name
5151
*/
5252
public static function getChildClasses(string $fqn) : array
5353
{

src/PHPFUI/InstaDoc/Controller.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Controller
6161
Controller::PAGE,
6262
];
6363

64+
/**
65+
* @var array<string> $accessTabs tabs to show access in UI
66+
*/
6467
private array $accessTabs = ['Public', 'Protected', 'Private', 'Static'];
6568

6669
private \PHPFUI\InstaDoc\FileManager $fileManager;
@@ -71,6 +74,9 @@ class Controller
7174

7275
private string $gitRoot = '';
7376

77+
/**
78+
* @var array<string, bool> markdown file names
79+
*/
7480
private array $homePageMarkdown = [];
7581

7682
private string $homeUrl = '#';
@@ -79,6 +85,9 @@ class Controller
7985

8086
private \PHPFUI\InstaDoc\PageInterface $page;
8187

88+
/**
89+
* @var array<string, string>
90+
*/
8291
private array $parameters = [];
8392

8493
private string $siteTitle = 'PHPFUI/InstaDoc';
@@ -111,7 +120,7 @@ public function clearMenu() : Controller
111120
/**
112121
* Display a page according to the parameters passed on the url.
113122
*
114-
* @param array $classPagesToShow limits the allowed pages to display, used for static file generation
123+
* @param array<string> $classPagesToShow limits the allowed pages to display, used for static file generation
115124
* @param ?PageInterface $page to use, default to current controller page, but pass in a new page for multiple page generations on the same controller instance
116125
*/
117126
public function display(array $classPagesToShow = Controller::VALID_CLASS_PAGES, ?PageInterface $page = null) : string
@@ -205,7 +214,9 @@ public function display(array $classPagesToShow = Controller::VALID_CLASS_PAGES,
205214
/**
206215
* Generate static files for high volume sites. Pass the path to the directory where you want the files to be placed, it must exist.
207216
*
208-
* @return array with generation file count and time
217+
* @param array<string> $pagesToInclude
218+
*
219+
* @return array<string, float|int<1, max>> array with generation file count and time
209220
*/
210221
public function generate(string $directoryPath, array $pagesToInclude = [Controller::DOC_PAGE], string $extension = '.html') : array
211222
{
@@ -270,13 +281,17 @@ public function generate(string $directoryPath, array $pagesToInclude = [Control
270281
return ['count' => $count, 'seconds' => $milliseconds];
271282
}
272283

284+
/**
285+
* @return array<string> tabs to show access in UI
286+
*/
273287
public function getAccessTabs() : array
274288
{
275289
return $this->accessTabs;
276290
}
277291

278292
/**
279293
* break up a namespaced class into parts
294+
* @return array<string, string>
280295
*/
281296
public function getClassParts(string $namespacedClass) : array
282297
{
@@ -340,6 +355,8 @@ public function getGitRoot() : string
340355

341356
/**
342357
* Get unique home page markdown files
358+
*
359+
* @return array<string> markdown file names
343360
*/
344361
public function getHomePageMarkdown() : array
345362
{
@@ -447,6 +464,8 @@ public function getParameter(string $parameter, ?string $default = null) : strin
447464

448465
/**
449466
* Get all parameters
467+
*
468+
* @return array<string, string>
450469
*/
451470
public function getParameters() : array
452471
{
@@ -482,9 +501,9 @@ public function getConstructorParameters(string $className) : string
482501
return $html2Text->getText();
483502
}
484503

485-
/**
486-
* Get a section for display. Override to change layout
487-
*/
504+
/**
505+
* Get a section for display. Override to change layout
506+
*/
488507
public function getSection(string $sectionName) : Section
489508
{
490509
if (! \in_array($sectionName, Controller::SECTIONS))
@@ -499,6 +518,8 @@ public function getSection(string $sectionName) : Section
499518

500519
/**
501520
* Get a url given parameters. Remove invalid parameters.
521+
*
522+
* @param array<string, string> $parameters
502523
*/
503524
public function getUrl(array $parameters) : string
504525
{
@@ -538,6 +559,9 @@ public function getUrl(array $parameters) : string
538559
return $url;
539560
}
540561

562+
/**
563+
* @param array<string> $tabs tabs to show access in UI
564+
*/
541565
public function setAccessTabs(array $tabs) : Controller
542566
{
543567
$this->accessTabs = $tabs;
@@ -607,6 +631,8 @@ public function setParameter(string $parameter, string $value) : Controller
607631

608632
/**
609633
* Set the valid parameters from an array
634+
*
635+
* @param array<string, string> $parameters key value pairs
610636
*/
611637
public function setParameters(array $parameters) : Controller
612638
{

src/PHPFUI/InstaDoc/FileManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ class FileManager
1212

1313
private string $fileName = '';
1414

15+
/**
16+
* @var array<string>
17+
*/
1518
private array $excludedNamespaces = [];
1619

20+
/**
21+
* @var array<array<string>>
22+
*/
1723
private array $includedNamespaces = [];
1824

1925
/**
@@ -110,6 +116,8 @@ public function excludeNamespace(string $namespace) : FileManager
110116
/**
111117
* Sometimes you don't feel like a nut. Pass namespaces in an
112118
* array to remove them from your documentation.
119+
*
120+
* @param array<string> $namespaces
113121
*/
114122
public function excludeNamespaces(array $namespaces) : FileManager
115123
{
@@ -150,7 +158,7 @@ public function rescan() : FileManager
150158

151159
foreach ($this->includedNamespaces as $parameters)
152160
{
153-
NamespaceTree::addNameSpace($parameters[0], $parameters[1], $parameters[2]);
161+
NamespaceTree::addNameSpace($parameters[0], $parameters[1], (bool)$parameters[2]);
154162
}
155163

156164
foreach ($this->excludedNamespaces as $namespace)

src/PHPFUI/InstaDoc/NamespaceTree.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ class NamespaceTree
99
private static string $activeNamespace;
1010

1111
/**
12-
* @var array indexed by namespace part containing a NamespaceTree
12+
* @var array<string, NamespaceTree> indexed by namespace part containing a NamespaceTree
1313
*/
1414
private array $children = [];
1515

1616
/**
17-
* @var array indexed by fully qualified class name containing the file name
17+
* @var array<string, string> indexed by fully qualified class name containing the file name
1818
*/
1919
private array $classes = [];
2020

21-
private static $controller;
21+
private static \PHPFUI\InstaDoc\Controller $controller;
2222

2323
/**
2424
* @var bool true if this namespace is in the local git repo
2525
*/
2626
private bool $localGit = false;
2727

2828
/**
29-
* @var array of unique markdown files indexed by file name
29+
* @var array<string, bool> of unique markdown files indexed by file name
3030
*/
3131
private array $md = [];
3232

@@ -38,9 +38,9 @@ class NamespaceTree
3838
/**
3939
* @var NamespaceTree our parent
4040
*/
41-
private ?NamespaceTree $parent = null;
41+
private ?\PHPFUI\InstaDoc\NamespaceTree $parent = null;
4242

43-
private static ?NamespaceTree $root = null;
43+
private static ?\PHPFUI\InstaDoc\NamespaceTree $root = null;
4444

4545
// only we can make us to ensure the tree is good
4646
private function __construct()
@@ -133,7 +133,7 @@ public static function findNamespace(string $namespace) : NamespaceTree
133133
}
134134

135135
/**
136-
* Returns array of all classes
136+
* @return array<string, string> all classes
137137
*/
138138
public static function getAllClasses(?NamespaceTree $tree = null) : array
139139
{
@@ -159,6 +159,9 @@ public static function getAllClasses(?NamespaceTree $tree = null) : array
159159
return $classes;
160160
}
161161

162+
/**
163+
* @return array<string>
164+
*/
162165
public static function getAllMDFiles(?NamespaceTree $tree = null) : array
163166
{
164167
if (! $tree)
@@ -175,13 +178,16 @@ public static function getAllMDFiles(?NamespaceTree $tree = null) : array
175178
return $files;
176179
}
177180

181+
/**
182+
* @return array<string, NamespaceTree> indexed by namespace part containing a NamespaceTree
183+
*/
178184
public function getChildren() : array
179185
{
180186
return $this->children;
181187
}
182188

183189
/**
184-
* Return an array with full paths of all the classes in the
190+
* @return array<string, string> an array with full paths of all the classes in the
185191
* namespace, indexed by class name
186192
*/
187193
public function getClassFilenames() : array
@@ -194,6 +200,9 @@ public function getGit() : bool
194200
return $this->localGit;
195201
}
196202

203+
/**
204+
* @return array<string> md file names
205+
*/
197206
public function getMDFiles() : array
198207
{
199208
return \array_keys($this->md);
@@ -346,7 +355,6 @@ public static function sort(?NamespaceTree $tree = null) : void
346355
}
347356
}
348357

349-
/** @phpstan-ignore-next-line */
350358
private function getMenuTree(NamespaceTree $tree, \PHPFUI\Menu $menu) : \PHPFUI\Menu
351359
{
352360
$currentMenu = new \PHPFUI\Menu();

src/PHPFUI/InstaDoc/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(\PHPFUI\InstaDoc\Controller $controller)
2222
$this->addStyleSheet('highlighter/styles/PHPFUI.css');
2323
}
2424

25-
public function addBody($item) : PageInterface
25+
public function addBody(mixed $item) : PageInterface
2626
{
2727
$this->mainColumn->add($item);
2828

src/PHPFUI/InstaDoc/PageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function __construct(Controller $controller);
88

99
public function __toString() : string;
1010

11-
public function addBody($item) : PageInterface;
11+
public function addBody(mixed $item) : PageInterface;
1212

1313
public function create(\PHPFUI\Menu $menu) : void;
1414

src/PHPFUI/InstaDoc/Section.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function getClassBase(string $fullClassName) : string
4343
return \array_pop($parts);
4444
}
4545

46+
/**
47+
* @param array<string> $allowedMenus
48+
*/
4649
public function getMenu(string $className, array $allowedMenus) : ?\PHPFUI\Menu
4750
{
4851
$menu = new \PHPFUI\Menu();

0 commit comments

Comments
 (0)