Skip to content

Commit

Permalink
- updated GitHub workflow to support PHP 8.4 and the latest nightly,
Browse files Browse the repository at this point in the history
- fixed workflow issue to correctly install Psalm 5.x,
- adjusted PHPUnit XML file with the latest version structure,
- hardened lots of places with old PHP conditions reported with RiskyTruthyFalsyComparison,
- hardened lots of places with string docblocks using non-empty-string,
- adjusted dataProviders methods to be static.
  • Loading branch information
thunderer committed Dec 15, 2024
1 parent 65d8b29 commit a19b8ef
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-old.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: ['ubuntu-latest']
steps:
- name: 'Checkout'
uses: 'actions/checkout@v2'
uses: 'actions/checkout@v4'
- name: 'Install PHP'
uses: 'shivammathur/setup-php@v2'
with:
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:
runs-on: '${{ matrix.os }}'
strategy:
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
os: ['ubuntu-latest']
failure: [false]
include:
- { php: '8.3', os: 'ubuntu-latest', failure: true } # '8.3' means 'nightly'
- { php: '8.4', os: 'ubuntu-latest', failure: true } # Psalm does not support PHP 8.4 yet
- { php: '8.5', os: 'ubuntu-latest', failure: true } # '8.5' means 'nightly'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v2'
uses: 'actions/checkout@v4'
- name: 'Install PHP'
uses: 'shivammathur/setup-php@v2'
with:
Expand All @@ -36,11 +37,13 @@ jobs:
continue-on-error: '${{ matrix.failure }}'
- name: 'Psalm'
run: |
composer require --dev vimeo/psalm
composer remove --dev -W 'phpunit/phpunit'
composer require --dev -W 'vimeo/psalm=^5.0' 'nikic/php-parser=^4.0'
php vendor/bin/psalm --shepherd --php-version=${{ matrix.php }}
continue-on-error: '${{ matrix.failure }}'
- name: 'Infection'
run: |
composer require --dev --with-all-dependencies infection/infection
composer remove --dev -W 'vimeo/psalm'
composer require --dev -W phpunit/phpunit infection/infection
php vendor/bin/infection
continue-on-error: '${{ matrix.failure }}'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2023 Tomasz Kowalczyk
Copyright (c) 2015-2025 Tomasz Kowalczyk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Each part is described in the dedicated section in this document.

## Installation

There are no required dependencies and all PHP versions from 5.3 up to latest 8.1 [are tested](https://github.com/thunderer/Shortcode/actions/workflows/test.yaml) and supported. This library is available on Composer/Packagist as `thunderer/shortcode`, to install it execute:
There are no required dependencies and all PHP versions from 5.3 up to latest 8.x [are tested](https://github.com/thunderer/Shortcode/actions/workflows/test.yaml) and supported. This library is available on Composer/Packagist as `thunderer/shortcode`, to install it execute:

```
composer require thunderer/shortcode=^0.7
Expand Down
17 changes: 8 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
backupGlobals = "false"
processIsolation = "false"
stopOnFailure = "false"
bootstrap = "vendor/autoload.php"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd">

<source>
<include>
<directory>src</directory>
</include>
</source>

<testsuites>
<testsuite name="Shortcode">
Expand All @@ -19,9 +21,6 @@
</testsuites>

<coverage>
<include>
<directory>src</directory>
</include>
<report>
<html outputDirectory="coverage/html" lowUpperBound="50" highLowerBound="90" />
</report>
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/EmailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class EmailHandler
*/
public function __invoke(ShortcodeInterface $shortcode)
{
$email = $shortcode->getBbCode() ?: $shortcode->getContent();
$email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent();
$content = $shortcode->getContent() === null ? $email : $shortcode->getContent();

return '<a href="mailto:'.(string)$email.'">'.(string)$content.'</a>';

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.0, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.0, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.4, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.4, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.1, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.1, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.3, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.3, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.5, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.5, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.2, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . $email . '">' . (string) $content . '</a>'; } }

Check warning on line 25 in src/Handler/EmailHandler.php

View workflow job for this annotation

GitHub Actions / test (8.2, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ { $email = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); - return '<a href="mailto:' . (string) $email . '">' . (string) $content . '</a>'; + return '<a href="mailto:' . (string) $email . '">' . $content . '</a>'; } }
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/UrlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class UrlHandler
*/
public function __invoke(ShortcodeInterface $shortcode)
{
$url = $shortcode->getBbCode() ?: $shortcode->getContent();
$url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent();

return '<a href="'.(string)$url.'">'.(string)$shortcode->getContent().'</a>';

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.0, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.0, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.4, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.4, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.1, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.1, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.3, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.3, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.5, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.5, ubuntu-latest, true)

Escaped Mutant for Mutator "CastString": @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.2, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . $url . '">' . (string) $shortcode->getContent() . '</a>'; } }

Check warning on line 24 in src/Handler/UrlHandler.php

View workflow job for this annotation

GitHub Actions / test (8.2, ubuntu-latest, false)

Escaped Mutant for Mutator "CastString": --- Original +++ New @@ @@ public function __invoke(ShortcodeInterface $shortcode) { $url = null !== $shortcode->getBbCode() ? $shortcode->getBbCode() : $shortcode->getContent(); - return '<a href="' . (string) $url . '">' . (string) $shortcode->getContent() . '</a>'; + return '<a href="' . (string) $url . '">' . $shortcode->getContent() . '</a>'; } }
}
Expand Down
6 changes: 3 additions & 3 deletions src/Parser/RegexParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ final class RegexParser implements ParserInterface
{
/** @var SyntaxInterface */
private $syntax;
/** @var string */
/** @var non-empty-string */
private $shortcodeRegex;
/** @var string */
/** @var non-empty-string */
private $singleShortcodeRegex;
/** @var string */
/** @var non-empty-string */
private $parametersRegex;

public function __construct(SyntaxInterface $syntax = null)
Expand Down
10 changes: 6 additions & 4 deletions src/Parser/RegularParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/
final class RegularParser implements ParserInterface
{
/** @var string */
/** @var non-empty-string */
private $lexerRegex;
/** @var string */
/** @var non-empty-string */
private $nameRegex;
/** @psalm-var list<array{0:int,1:string,2:int}> */
private $tokens = array();
Expand Down Expand Up @@ -184,6 +184,7 @@ private function shortcode(array &$names)
return array_merge(array($this->getObject($name, $parameters, $bbCode, $offset, null, $text)), $shortcodes);
}
$content = $this->getBacktrack();
/** @psalm-suppress RiskyTruthyFalsyComparison */
if(!$this->close($names)) { return false; }
array_pop($names);

Expand Down Expand Up @@ -314,6 +315,7 @@ private function match($type, $ws)
}

$token = $this->tokens[$this->position];
/** @psalm-suppress RiskyTruthyFalsyComparison */
if(!empty($type) && $token[0] !== $type) {
return '';
}
Expand Down Expand Up @@ -352,7 +354,7 @@ private function tokenize($text)
case -1 !== $match['separator'][1]: { $token = $match['separator'][0]; $type = self::TOKEN_SEPARATOR; break; }
case -1 !== $match['open'][1]: { $token = $match['open'][0]; $type = self::TOKEN_OPEN; break; }
case -1 !== $match['close'][1]: { $token = $match['close'][0]; $type = self::TOKEN_CLOSE; break; }
default: { throw new \RuntimeException(sprintf('Invalid token.')); }
default: { throw new \RuntimeException('Invalid token.'); }
}
$tokens[] = array($type, $token, $position);
$position += mb_strlen($token, 'utf-8');
Expand All @@ -361,7 +363,7 @@ private function tokenize($text)
return $tokens;
}

/** @return string */
/** @return non-empty-string */
private function prepareLexer(SyntaxInterface $syntax)
{
// FIXME: for some reason Psalm does not understand the `@psalm-var callable() $var` annotation
Expand Down
6 changes: 4 additions & 2 deletions src/Parser/WordpressParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
*
* @see https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/shortcodes.php#L239
* @see https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/shortcodes.php#L448
* @psalm-suppress RiskyTruthyFalsyComparison
*
* @author Tomasz Kowalczyk <[email protected]>
*/
final class WordpressParser implements ParserInterface
{
/** @var string */
/** @var non-empty-string */
private static $shortcodeRegex = '/\\[(\\[?)(<NAMES>)(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/s';
/** @var string */
/** @var non-empty-string */
private static $argumentsRegex = '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';

/** @var string[] */
Expand Down Expand Up @@ -74,6 +75,7 @@ public function parse($text)
$names = $this->names
? implode('|', array_map(function($name) { return preg_quote($name, '/'); }, $this->names))
: RegexBuilderUtility::buildNameRegex();
/** @var non-empty-string $regex */
$regex = str_replace('<NAMES>', $names, static::$shortcodeRegex);
preg_match_all($regex, $text, $matches, PREG_OFFSET_CAPTURE);

Expand Down
2 changes: 1 addition & 1 deletion src/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private function processHandler(ParsedShortcodeInterface $parsed, ProcessorConte
$content = $this->processRecursion($processed, $context);
$processed = $processed->withContent($content);

if($handler) {
if(null !== $handler) {
return $handler($processed);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/XmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function getAttribute(\DOMNode $node, $name)
*/
$attribute = $node->attributes->getNamedItem($name);

/** @psalm-suppress DocblockTypeContradiction */
/** @psalm-suppress DocblockTypeContradiction,RiskyTruthyFalsyComparison */
if(!$attribute || !$attribute->nodeValue) {
throw new \InvalidArgumentException('Invalid shortcode XML!');
}
Expand Down
10 changes: 5 additions & 5 deletions src/Syntax/CommonSyntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
*/
final class CommonSyntax implements SyntaxInterface
{
/** @return string */
/** @return non-empty-string */
public function getOpeningTag()
{
return '[';
}

/** @return string */
/** @return non-empty-string */
public function getClosingTag()
{
return ']';
}

/** @return string */
/** @return non-empty-string */
public function getClosingTagMarker()
{
return '/';
}

/** @return string */
/** @return non-empty-string */
public function getParameterValueSeparator()
{
return '=';
}

/** @return string */
/** @return non-empty-string */
public function getParameterValueDelimiter()
{
return '"';
Expand Down
40 changes: 20 additions & 20 deletions src/Syntax/Syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
*/
final class Syntax implements SyntaxInterface
{
/** @var string|null */
/** @var non-empty-string|null */
private $openingTag;
/** @var string|null */
/** @var non-empty-string|null */
private $closingTag;
/** @var string|null */
/** @var non-empty-string|null */
private $closingTagMarker;
/** @var string|null */
/** @var non-empty-string|null */
private $parameterValueSeparator;
/** @var string|null */
/** @var non-empty-string|null */
private $parameterValueDelimiter;

/**
* @param string|null $openingTag
* @param string|null $closingTag
* @param string|null $closingTagMarker
* @param string|null $parameterValueSeparator
* @param string|null $parameterValueDelimiter
* @param non-empty-string|null $openingTag
* @param non-empty-string|null $closingTag
* @param non-empty-string|null $closingTagMarker
* @param non-empty-string|null $parameterValueSeparator
* @param non-empty-string|null $parameterValueDelimiter
*/
public function __construct(
$openingTag = null,
Expand All @@ -38,33 +38,33 @@ public function __construct(
$this->parameterValueDelimiter = $parameterValueDelimiter;
}

/** @return string */
/** @return non-empty-string */
public function getOpeningTag()
{
return $this->openingTag ?: '[';
return null !== $this->openingTag ? $this->openingTag : '[';
}

/** @return string */
/** @return non-empty-string */
public function getClosingTag()
{
return $this->closingTag ?: ']';
return null !== $this->closingTag ? $this->closingTag : ']';
}

/** @return string */
/** @return non-empty-string */
public function getClosingTagMarker()
{
return $this->closingTagMarker ?: '/';
return null !== $this->closingTagMarker ? $this->closingTagMarker : '/';
}

/** @return string */
/** @return non-empty-string */
public function getParameterValueSeparator()
{
return $this->parameterValueSeparator ?: '=';
return null !== $this->parameterValueSeparator ? $this->parameterValueSeparator : '=';
}

/** @return string */
/** @return non-empty-string */
public function getParameterValueDelimiter()
{
return $this->parameterValueDelimiter ?: '"';
return null !== $this->parameterValueDelimiter ? $this->parameterValueDelimiter : '"';
}
}
20 changes: 10 additions & 10 deletions src/Syntax/SyntaxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
final class SyntaxBuilder
{
/** @var string|null */
/** @var non-empty-string|null */
private $openingTag;
/** @var string|null */
/** @var non-empty-string|null */
private $closingTag;
/** @var string|null */
/** @var non-empty-string|null */
private $closingTagMarker;
/** @var string|null */
/** @var non-empty-string|null */
private $parameterValueSeparator;
/** @var string|null */
/** @var non-empty-string|null */
private $parameterValueDelimiter;

public function __construct()
Expand All @@ -34,7 +34,7 @@ public function getSyntax()
}

/**
* @param string $tag
* @param non-empty-string $tag
*
* @return $this
*/
Expand All @@ -46,7 +46,7 @@ public function setOpeningTag($tag)
}

/**
* @param string $tag
* @param non-empty-string $tag
*
* @return $this
*/
Expand All @@ -58,7 +58,7 @@ public function setClosingTag($tag)
}

/**
* @param string $marker
* @param non-empty-string $marker
*
* @return $this
*/
Expand All @@ -70,7 +70,7 @@ public function setClosingTagMarker($marker)
}

/**
* @param string $separator
* @param non-empty-string $separator
*
* @return $this
*/
Expand All @@ -82,7 +82,7 @@ public function setParameterValueSeparator($separator)
}

/**
* @param string $delimiter
* @param non-empty-string $delimiter
*
* @return $this
*/
Expand Down
Loading

0 comments on commit a19b8ef

Please sign in to comment.