[go: nahoru, domu]

Skip to content

Commit

Permalink
fix: add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Jan 6, 2022
1 parent 6945708 commit a2b77aa
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 393 deletions.
42 changes: 7 additions & 35 deletions src/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,23 @@
class Attributes extends \ArrayObject
{
/**
* @var array
* @var array<string, string>
*/
protected $attributes = ['class' => 'bb'];

/**
* @param string $name
*
* @return string
*/
public function getAttributeValue($name)
public function getAttributeValue(string $name): string
{
return $this->attributes[$name];
}

/**
* @param string $name
* @param string $value
*
* @return Attributes
*/
public function set($name, $value)
public function set(string $name, string $value): self
{
$this->attributes[$name] = $value;

return $this;
}

/**
* @param string $name
* @param string $value
*
* @return Attributes
*/
public function add($name, $value)
public function add(string $name, string $value): self
{
if (isset($this->attributes[$name])) {
$this->attributes[$name] .= ' '.$value;
Expand All @@ -72,30 +55,19 @@ public function add($name, $value)
return $this;
}

/**
* @param string $name
*
* @return Attributes
*/
public function remove($name)
public function remove(string $name): self
{
unset($this->attributes[$name]);

return $this;
}

/**
* @return \ArrayIterator
*/
public function getIterator()
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->attributes);
}

/**
* @return string
*/
public function __toString()
public function __toString(): string
{
$str = '';
foreach ($this->getIterator() as $name => $value) {
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$this->setAutoLinks(false);

Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Abbr.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<abbr '.$this->getAttributes().'>'.$this->getBody().'</abbr>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Acronym.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<acronym '.$this->getAttributes().'>'.$this->getBody().'</acronym>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ class Address extends Tag
{
/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<address '.$this->getAttributes().'>'.$this->getBody().'</address>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Align.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<div '.$this->getAttributes().'>'.$this->getBody().'</div>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Altfont.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<font '.$this->getAttributes().'>'.$this->getBody().'</font>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Bbcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ protected function build()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$this->build();

Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Bdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<bdo '.$this->getAttributes().'>'.$this->getBody().'</bdo>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Br.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ class Br extends Tag

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<br '.$this->getAttributes().' />';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Caption.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class Caption extends Tag

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<caption '.$this->getAttributes().'>'.$this->getBody().'</caption>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ protected function getFooter()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$this->setLanguage();
$this->setSource();
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<font '.$this->getAttributes().'>'.$this->getBody().'</font>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<font '.$this->getAttributes().'>'.$this->getBody().'</font>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Hr.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ class Hr extends Tag

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<hr '.$this->getAttributes().' />';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Img.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<img '.$this->getAttributes().' />';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Li.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<li '.$this->getAttributes().'>'.$this->getBody().'</li>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Nobb.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class Nobb extends Tag

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return \htmlspecialchars($this->getTreeText(), \ENT_NOQUOTES);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Ol.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<ol '.$this->getAttributes().'>'.$this->getBody().'</ol>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/P.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class P extends Align

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<'.$this->getTagName().' '.$this->getAttributes().'>'.$this->getBody().'</'.$this->getTagName().'>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<blockquote '.$this->getAttributes().'>'.$this->getAuthor().$this->getBody().'</blockquote>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class Simple extends Tag

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
switch ($this->getTagName()) {
case 'b':
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<font '.$this->getAttributes().'>'.$this->getBody().'</font>';
}
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Spoiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$attr = $this->getAttributes();
$id = $attr->getAttributeValue('id');
Expand Down
4 changes: 1 addition & 3 deletions src/Tag/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ protected function getAttributes()

/**
* Return html code.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return '<table '.$this->getAttributes().'>'.$this->getBody().'</table>';
}
Expand Down
Loading

0 comments on commit a2b77aa

Please sign in to comment.