Skip to content

Commit

Permalink
Add deprecation trigger for context extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapio committed Apr 12, 2024
1 parent a1ccdaa commit 76aaa48
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 313 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"doctrine/deprecations": "^1.1",
"phpdocumentor/guides": "^2.0@dev || ^1.0",
"phpdocumentor/guides-cli": "^2.0@dev || ^1.0",
"phpdocumentor/guides-code": "^2.0@dev || ^1.0",
Expand Down
638 changes: 329 additions & 309 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function givenInlineMarkupRule(): InlineMarkupRule
$inlineTokenParser->method('parse')->willReturnCallback(
static fn (string $arg): InlineCompoundNode => new InlineCompoundNode([
new PlainTextInlineNode($arg),
])
]),
);

return new InlineMarkupRule($inlineTokenParser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function getInlineTokenParserMock(): InlineParser
{
$inlineTokenParser = $this->createMock(InlineParser::class);
$inlineTokenParser->method('parse')->willReturnCallback(
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg)
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg),
);

return $inlineTokenParser;
Expand Down
1 change: 1 addition & 0 deletions packages/guides/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"php": "^8.1",
"ext-json": "*",
"ext-zlib": "*",
"doctrine/deprecations": "^1.0",
"league/flysystem": "^1.1",
"league/tactician": "^1.1",
"league/uri": "^7.4.1",
Expand Down
10 changes: 10 additions & 0 deletions packages/guides/src/Compiler/CompilerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace phpDocumentor\Guides\Compiler;

use Doctrine\Deprecations\Deprecation;
use Exception;
use phpDocumentor\Guides\Compiler\ShadowTree\TreeNode;
use phpDocumentor\Guides\Nodes\DocumentNode;
Expand All @@ -38,6 +39,15 @@ class CompilerContext implements CompilerContextInterface
public function __construct(
private readonly ProjectNode $projectNode,
) {
if (self::class === static::class) {
return;
}

Deprecation::trigger(
'phpdocumentor/guides',
'https://github.com/phpDocumentor/guides/issues/971',
'Extending CompilerContext is deprecated, please use the CompilerContextInterface instead.',
);
}

public function getProjectNode(): ProjectNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace phpDocumentor\Guides\Compiler\NodeTransformers;

use phpDocumentor\Guides\Compiler\CompilerContext;
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
use phpDocumentor\Guides\Compiler\CompilerPass;
use phpDocumentor\Guides\Compiler\DocumentNodeTraverser;
use phpDocumentor\Guides\Nodes\DocumentNode;
Expand Down
36 changes: 36 additions & 0 deletions packages/guides/tests/unit/Compiler/CompilerContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/

namespace phpDocumentor\Guides\Compiler;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use phpDocumentor\Guides\Nodes\ProjectNode;
use PHPUnit\Framework\TestCase;

final class CompilerContextTest extends TestCase
{
use VerifyDeprecations;

public function testTriggersDeprecationOnContextExtend(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971');
$context = new class (new ProjectNode()) extends CompilerContext{
};
}

public function testNoDeprecationOnNormalConstruct(): void
{
$this->expectNoDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971');
$context = new CompilerContext(new ProjectNode());
}
}
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ parameters:
count: 1
path: packages/guides-restructured-text/src/RestructuredText/Parser/Productions/ListRule.php

-
message: "#^Strict comparison using \\=\\=\\= between 'phpDocumentor\\\\\\\\Guides\\\\\\\\Compiler\\\\\\\\CompilerContext' and 'phpDocumentor\\\\\\\\Guides\\\\\\\\Compiler\\\\\\\\CompilerContext' will always evaluate to true\\.$#"
count: 1
path: packages/guides/src/Compiler/CompilerContext.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: packages/guides/src/Compiler/CompilerContext.php

-
message: "#^Function Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\tagged_iterator not found\\.$#"
count: 2
Expand All @@ -140,6 +150,11 @@ parameters:
count: 1
path: packages/guides/src/Renderer/DocumentListIterator.php

-
message: "#^Anonymous class extends @final class phpDocumentor\\\\Guides\\\\Compiler\\\\CompilerContext\\.$#"
count: 1
path: packages/guides/tests/unit/Compiler/CompilerContextTest.php

-
message: "#^Return type \\(iterable\\<phpDocumentor\\\\Guides\\\\Compiler\\\\NodeTransformers\\\\MoveAnchorTransformer\\>\\) of method class@anonymous/packages/guides/tests/unit/Compiler/NodeTransformers/MoveAnchorTransformerTest\\.php\\:32\\:\\:getTransformers\\(\\) should be compatible with return type \\(iterable\\<phpDocumentor\\\\Guides\\\\Compiler\\\\NodeTransformer\\<phpDocumentor\\\\Guides\\\\Nodes\\\\Node\\>\\>\\) of method phpDocumentor\\\\Guides\\\\Compiler\\\\NodeTransformers\\\\NodeTransformerFactory\\:\\:getTransformers\\(\\)$#"
count: 1
Expand Down
7 changes: 6 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.22.2@d768d914152dbbf3486c36398802f74e80cfde48">
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
<file src="packages/guides-cli/src/Config/Configuration.php">
<UndefinedMethod>
<code><![CDATA[ignoreExtraKeys]]></code>
Expand Down Expand Up @@ -55,6 +55,11 @@
<code><![CDATA[$result->value]]></code>
</InvalidPropertyAssignmentValue>
</file>
<file src="packages/guides/tests/unit/Compiler/CompilerContextTest.php">
<InvalidExtendClass>
<code><![CDATA[CompilerContext]]></code>
</InvalidExtendClass>
</file>
<file src="packages/guides/tests/unit/Compiler/NodeTransformers/DocumentEntryRegistrationTransformerTest.php">
<InvalidArgument>
<code><![CDATA[[new SectionNode(TitleNode::emptyNode())]]]></code>
Expand Down

0 comments on commit 76aaa48

Please sign in to comment.