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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- hhvm
- nightly

Expand All @@ -24,5 +26,7 @@ after_script:

matrix:
allow_failures:
- php: 5.3
- php: hhvm
- php: nightly
- php: hhvm
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PHP ?= 7.3

composer-update:
docker-compose run --rm composer composer config platform.php ${PHP}
docker-compose run --rm composer composer update
docker-compose run --rm composer composer config --unset platform

test:
docker-compose run --rm php-${PHP} php -v
docker-compose run --rm php-${PHP} php /app/vendor/bin/phpunit -c /app/phpunit.xml.dist
test-local:
php -v
php vendor/bin/phpunit
19 changes: 19 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'

services:

composer:
image: 'composer:1.6'
volumes: ['.:/app']

# PHP 5.3 contains neither mbstring extension nor docker-php-ext-install script
# Original Dockerfile can be found here https://github.com/docker-library/php/pull/20/files
# Unfortunately it fails to build now because GPG signatures do not exist anymore
# php-5.3: { build: 'docker/php-5.3', volumes: ['.:/app'] }
php-5.4: { build: 'docker/php-5.4', volumes: ['.:/app'] }
php-5.5: { image: 'php:5.5', volumes: ['.:/app'] }
php-5.6: { image: 'php:5.6', volumes: ['.:/app'] }
php-7.0: { image: 'php:7.0', volumes: ['.:/app'] }
php-7.1: { image: 'php:7.1', volumes: ['.:/app'] }
php-7.2: { image: 'php:7.2', volumes: ['.:/app'] }
php-7.3: { image: 'php:7.3', volumes: ['.:/app'] }
3 changes: 3 additions & 0 deletions docker/php-5.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM php:5.4

RUN docker-php-ext-install mbstring
1 change: 0 additions & 1 deletion src/Event/ReplaceShortcodesEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct($text, array $replacements, ShortcodeInterface $shor
{
$this->shortcode = $shortcode;
$this->text = $text;
$this->result = null;

$this->setReplacements($replacements);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventContainer/EventContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()

public function addListener($event, $handler)
{
if(!in_array($event, Events::getEvents())) {
if(!\in_array($event, Events::getEvents(), true)) {
throw new \InvalidArgumentException(sprintf('Unsupported event %s!', $event));
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventHandler/FilterRawEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(array $names)
public function __invoke(FilterShortcodesEvent $event)
{
$parent = $event->getParent();
if($parent && in_array($parent->getName(), $this->names)) {
if($parent && \in_array($parent->getName(), $this->names, true)) {
$event->setShortcodes(array());

return;
Expand Down
2 changes: 1 addition & 1 deletion src/HandlerContainer/HandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getNames()

public function get($name)
{
return $this->has($name) ? $this->handlers[$name] : ($this->default ?: null);
return $this->has($name) ? $this->handlers[$name] : $this->default;
}

public function has($name)
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/WordpressParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static function parseParameters($text)
$parameters[strtolower($match[3])] = stripcslashes($match[4]);
} elseif(!empty($match[5])) {
$parameters[strtolower($match[5])] = stripcslashes($match[6]);
} elseif(isset($match[7]) && strlen($match[7])) {
} elseif(isset($match[7]) && $match[7] !== '') {
$parameters[stripcslashes($match[7])] = null;
} elseif(isset($match[8])) {
$parameters[stripcslashes($match[8])] = null;
Expand Down
5 changes: 3 additions & 2 deletions src/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final class Processor implements ProcessorInterface
/** @var EventContainerInterface */
private $eventContainer;

private $recursionDepth = null; // infinite recursion
/** @var int|null */
private $recursionDepth; // infinite recursion
private $maxIterations = 1; // one iteration
private $autoProcessContent = true; // automatically process shortcode content

Expand Down Expand Up @@ -144,7 +145,7 @@ private function processHandler(ParsedShortcodeInterface $parsed, ProcessorConte
return mb_substr($state, 0, $offset, 'utf-8').$processed->getContent().mb_substr($state, $offset + $length, mb_strlen($state, 'utf-8'), 'utf-8');
}

private function processRecursion(ParsedShortcodeInterface $shortcode, ProcessorContext $context)
private function processRecursion(ProcessedShortcode $shortcode, ProcessorContext $context)
{
if ($this->autoProcessContent && null !== $shortcode->getContent()) {
$context->recursionLevel++;
Expand Down
12 changes: 6 additions & 6 deletions src/Processor/ProcessorContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
final class ProcessorContext
{
/** @var ShortcodeInterface */
public $shortcode = null;
public $shortcode;

/** @var ShortcodeInterface */
public $parent = null;
public $parent;

/** @var ProcessorInterface */
public $processor = null;
public $processor;

public $textContent = null;
public $textContent;
public $position = 0;
public $namePosition = array();
public $text = '';
public $shortcodeText = '';
public $iterationNumber = 0;
public $recursionLevel = 0;
public $offset = null;
public $baseOffset = null;
public $offset;
public $baseOffset;
}
2 changes: 1 addition & 1 deletion src/Serializer/TextSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function serializeValue($value)
$delimiter = $this->syntax->getParameterValueDelimiter();
$separator = $this->syntax->getParameterValueSeparator();

return $separator.(preg_match('/^\w+$/us', $value)
return $separator.(preg_match('/^\w+$/u', $value)
? $value
: $delimiter.$value.$delimiter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Shortcode/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ final class Shortcode extends AbstractShortcode implements ShortcodeInterface
{
public function __construct($name, array $parameters, $content, $bbCode = null)
{
if(false === is_string($name) || (is_string($name) && !mb_strlen($name))) {
if(false === is_string($name) || '' === $name) {
throw new \InvalidArgumentException('Shortcode name must be a non-empty string!');
}

$isStringOrNull = function($value) { return is_string($value) || is_null($value); };
$isStringOrNull = function($value) { return is_string($value) || null === $value; };
if(count(array_filter($parameters, $isStringOrNull)) !== count($parameters)) {
throw new \InvalidArgumentException('Parameter values must be either string or empty (null)!');
}
Expand Down