Skip to content

Commit c948759

Browse files
committed
PHP 8.2 support
1 parent d410824 commit c948759

File tree

10 files changed

+125
-43
lines changed

10 files changed

+125
-43
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
$config = include '../phpfui/PhpCsFixer.php';
9+
$config = include 'vendor/phpfui/phpunit-syntax-coverage/PhpCsFixer.php';
1010

1111
return $config->setFinder(PhpCsFixer\Finder::create()
1212
->exclude('vendor')

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"require": {
1515
"php": ">=8.0 <8.3",
1616
"phpfui/phpfui": "^6.0",
17-
"scrivo/highlight.php": "dev-master",
1817
"phpdocumentor/reflection-docblock": "^5.0",
1918
"gitonomy/gitlib": "^1.2",
2019
"cebe/markdown": "^1.2",
2120
"voku/simple_html_dom": "^4.7",
22-
"soundasleep/html2text": "^2.0"
21+
"soundasleep/html2text": "^2.0",
22+
"scrivo/highlight.php": ">=v9.18"
2323
},
2424
"autoload": {
2525
"psr-4": {"PHPFUI\\InstaDoc\\": "src/PHPFUI/InstaDoc/"}

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
9+
convertDeprecationsToExceptions="true"
910
processIsolation="false"
1011
stopOnFailure="false"
1112
bootstrap="./tests/bootstrap.php"

src/PHPFUI/InstaDoc/FileManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function loadVendorDirectories() : void
236236

237237
$composerJsonPath = $this->composerJsonPath . 'composer.lock';
238238
$composerJsonPath = \str_replace('//', '/', $composerJsonPath);
239-
$json = \json_decode(@\file_get_contents($composerJsonPath), true, 512, JSON_THROW_ON_ERROR);
239+
$json = \json_decode(@\file_get_contents($composerJsonPath), true, 512);
240240

241241
if (! $json)
242242
{

src/PHPFUI/InstaDoc/MarkDownParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function text(string $markdown) : string
3535
$div->addClass('markdown-body');
3636
$html = $this->parser->parse($markdown);
3737
$dom = new \voku\helper\HtmlDomParser($html);
38-
$codeBlocks = $dom->find('.language-PHP');
38+
$codeBlocks = $dom->find('.language-php');
3939

4040
foreach ($codeBlocks as $block)
4141
{

src/PHPFUI/InstaDoc/NamespaceTree.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function addGlobalNameSpaceClass(string $filename, bool $localGit
5151
{
5252
$filenameLength = \strlen($filename);
5353

54-
if (\strpos($filename, '.php') == $filenameLength - 4)
54+
if (\str_ends_with($filename, '.php'))
5555
{
5656
$root = self::getRoot();
5757
$file = \str_replace('/', '\\', \str_replace('.php', '', $filename));
@@ -92,7 +92,7 @@ public static function addNamespace(string $namespace, string $directory, bool $
9292
{
9393
self::addNamespace($namespace . '\\' . $filename, $directory . '/' . $filename, $localGit);
9494
}
95-
elseif (\strpos($filename, '.php') == $filenameLength - 4)
95+
elseif (\str_ends_with($filename, '.php'))
9696
{
9797
$class = \substr($filename, 0, $filenameLength - 4);
9898
$class = $namespace . '\\' . $class;

src/PHPFUI/InstaDoc/Section/CodeCommon.php

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -127,40 +127,7 @@ public function getValueString(mixed $value) : string
127127
break;
128128

129129
case 'object':
130-
$class = $value::class;
131-
132-
if ('ReflectionNamedType' == $class)
133-
{
134-
$value = ($value->allowsNull() ? '?' : '') . $this->getClassName($value->getName());
135-
}
136-
elseif ('ReflectionUnionType' == $class)
137-
{
138-
$types = $value->getTypes();
139-
$value = $bar = '';
140-
141-
foreach ($types as $type)
142-
{
143-
$value .= $bar;
144-
$bar = '|';
145-
$value .= $this->getClassName($type->getName());
146-
}
147-
}
148-
elseif ('ReflectionIntersectionType' == $class)
149-
{
150-
$types = $value->getTypes();
151-
$value = $bar = '';
152-
153-
foreach ($types as $type)
154-
{
155-
$value .= $bar;
156-
$bar = '&';
157-
$value .= $this->getClassName($type->getName());
158-
}
159-
}
160-
else
161-
{
162-
$value = $this->getClassName($class);
163-
}
130+
$value = $this->getClassName($value);
164131

165132
break;
166133

@@ -302,10 +269,53 @@ protected function formatComments(?\phpDocumentor\Reflection\DocBlock $docBlock,
302269
return $container;
303270
}
304271

305-
protected function getClassName(string $class, bool $asLink = true) : string
272+
protected function getClassName(string | object $class, bool $asLink = true) : string
306273
{
307274
$array = '';
308275

276+
if (! \is_string($class))
277+
{
278+
$className = $class::class;
279+
280+
if ('ReflectionNamedType' == $className)
281+
{
282+
return ($class->allowsNull() ? '?' : '') . $this->getClassName($class->getName());
283+
}
284+
elseif ('ReflectionUnionType' == $className)
285+
{
286+
$types = $class->getTypes();
287+
$value = $bar = '';
288+
289+
foreach ($types as $type)
290+
{
291+
$value .= $bar;
292+
$bar = '|';
293+
$value .= $this->getClassName($type);
294+
}
295+
296+
return $value;
297+
}
298+
elseif ('ReflectionIntersectionType' == $className)
299+
{
300+
$types = $class->getTypes();
301+
$value = '(';
302+
$bar = '';
303+
304+
foreach ($types as $type)
305+
{
306+
$value .= $bar;
307+
$bar = '&';
308+
$value .= $this->getClassName($type->getName());
309+
}
310+
311+
return $value . ')';
312+
}
313+
314+
315+
return $this->getClassName($class::class);
316+
317+
}
318+
309319
if ($asLink && $class)
310320
{
311321
// could be mixed, break out by |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace PHPFUI\InstaDoc\Tests;
4+
5+
trait ConstantsAllowed82
6+
{
7+
public const CONSTANT = 1;
8+
9+
public function bar() : int
10+
{
11+
return Foo::CONSTANT;
12+
}
13+
}

src/PHPFUI/InstaDoc/Tests/Test82.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace PHPFUI\InstaDoc\Tests;
4+
5+
/**
6+
* A test class with no functionality.
7+
*
8+
* <b>It is just to test InstaDoc</b>
9+
*
10+
* @author bruce (12/22/2022)
11+
*/
12+
readonly class Test82
13+
{
14+
private Status $status;
15+
16+
public function __construct(private ?Status $enum = Status::Published)
17+
{
18+
}
19+
20+
public function disjunctiveNormalFormTypes((ConstantsAllowed82 & Status) | null $post) : void
21+
{
22+
}
23+
24+
public function takeAndReturnEnum(?Status $enum = null) : Status
25+
{
26+
return $enum;
27+
}
28+
29+
final public function intersectionTypesFinal(\Iterator & \Countable $collection) : never
30+
{
31+
exit;
32+
}
33+
34+
protected function alwaysTrue() : true
35+
{
36+
return true;
37+
}
38+
39+
protected function alwaysNull() : null
40+
{
41+
return null;
42+
}
43+
44+
private function alwaysFalse() : false
45+
{
46+
return false;
47+
}
48+
}

tests/SectionTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ public function testHomePage() : void
9999
$this->assertNotWarningHtml("{$page}");
100100
}
101101

102+
public function testMarkDown() : void
103+
{
104+
$parser = new \PHPFUI\InstaDoc\MarkDownParser();
105+
106+
$html = $parser->fileText(__DIR__ . '/../README.md');
107+
$this->assertValidHtml("{$html}");
108+
$this->assertNotWarningHtml("{$html}");
109+
$this->assertStringNotContainsStringIgnoringCase('simple_html_dom__voku__html_wrapper', $html);
110+
}
111+
102112
public function testInvalidPage() : void
103113
{
104114
$this->controller->setParameters($this->controller->getClassParts('\\Fred\\Flintstone\\Bedrock'));
@@ -110,7 +120,7 @@ public function testTestClass() : void
110120
{
111121
$runningPHPVersion = PHP_MAJOR_VERSION * 10 + PHP_MINOR_VERSION;
112122

113-
foreach ([81, 80, 74, 73, 72, 71] as $phpVersion)
123+
foreach ([82, 81, 80, 74, 73, 72, 71] as $phpVersion)
114124
{
115125
if ($runningPHPVersion >= $phpVersion)
116126
{

0 commit comments

Comments
 (0)