From e6f2ab0806d1a84e5bd2302ee5a643549023c137 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Tue, 15 Aug 2023 16:46:06 +0200 Subject: [PATCH] Fix PHPDoc --- src/Phug/Ast/Ast/Node.php | 1 - .../NodeCompiler/AssignmentNodeCompiler.php | 1 - .../NodeCompiler/AttributeNodeCompiler.php | 1 - .../Compiler/Compiler/NodeCompilerInterface.php | 2 +- src/Phug/Formatter/Formatter/AbstractFormat.php | 11 +++++++---- src/Phug/Formatter/Formatter/Format/XmlFormat.php | 2 +- .../Formatter/Partial/AssignmentHelpersTrait.php | 2 +- src/Phug/Lexer/Lexer/State.php | 9 ++++----- src/Phug/Parser/Parser.php | 2 +- src/Phug/Parser/Parser/Event/NodeEvent.php | 5 +++-- src/Phug/Reader/Reader.php | 6 +++--- src/Phug/Renderer/Renderer/CacheInterface.php | 2 +- .../Renderer/Partial/Debug/DebuggerTrait.php | 3 +++ src/Phug/Renderer/Renderer/Profiler/LinkDump.php | 4 ++-- src/Phug/Util/Util/OrderedValue.php | 1 + src/Phug/Util/Util/Partial/OrderTrait.php | 4 ---- tests/Phug/AbstractCompilerTest.php | 1 - tests/Phug/Adapter/FileAdapterTest.php | 4 ++++ tests/Phug/Ast/NodeTest.php | 8 ++++++++ tests/Phug/CompilerTest.php | 14 ++++++++++++++ tests/Phug/Util/UnorderedArgumentsTest.php | 8 ++++++++ 21 files changed, 62 insertions(+), 29 deletions(-) diff --git a/src/Phug/Ast/Ast/Node.php b/src/Phug/Ast/Ast/Node.php index 8b646c30..5dbdc8e9 100644 --- a/src/Phug/Ast/Ast/Node.php +++ b/src/Phug/Ast/Ast/Node.php @@ -370,7 +370,6 @@ public function findChildren(callable $callback, $depth = null, $level = null) $level = $level ?: 0; foreach ($this->children as $child) { - /** @var NodeInterface $child */ if ($child->is($callback)) { yield $child; diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php index 3048ce6c..74df6392 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php @@ -8,7 +8,6 @@ use Phug\Parser\Node\AssignmentNode; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; -use Phug\Util\AttributesStorage; use Phug\Util\OrderableInterface; use SplObjectStorage; diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php index 76bfb299..896c9145 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php @@ -9,7 +9,6 @@ use Phug\Formatter\ElementInterface; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; -use Phug\Util\OrderableInterface; class AttributeNodeCompiler extends AbstractNodeCompiler { diff --git a/src/Phug/Compiler/Compiler/NodeCompilerInterface.php b/src/Phug/Compiler/Compiler/NodeCompilerInterface.php index ae9a5d6e..1522f816 100644 --- a/src/Phug/Compiler/Compiler/NodeCompilerInterface.php +++ b/src/Phug/Compiler/Compiler/NodeCompilerInterface.php @@ -11,7 +11,7 @@ interface NodeCompilerInterface { /** - * @param $nodeList + * @param $nodeList * @param ElementInterface $parent * * @return array diff --git a/src/Phug/Formatter/Formatter/AbstractFormat.php b/src/Phug/Formatter/Formatter/AbstractFormat.php index 963297f4..20d1aad5 100644 --- a/src/Phug/Formatter/Formatter/AbstractFormat.php +++ b/src/Phug/Formatter/Formatter/AbstractFormat.php @@ -460,13 +460,16 @@ protected function formatDynamicValue($formattedName, $value) return 'null'; } - if ($value instanceof ExpressionElement && - in_array(($code = strtolower($value->getValue())), ['true', 'false', 'null', 'undefined']) - ) { - return $code; + if ($value instanceof ExpressionElement) { + $code = strtolower($value->getValue()); + + if (in_array($code, ['true', 'false', 'null', 'undefined'])) { + return $code; + } } $code = $this->formatAssignmentValue($value); + if ($value instanceof ExpressionElement && $value->isEscaped()) { return $this->exportHelper('array_escape', [$formattedName, $code]); } diff --git a/src/Phug/Formatter/Formatter/Format/XmlFormat.php b/src/Phug/Formatter/Formatter/Format/XmlFormat.php index c4da4062..923f539f 100644 --- a/src/Phug/Formatter/Formatter/Format/XmlFormat.php +++ b/src/Phug/Formatter/Formatter/Format/XmlFormat.php @@ -559,7 +559,7 @@ protected function formatMarkupElement(MarkupElement $element) /** * @param AssignmentContainerInterface|AttributesInterface|mixed $markup - * @param Closure(OrderedValue, OrderedValue): int $sorter + * @param Closure(OrderedValue, OrderedValue): int $sorter * * @return list */ diff --git a/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php b/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php index 93c87071..f5ec8c3b 100644 --- a/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php +++ b/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php @@ -37,7 +37,7 @@ function ($attributeAssignments) { return function (&$attributes, $name, $value) use ($attributeAssignments) { if (isset($name) && $name !== '') { $result = $attributeAssignments($attributes, $name, $value); - if (($result !== null && $result !== false && ($result !== '' || $name !== 'class'))) { + if ($result !== null && $result !== false && ($result !== '' || $name !== 'class')) { $attributes[$name] = $result; } } diff --git a/src/Phug/Lexer/Lexer/State.php b/src/Phug/Lexer/Lexer/State.php index c7f0d054..a1c7f5a2 100644 --- a/src/Phug/Lexer/Lexer/State.php +++ b/src/Phug/Lexer/Lexer/State.php @@ -241,7 +241,6 @@ public function scan($scanners, array $options = []) $scanners = $this->filterScanners($scanners); foreach ($scanners as $scanner) { - /** @var ScannerInterface $scanner */ $success = false; foreach ($scanner->scan($this, $options) as $token) { @@ -267,7 +266,7 @@ public function scan($scanners, array $options = []) * If the second argument is true, it will throw an exception if none of the scanners * produced any valid tokens. The reading also stops when the end of the input as been reached. * - * @param $scanners + * @param $scanners * @param bool $required * * @throws LexerException @@ -346,9 +345,9 @@ public function createToken($className) * in scanners as you can simply return it's value without having to check for it to be null. * * - * @param $className - * @param $pattern - * @param null $modifiers + * @param class-string $className + * @param string $pattern + * @param string|null $modifiers * * @return iterable */ diff --git a/src/Phug/Parser/Parser.php b/src/Phug/Parser/Parser.php index bca4a48f..1f807255 100644 --- a/src/Phug/Parser/Parser.php +++ b/src/Phug/Parser/Parser.php @@ -330,8 +330,8 @@ public function parse($input, $path = null) foreach ($expandingNodes as $expandingNode) { $current = $expandingNode; - while ($outerNode = $expandingNode->getOuterNode()) { + while ($outerNode = $expandingNode->getOuterNode()) { /** @var NodeInterface $expandedNode */ $expandedNode = $outerNode; $current->setOuterNode(null); diff --git a/src/Phug/Parser/Parser/Event/NodeEvent.php b/src/Phug/Parser/Parser/Event/NodeEvent.php index 9502eb0c..e45ca7ab 100644 --- a/src/Phug/Parser/Parser/Event/NodeEvent.php +++ b/src/Phug/Parser/Parser/Event/NodeEvent.php @@ -4,6 +4,7 @@ use Phug\Event; use Phug\Parser\NodeInterface; +use Phug\ParserEvent; class NodeEvent extends Event { @@ -12,8 +13,8 @@ class NodeEvent extends Event /** * NodeEvent constructor. * - * @param $name - * @param NodeInterface $node + * @param ParserEvent::* $name + * @param NodeInterface $node */ public function __construct($name, NodeInterface $node) { diff --git a/src/Phug/Reader/Reader.php b/src/Phug/Reader/Reader.php index 5cc93461..8b28ba24 100644 --- a/src/Phug/Reader/Reader.php +++ b/src/Phug/Reader/Reader.php @@ -313,9 +313,9 @@ public function peek($length = null, $start = null) * * Notice that ^ is automatically prepended to the pattern. * - * @param string $pattern the regular expression without slashes or modifiers. - * @param string $modifiers the modifiers for the regular expression. - * @param string $ignoredSuffixes characters that are scanned, but don't end up in the consume length. + * @param string $pattern the regular expression without slashes or modifiers. + * @param string|null $modifiers the modifiers for the regular expression. + * @param string|null $ignoredSuffixes characters that are scanned, but don't end up in the consume length. * * @throws ReaderException * diff --git a/src/Phug/Renderer/Renderer/CacheInterface.php b/src/Phug/Renderer/Renderer/CacheInterface.php index c1968eca..d7260197 100644 --- a/src/Phug/Renderer/Renderer/CacheInterface.php +++ b/src/Phug/Renderer/Renderer/CacheInterface.php @@ -11,7 +11,7 @@ interface CacheInterface /** * Return the cached file path after cache optional process. * - * @param $path + * @param string $path * @param string $input pug input * @param callable $rendered method to compile the source into PHP * @param bool $success diff --git a/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php b/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php index fe5c1aec..42a69d84 100644 --- a/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php +++ b/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php @@ -180,6 +180,7 @@ private function getRendererException($error, $code, $line, $offset, $source, $s /** * @return bool + * * @codeCoverageIgnore */ private function hasColorSupport() @@ -200,6 +201,7 @@ private function hasColorSupport() /** * @return bool + * * @codeCoverageIgnore */ private function hasStdOutVt100Support() @@ -211,6 +213,7 @@ private function hasStdOutVt100Support() /** * @return bool + * * @codeCoverageIgnore */ private function isStdOutATTY() diff --git a/src/Phug/Renderer/Renderer/Profiler/LinkDump.php b/src/Phug/Renderer/Renderer/Profiler/LinkDump.php index 28388312..65897c34 100644 --- a/src/Phug/Renderer/Renderer/Profiler/LinkDump.php +++ b/src/Phug/Renderer/Renderer/Profiler/LinkDump.php @@ -33,11 +33,11 @@ private function initProperties($name, $events) foreach ([ ['current', EndLexEvent::class, 'lexing', [ 'background' => '#7200c4', - 'color' => 'white', + 'color' => 'white', ]], ['current', HtmlEvent::class, 'rendering', [ 'background' => '#648481', - 'color' => 'white', + 'color' => 'white', ]], ['previous', CompileEvent::class, '%s', [ 'background' => '#ffff78', diff --git a/src/Phug/Util/Util/OrderedValue.php b/src/Phug/Util/Util/OrderedValue.php index ef11b69d..897f9c5f 100644 --- a/src/Phug/Util/Util/OrderedValue.php +++ b/src/Phug/Util/Util/OrderedValue.php @@ -9,6 +9,7 @@ * Class OrderedValue. * * @template T + * * @template-implements ValueTrait */ class OrderedValue implements OrderableInterface diff --git a/src/Phug/Util/Util/Partial/OrderTrait.php b/src/Phug/Util/Util/Partial/OrderTrait.php index fd30a142..72a73398 100644 --- a/src/Phug/Util/Util/Partial/OrderTrait.php +++ b/src/Phug/Util/Util/Partial/OrderTrait.php @@ -2,10 +2,6 @@ namespace Phug\Util\Partial; -use ArrayAccess; -use ArrayObject; -use Phug\Util\Collection; - trait OrderTrait { /** diff --git a/tests/Phug/AbstractCompilerTest.php b/tests/Phug/AbstractCompilerTest.php index 259d51e2..2dab4758 100644 --- a/tests/Phug/AbstractCompilerTest.php +++ b/tests/Phug/AbstractCompilerTest.php @@ -78,7 +78,6 @@ protected function enableJsPhpize() }); $compiler->attach(CompilerEvent::OUTPUT, function (Compiler\Event\OutputEvent $event) use ($compiler) { - /** @var JsPhpize $jsPhpize */ $jsPhpize = $compiler->getOption('jsphpize_engine'); $dependencies = $jsPhpize->compileDependencies(); diff --git a/tests/Phug/Adapter/FileAdapterTest.php b/tests/Phug/Adapter/FileAdapterTest.php index a3b81851..e4746127 100644 --- a/tests/Phug/Adapter/FileAdapterTest.php +++ b/tests/Phug/Adapter/FileAdapterTest.php @@ -575,7 +575,9 @@ public function testCacheRenderString() * @covers \Phug\Renderer\Adapter\FileAdapter::cacheDirectory * @covers \Phug\Renderer\Adapter\FileAdapter::getCacheDirectory * @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::getDebuggedException + * * @expectedException \RuntimeException + * * @expectedExceptionCode 5 */ public function testMissingDirectory() @@ -594,7 +596,9 @@ public function testMissingDirectory() * @covers \Phug\Renderer\Adapter\FileAdapter::cacheDirectory * @covers \Phug\Renderer\Adapter\FileAdapter::cache * @covers \Phug\Renderer\Adapter\FileAdapter::displayCached + * * @expectedException \RuntimeException + * * @expectedExceptionCode 6 */ public function testReadOnlyDirectory() diff --git a/tests/Phug/Ast/NodeTest.php b/tests/Phug/Ast/NodeTest.php index 4e2f66b0..ffc8e10b 100644 --- a/tests/Phug/Ast/NodeTest.php +++ b/tests/Phug/Ast/NodeTest.php @@ -282,6 +282,7 @@ public function testGetChildAt() /** * @covers ::getChildAt + * * @expectedException \Phug\AstException */ public function testGetChildAtWithInvalidOffset() @@ -309,6 +310,7 @@ public function testRemoveChildAt() /** * @covers ::removeChildAt + * * @expectedException \Phug\AstException */ public function testRemoveChildAtWithInvalidOffset() @@ -447,7 +449,9 @@ public function testFindChildren() /** * @covers ::insertBefore + * * @expectedException \Phug\AstException + * * @expectedExceptionMessage Failed to insert before: Passed child is not a child of element to insert in */ public function testInsertBeforeWithBadSibling() @@ -481,7 +485,9 @@ public function testInsertBefore() /** * @covers ::insertAfter + * * @expectedException \Phug\AstException + * * @expectedExceptionMessage Failed to insert after: Passed child is not a child of element to insert in */ public function testInsertAfterWithBadSibling() @@ -562,7 +568,9 @@ public function testGetIterator() /** * @covers ::offsetSet + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Argument 2 passed to Node->offsetSet needs to be instance of Phug\Ast\NodeInterface */ public function testOffsetSetInvalidArgument() diff --git a/tests/Phug/CompilerTest.php b/tests/Phug/CompilerTest.php index a96f18ad..e65753aa 100644 --- a/tests/Phug/CompilerTest.php +++ b/tests/Phug/CompilerTest.php @@ -162,6 +162,7 @@ public function testGetCompiledChildren() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testParserClassException() @@ -180,6 +181,7 @@ public function testParserClassException() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testFormatterClassException() @@ -198,6 +200,7 @@ public function testFormatterClassException() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testLocatorClassException() @@ -213,6 +216,7 @@ public function testLocatorClassException() /** * @covers ::setNodeCompiler + * * @expectedException \InvalidArgumentException */ public function testSetNodeCompilerException() @@ -228,6 +232,7 @@ public function testSetNodeCompilerException() /** * @covers ::compileNode + * * @expectedException \Phug\CompilerException */ public function testCompileNodeException() @@ -246,6 +251,7 @@ public function testCompileNodeException() * @covers ::locate * @covers ::resolve * @covers \Phug\Compiler\NodeCompiler\ImportNodeCompiler::compileNode + * * @expectedException \Phug\CompilerException */ public function testAbsolutePathWithoutPaths() @@ -283,7 +289,9 @@ public function testResolve() /** * @covers ::resolve + * * @expectedException \Phug\CompilerException + * * @expectedExceptionMessage Source file not-existent not found */ public function testResolveNotFoundException() @@ -409,6 +417,7 @@ function ($name) { /** * @covers ::throwException + * * @expectedException \Phug\CompilerException */ public function testThrowException() @@ -419,7 +428,9 @@ public function testThrowException() /** * @covers ::throwException + * * @expectedException \Phug\CompilerException + * * @expectedExceptionMessage foobar.pug */ public function testThrowExceptionFileName() @@ -441,6 +452,7 @@ public function testAssertSuccess() /** * @covers ::assert + * * @expectedException \Phug\CompilerException */ public function testAssertFailure() @@ -451,7 +463,9 @@ public function testAssertFailure() /** * @covers ::initializeFormatter + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Passed formatter class stdClass is not a valid Phug\Formatter */ public function testInitializeFormatterException() diff --git a/tests/Phug/Util/UnorderedArgumentsTest.php b/tests/Phug/Util/UnorderedArgumentsTest.php index 02c68a30..953edc22 100644 --- a/tests/Phug/Util/UnorderedArgumentsTest.php +++ b/tests/Phug/Util/UnorderedArgumentsTest.php @@ -47,7 +47,9 @@ public function testRequired() /** * @covers ::required + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Arguments miss one of the boolean type */ public function testRequiredException() @@ -72,7 +74,9 @@ public function testNoMoreArguments() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 2 unexpected arguments */ public function testNoMoreArgumentsException() @@ -87,7 +91,9 @@ public function testNoMoreArgumentsException() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 2 unexpected arguments */ public function testNoMoreUndefinedArgumentsException() @@ -103,7 +109,9 @@ public function testNoMoreUndefinedArgumentsException() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 1 unexpected not null arguments */ public function testNoMoreDefinedArgumentsException()