Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ vendor: composer.json composer.lock

.PHONY: rector
rector: ## Refactor code using rector
$(PHP_BIN) vendor/bin/rector process packages
$(PHP_BIN) vendor/bin/rector process

.PHONY: pre-commit-test
pre-commit-test: fix-code-style test code-style static-code-analysis
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"league/flysystem-memory": "^1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-strict-rules": "^1.5",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^10.3",
"psalm/plugin-phpunit": "^0.18.4",
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions packages/guides-cli/src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

final class ContainerFactory
{
private ContainerBuilder $container;
private XmlFileLoader $configLoader;
private readonly ContainerBuilder $container;
private readonly XmlFileLoader $configLoader;

/** @var array<string, string> */
private array $registeredExtensions = [];
Expand All @@ -42,7 +42,7 @@ public function __construct(array $defaultExtensions = [])
$this->container = new ContainerBuilder();
$this->configLoader = new XmlFileLoader(new FileLocator());

foreach (array_merge([new GuidesExtension(), new ReStructuredTextExtension()], $defaultExtensions) as $extension) {
foreach ([new GuidesExtension(), new ReStructuredTextExtension(), ...$defaultExtensions] as $extension) {
$this->registerExtension($extension);
}
}
Expand All @@ -54,7 +54,7 @@ public function loadExtensionConfig(string $extension, array $config): void

$extensionAlias = $this->registeredExtensions[$extensionFqcn] ?? false;
if (!$extensionAlias) {
$this->registerExtension(new $extensionFqcn(), $config);
$this->registerExtension(new $extensionFqcn());

return;
}
Expand All @@ -72,15 +72,14 @@ public function create(string $vendorDir): Container
$this->processConfig();

$this->container->setParameter('vendor_dir', $vendorDir);
$this->container->setParameter('working_directory', $workingDirectory = rtrim(getcwd(), '/'));
$this->container->setParameter('working_directory', rtrim(getcwd(), '/'));

$this->container->compile(true);

return $this->container;
}

/** @param array<mixed> $config */
private function registerExtension(ExtensionInterface $extension, array $config = []): void
private function registerExtension(ExtensionInterface $extension): void
{
$this->container->registerExtension($extension);
$this->container->loadFromExtension($extension->getAlias());
Expand Down
2 changes: 1 addition & 1 deletion packages/guides-cli/tests/unit/Logger/SpyProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testHasBeenCalledReturnsFalseByDefault(): void
{
$spyProcessor = new SpyProcessor();

$this->assertFalse($spyProcessor->hasBeenCalled());
self::assertFalse($spyProcessor->hasBeenCalled());
}

public function testItKnowsWhenALogIsEmitted(): void
Expand Down
8 changes: 4 additions & 4 deletions packages/guides-graphs/tests/unit/Nodes/UmlNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function test_it_can_be_created_with_a_value(): void
{
$node = new UmlNode('value');

$this->assertSame('value', $node->getValue());
self::assertSame('value', $node->getValue());
}

public function test_you_can_set_a_caption_for_underneath_diagrams(): void
Expand All @@ -22,7 +22,7 @@ public function test_you_can_set_a_caption_for_underneath_diagrams(): void
$node = new UmlNode('value');
$node->setCaption($caption);

$this->assertSame($caption, $node->getCaption());
self::assertSame($caption, $node->getCaption());
}

public function test_you_can_pass_classes_for_in_templates(): void
Expand All @@ -32,7 +32,7 @@ public function test_you_can_pass_classes_for_in_templates(): void
$node = new UmlNode('value');
$node->setClasses($classes);

$this->assertSame($classes, $node->getClasses());
$this->assertSame('float-left my-class', $node->getClassesString());
self::assertSame($classes, $node->getClasses());
self::assertSame('float-left my-class', $node->getClassesString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function processSub(

$document->setClasses($normalizedClasses);

if (!$document instanceof DocumentNode || $document->getNodes() === []) {
if ($document->getNodes() === []) {
$classNode = new ClassNode($directive->getData());
$classNode->setClasses($classes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class BlockContext
{
private LinesIterator $documentIterator;
private readonly LinesIterator $documentIterator;

public function __construct(
private readonly DocumentParserContext $documentParserContext,
Expand Down Expand Up @@ -50,6 +50,6 @@ public function getLoggerInformation(): array
'currentLineNumber' => $this->lineOffset + $this->documentIterator->key(),
];

return array_merge($this->getDocumentParserContext()->getLoggerInformation(), $info);
return [...$this->documentParserContext->getLoggerInformation(), ...$info];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class DocumentParserContext
public bool $nextIndentedBlockShouldBeALiteralBlock = false;

public DocumentNode|null $document = null;

private int $currentTitleLevel;
/* Each Document has its own text role factory as text roles can be changed on a per document base
by directives */
private TextRoleFactory $textRoleFactoryForDocument;
private readonly TextRoleFactory $textRoleFactoryForDocument;

private string $codeBlockDefaultLanguage = '';

/** @var string[] */
Expand Down Expand Up @@ -79,7 +79,7 @@ public function setDocument(DocumentNode $document): void
{
$this->document = $document;
}

public function getLevel(string $overlineLetter, string $underlineLetter): int
{
$letter = $overlineLetter . ':' . $underlineLetter;
Expand All @@ -99,7 +99,7 @@ public function getTextRoleFactoryForDocument(): TextRoleFactory
{
return $this->textRoleFactoryForDocument;
}

public function getCodeBlockDefaultLanguage(): string
{
return $this->codeBlockDefaultLanguage;
Expand All @@ -109,7 +109,7 @@ public function setCodeBlockDefaultLanguage(string $codeBlockDefaultLanguage): v
{
$this->codeBlockDefaultLanguage = $codeBlockDefaultLanguage;
}

/** @return array<string, string> */
public function getLoggerInformation(): array
{
Expand All @@ -120,6 +120,6 @@ public function getLoggerInformation(): array
$info['documentNode'] = 'null';
}

return array_merge($this->getContext()->getLoggerInformation(), $info);
return [...$this->context->getLoggerInformation(), ...$info];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,48 +132,21 @@ protected function getType(string &$value)
return self::WHITESPACE;
}

switch ($value) {
case '`':
return self::BACKTICK;

case '**':
return self::STRONG_DELIMITER;

case '*':
return self::EMPHASIS_DELIMITER;

case '|':
return self::VARIABLE_DELIMITER;

case '<':
return self::EMBEDED_URL_START;

case '>':
return self::EMBEDED_URL_END;

case '_':
return self::UNDERSCORE;

case '__':
return self::ANONYMOUS_END;

case ':':
return self::COLON;

case '#':
return self::OCTOTHORPE;

case '[':
return self::ANNOTATION_START;

case ']':
return self::ANNOTATION_END;

case '~':
return self::NBSP;

default:
return self::WORD;
}
return match ($value) {
'`' => self::BACKTICK,
'**' => self::STRONG_DELIMITER,
'*' => self::EMPHASIS_DELIMITER,
'|' => self::VARIABLE_DELIMITER,
'<' => self::EMBEDED_URL_START,
'>' => self::EMBEDED_URL_END,
'_' => self::UNDERSCORE,
'__' => self::ANONYMOUS_END,
':' => self::COLON,
'#' => self::OCTOTHORPE,
'[' => self::ANNOTATION_START,
']' => self::ANNOTATION_END,
'~' => self::NBSP,
default => self::WORD,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class InlineParser
public function __construct(iterable $inlineRules)
{
$this->rules = [...$inlineRules];
usort($this->rules, static function (InlineRule $a, InlineRule $b): int {
return $a->getPriority() > $b->getPriority() ? -1 : 1;
});
usort($this->rules, static fn (InlineRule $a, InlineRule $b): int => $a->getPriority() > $b->getPriority() ? -1 : 1);
}

public function parse(string $content, BlockContext $blockContext): InlineCompoundNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

namespace phpDocumentor\Guides\RestructuredText\Parser;

use phpDocumentor\Guides\Nodes\Lists\ListItem;

use function in_array;
use function mb_strlen;
use function preg_match;
use function strlen;
use function trim;

class LineChecker
{
Expand Down Expand Up @@ -61,60 +56,13 @@ public static function isSpecialLine(string $line, int $minimumLength = 2): stri
return null;
}

for ($i = 1; $i < mb_strlen($line); $i++) {
$max = mb_strlen($line);
for ($i = 1; $i < $max; $i++) {
if ($line[$i] !== $letter) {
return null;
}
}

return $letter;
}

public function isListLine(string $line, bool $isCode): bool
{
$listLine = $this->parseListLine($line);

if ($listLine !== null) {
return $listLine->getDepth() === 0 || !$isCode;
}

return false;
}

private function parseListLine(string $line): ListItem|null
{
$depth = 0;

for ($i = 0; $i < strlen($line); $i++) {
$char = $line[$i];

if ($char === ' ') {
$depth++;
} elseif ($char === "\t") {
$depth += 2;
} else {
break;
}
}

if (preg_match('/^((\*|\-)|([\d#]+)\.) (.+)$/', trim($line), $match) > 0) {
return new ListItem(
$line[$i],
$line[$i] !== '*' && $line[$i] !== '-',
$depth,
[$match[4]],
);
}

if (strlen($line) === 1 && $line[0] === '-') {
return new ListItem(
$line[$i],
$line[$i] !== '*' && $line[$i] !== '-',
$depth,
[''],
);
}

return null;
}
}
Loading