for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Groundskeeper\Tokens;
use Groundskeeper\Configuration;
abstract class AbstractToken implements Token
{
/** @var int */
private $depth;
protected $isValid;
/** @var null|Token */
private $parent;
/** @var string */
private $type;
/**
* Constructor
*/
public function __construct($type, Token $parent = null)
if (!$this->isValidType($type)) {
throw new \InvalidArgumentException('Invalid type: ' . $type);
}
$this->isValid = false;
$isValid
integer
false
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
$this->setParent($parent);
$this->type = $type;
public function getDepth()
return $this->depth;
* Getter for 'isValid'.
public function getIsValid()
return $this->isValid;
* Getter for 'parent'.
public function getParent()
return $this->parent;
* Chainable setter for 'parent'.
public function setParent(Token $parent = null)
$this->depth = 0;
if ($parent instanceof Token) {
$this->depth = $parent->getDepth() + 1;
$this->parent = $parent;
return $this;
public function getType()
return $this->type;
public function validate(Configuration $configuration)
$this->isValid = $configuration->isAllowedType($this->type);
$configuration->isAllowedType($this->type)
boolean
protected function isValidType($type)
return $type === Token::CDATA
|| $type === Token::COMMENT
|| $type === Token::DOCTYPE
|| $type === Token::ELEMENT
|| $type === Token::TEXT;
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.