Skip to content
Open
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
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
language: php
php:
- 5.6
- hhvm
- nightly
- 8.3
- 8.4

matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: nightly

git:
depth: 10
Expand All @@ -26,3 +22,6 @@ install:

after_success:
- php vendor/bin/coveralls -v

script:
- vendor/bin/phpunit
61 changes: 33 additions & 28 deletions JBBCode/CodeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,40 @@
class CodeDefinition
{
/** @var string NOTE: THIS PROPERTY SHOULD ALWAYS BE LOWERCASE; USE setTagName() TO ENSURE THIS */
protected $tagName;
protected string $tagName;

/** @var boolean Whether or not this CodeDefinition uses an option parameter. */
protected $useOption;
protected bool $useOption;

/** @var string The replacement text to be used for simple CodeDefinitions */
protected $replacementText;
protected string $replacementText;

/** @var boolean Whether or not to parse elements of this definition's contents */
protected $parseContent;
protected bool $parseContent;

/** @var integer How many of this element type may be nested within each other */
protected $nestLimit;
protected int $nestLimit;

/** @var integer How many of this element type have been seen */
protected $elCounter;
protected int $elCounter;

/** @var array[string]InputValidator The input validators to run options through */
protected $optionValidator;
protected array $optionValidator;

/** @var InputValidator The input validator to run the body ({param}) through */
protected $bodyValidator;
protected ?InputValidator $bodyValidator;

/**
* Constructs a new CodeDefinition.
*/
public static function construct($tagName, $replacementText, $useOption = false,
$parseContent = true, $nestLimit = -1, $optionValidator = array(),
$bodyValidator = null)
public static function construct(
string $tagName,
string $replacementText,
bool $useOption = false,
bool $parseContent = true,
int $nestLimit = -1,
array $optionValidator = [],
?InputValidator $bodyValidator = null): self
{
$def = new CodeDefinition();
$def->elCounter = 0;
Expand Down Expand Up @@ -81,7 +86,7 @@ public function __construct()
* @param ElementNode $el the ElementNode to validate
* @return boolean true if the ElementNode's {option} and {param} are OK, false if they're not
*/
public function hasValidInputs(ElementNode $el)
public function hasValidInputs(ElementNode $el): bool
{
if ($this->usesOption() && $this->optionValidator) {
$att = $el->getAttribute();
Expand Down Expand Up @@ -117,7 +122,7 @@ public function hasValidInputs(ElementNode $el)
*
* @return string the parsed html of this element (INCLUDING ITS CHILDREN)
*/
public function asHtml(ElementNode $el)
public function asHtml(ElementNode $el): string
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
Expand All @@ -144,7 +149,7 @@ public function asHtml(ElementNode $el)
return $html;
}

protected function getContent(ElementNode $el)
protected function getContent(ElementNode $el): string
{
if ($this->parseContent()) {
$content = "";
Expand All @@ -168,7 +173,7 @@ protected function getContent(ElementNode $el)
*
* @return string the text representation of $el
*/
public function asText(ElementNode $el)
public function asText(ElementNode $el): string
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
Expand All @@ -186,7 +191,7 @@ public function asText(ElementNode $el)
*
* @return string this definition's associated tag name
*/
public function getTagName()
public function getTagName(): string
{
return $this->tagName;
}
Expand All @@ -198,7 +203,7 @@ public function getTagName()
*
* @return string the replacement text of this CodeDefinition
*/
public function getReplacementText()
public function getReplacementText(): string
{
return $this->replacementText;
}
Expand All @@ -208,7 +213,7 @@ public function getReplacementText()
*
* @return boolean true if this CodeDefinition uses the option, false otherwise
*/
public function usesOption()
public function usesOption(): bool
{
return $this->useOption;
}
Expand All @@ -219,7 +224,7 @@ public function usesOption()
*
* @return boolean true if this CodeDefinition parses elements contained within itself
*/
public function parseContent()
public function parseContent(): bool
{
return $this->parseContent;
}
Expand All @@ -232,7 +237,7 @@ public function parseContent()
*
* @return integer
*/
public function getNestLimit()
public function getNestLimit(): int
{
return $this->nestLimit;
}
Expand All @@ -244,7 +249,7 @@ public function getNestLimit()
*
* @param string $tagName the new tag name of this definition
*/
public function setTagName($tagName)
public function setTagName(string $tagName): void
{
$this->tagName = strtolower($tagName);
}
Expand All @@ -256,7 +261,7 @@ public function setTagName($tagName)
*
* @param string $txt the new replacement text
*/
public function setReplacementText($txt)
public function setReplacementText(string $txt): void
{
$this->replacementText = $txt;
}
Expand All @@ -268,7 +273,7 @@ public function setReplacementText($txt)
*
* @param boolean $bool
*/
public function setUseOption($bool)
public function setUseOption(bool $bool): void
{
$this->useOption = $bool;
}
Expand All @@ -280,7 +285,7 @@ public function setUseOption($bool)
*
* @param boolean $bool
*/
public function setParseContent($bool)
public function setParseContent(bool $bool): void
{
$this->parseContent = $bool;
}
Expand All @@ -292,7 +297,7 @@ public function setParseContent($bool)
*
* @return void
*/
public function incrementCounter()
public function incrementCounter(): void
{
$this->elCounter++;
}
Expand All @@ -304,7 +309,7 @@ public function incrementCounter()
*
* @return void
*/
public function decrementCounter()
public function decrementCounter(): void
{
$this->elCounter--;
}
Expand All @@ -314,7 +319,7 @@ public function decrementCounter()
*
* @deprecated
*/
public function resetCounter()
public function resetCounter(): void
{
$this->elCounter = 0;
}
Expand All @@ -326,7 +331,7 @@ public function resetCounter()
*
* @return int
*/
public function getCounter()
public function getCounter(): int
{
return $this->elCounter;
}
Expand Down
66 changes: 36 additions & 30 deletions JBBCode/CodeDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ class CodeDefinitionBuilder
{

/** @var string */
protected $tagName;
protected string $tagName;

/** @var boolean */
protected $useOption = false;
protected bool $useOption = false;

/** @var string */
protected $replacementText;
protected string $replacementText;

/** @var boolean */
protected $parseContent = true;
protected bool $parseContent = true;

/** @var integer */
protected $nestLimit = -1;
protected int $nestLimit = -1;

/** @var array[string]InputValidator The input validators to run options through */
protected $optionValidator = array();
protected array $optionValidator = [];

/** @var InputValidator */
protected $bodyValidator = null;
protected ?InputValidator $bodyValidator = null;

/**
* Construct a CodeDefinitionBuilder.
*
* @param string $tagName the tag name of the definition to build
* @param string $replacementText the replacement text of the definition to build
*/
public function __construct($tagName, $replacementText)
public function __construct(string $tagName, string $replacementText)
{
$this->tagName = $tagName;
$this->replacementText = $replacementText;
Expand All @@ -46,7 +52,7 @@ public function __construct($tagName, $replacementText)
* @param string $tagName the tag name for the new CodeDefinition
* @return self
*/
public function setTagName($tagName)
public function setTagName(string $tagName): self
{
$this->tagName = $tagName;
return $this;
Expand All @@ -59,7 +65,7 @@ public function setTagName($tagName)
* @param string $replacementText the replacement text for the new CodeDefinition
* @return self
*/
public function setReplacementText($replacementText)
public function setReplacementText(string $replacementText): self
{
$this->replacementText = $replacementText;
return $this;
Expand All @@ -72,7 +78,7 @@ public function setReplacementText($replacementText)
* @param boolean $option true iff the definition includes an option
* @return self
*/
public function setUseOption($option)
public function setUseOption(bool $option): self
{
$this->useOption = $option;
return $this;
Expand All @@ -85,7 +91,7 @@ public function setUseOption($option)
* @param boolean $parseContent true iff the content should be parsed
* @return self
*/
public function setParseContent($parseContent)
public function setParseContent(bool $parseContent): self
{
$this->parseContent = $parseContent;
return $this;
Expand All @@ -98,11 +104,10 @@ public function setParseContent($parseContent)
* @throws \InvalidArgumentException if the nest limit is invalid
* @return self
*/
public function setNestLimit($limit)
public function setNestLimit(int $limit): self
{
if (!is_int($limit) || ($limit <= 0 && -1 != $limit)) {
throw new \InvalidArgumentException("A nest limit must be a positive integer " .
"or -1.");
if ($limit <= 0 && -1 != $limit) {
throw new \InvalidArgumentException("A nest limit must be a positive integer or -1.");
}
$this->nestLimit = $limit;
return $this;
Expand All @@ -114,7 +119,7 @@ public function setNestLimit($limit)
* @param InputValidator $validator the InputValidator instance to use
* @return self
*/
public function setOptionValidator(\JBBCode\InputValidator $validator, $option=null)
public function setOptionValidator(\JBBCode\InputValidator $validator, ?string $option = null): self
{
if (empty($option)) {
$option = $this->tagName;
Expand All @@ -129,7 +134,7 @@ public function setOptionValidator(\JBBCode\InputValidator $validator, $option=n
* @param InputValidator $validator the InputValidator instance to use
* @return self
*/
public function setBodyValidator(\JBBCode\InputValidator $validator)
public function setBodyValidator(\JBBCode\InputValidator $validator): self
{
$this->bodyValidator = $validator;
return $this;
Expand All @@ -139,17 +144,17 @@ public function setBodyValidator(\JBBCode\InputValidator $validator)
* Removes the attached option validator if one is attached.
* @return self
*/
public function removeOptionValidator()
public function removeOptionValidator(): self
{
$this->optionValidator = array();
$this->optionValidator = [];
return $this;
}

/**
* Removes the attached body validator if one is attached.
* @return self
*/
public function removeBodyValidator()
public function removeBodyValidator(): self
{
$this->bodyValidator = null;
return $this;
Expand All @@ -160,15 +165,16 @@ public function removeBodyValidator()
*
* @return CodeDefinition a new CodeDefinition instance
*/
public function build()
public function build(): CodeDefinition
{
$definition = CodeDefinition::construct($this->tagName,
$this->replacementText,
$this->useOption,
$this->parseContent,
$this->nestLimit,
$this->optionValidator,
$this->bodyValidator);
return $definition;
return CodeDefinition::construct(
$this->tagName,
$this->replacementText,
$this->useOption,
$this->parseContent,
$this->nestLimit,
$this->optionValidator,
$this->bodyValidator
);
}
}
2 changes: 1 addition & 1 deletion JBBCode/CodeDefinitionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface CodeDefinitionSet
* Retrieves the CodeDefinitions within this set as an array.
* @return CodeDefinition[]
*/
public function getCodeDefinitions();
public function getCodeDefinitions(): array;
}
Loading