Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.
Closed
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
47 changes: 47 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: PHP Code Quality
on:
pull_request:
branches:
- trunk
push:
branches:
- trunk

jobs:
quality:
name: Code Quality PHP (${{matrix.php_versions}})
runs-on: ubuntu-latest
strategy:
matrix:
php_versions: ['7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP ${{ matrix.php_versions}}
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{matrix.php_versions}}
tools: composer, cs2pr, parallel-lint, phpcs, phpstan, psalm

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v3
name: Cache Composer Dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
uses: ramsey/composer-install@v1

- name: Linting
run: |
parallel-lint --no-colors --no-progress --checkstyle ./Common.php | cs2pr
- name: Run Static Analysis (PHPStan)
run: phpstan analyse
70 changes: 34 additions & 36 deletions Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,45 @@
* @version Release: @package_version@
* @abstract
*/
class HTML_Common
abstract class HTML_Common
{
/**
* Associative array of attributes
* @var array
* @access private
*/
var $_attributes = array();
protected $_attributes = [];

/**
* Tab offset of the tag
* @var int
* @access private
*/
var $_tabOffset = 0;
protected $_tabOffset = 0;

/**
* Tab string
* @var string
* @since 1.7
* @access private
*/
var $_tab = "\11";
protected $_tab = "\11";

/**
* Contains the line end string
* @var string
* @since 1.7
* @access private
*/
var $_lineEnd = "\12";
protected $_lineEnd = "\12";

/**
* HTML comment on the object
* @var string
* @since 1.5
* @access private
*/
var $_comment = '';
protected $_comment = '';

/**
* Class constructor
Expand All @@ -77,7 +77,7 @@ class HTML_Common
* @param int $tabOffset Indent offset in tabs
* @access public
*/
function HTML_Common($attributes = null, $tabOffset = 0)
public function __construct($attributes = null, int $tabOffset = 0)
{
$this->setAttributes($attributes);
$this->setTabOffset($tabOffset);
Expand All @@ -88,7 +88,7 @@ function HTML_Common($attributes = null, $tabOffset = 0)
* @access public
* @returns double
*/
function apiVersion()
public function apiVersion(): float
{
return 1.7;
} // end func apiVersion
Expand All @@ -100,7 +100,7 @@ function apiVersion()
* @access private
* @return string
*/
function _getLineEnd()
protected function _getLineEnd()
{
return $this->_lineEnd;
} // end func getLineEnd
Expand All @@ -112,7 +112,7 @@ function _getLineEnd()
* @access private
* @return string
*/
function _getTab()
protected function _getTab()
{
return $this->_tab;
} // end func _getTab
Expand All @@ -123,7 +123,7 @@ function _getTab()
* @return string
* @access private
*/
function _getTabs()
protected function _getTabs()
{
return str_repeat($this->_getTab(), $this->_tabOffset);
} // end func _getTabs
Expand All @@ -134,12 +134,12 @@ function _getTabs()
* @return string
* @access private
*/
function _getAttrString($attributes)
protected function _getAttrString(array $attributes)
{
$strAttr = '';

if (is_array($attributes)) {
$charset = HTML_Common::charset();
$charset = self::charset();
foreach ($attributes as $key => $value) {
$strAttr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, $charset) . '"';
}
Expand All @@ -153,7 +153,7 @@ function _getAttrString($attributes)
* @access private
* @return array
*/
function _parseAttributes($attributes)
protected function _parseAttributes($attributes)
{
if (is_array($attributes)) {
$ret = array();
Expand All @@ -167,7 +167,7 @@ function _parseAttributes($attributes)
}
return $ret;

} elseif (is_string($attributes)) {
} else if (is_string($attributes)) {
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
if (preg_match_all($preg, $attributes, $regs)) {
Expand All @@ -188,6 +188,7 @@ function _parseAttributes($attributes)
return $arrAttr;
}
}
return [];
} // end func _parseAttributes

/**
Expand All @@ -199,7 +200,7 @@ function _parseAttributes($attributes)
* @access private
* @return bool
*/
function _getAttrKey($attr, $attributes)
protected function _getAttrKey(string $attr, array $attributes)
{
if (isset($attributes[strtolower($attr)])) {
return true;
Expand All @@ -214,7 +215,7 @@ function _getAttrKey($attr, $attributes)
* @param array $attr2 New attributes array
* @access private
*/
function _updateAttrArray(&$attr1, $attr2)
protected function _updateAttrArray(array &$attr1, array $attr2)
{
if (!is_array($attr2)) {
return false;
Expand All @@ -233,7 +234,7 @@ function _updateAttrArray(&$attr1, $attr2)
* @access private
* @return void
*/
function _removeAttr($attr, &$attributes)
protected function _removeAttr(string $attr, array &$attributes)
{
$attr = strtolower($attr);
if (isset($attributes[$attr])) {
Expand All @@ -249,7 +250,7 @@ function _removeAttr($attr, &$attributes)
* @access public
* @return string|null returns null if an attribute does not exist
*/
function getAttribute($attr)
public function getAttribute(string $attr)
{
$attr = strtolower($attr);
if (isset($this->_attributes[$attr])) {
Expand All @@ -265,7 +266,7 @@ function getAttribute($attr)
* @param string Attribute value (will be set to $name if omitted)
* @access public
*/
function setAttribute($name, $value = null)
public function setAttribute(string $name, ?string $value = null)
{
$name = strtolower($name);
if (is_null($value)) {
Expand All @@ -279,7 +280,7 @@ function setAttribute($name, $value = null)
* @param mixed $attributes Either a typical HTML attribute string or an associative array
* @access public
*/
function setAttributes($attributes)
public function setAttributes($attributes)
{
$this->_attributes = $this->_parseAttributes($attributes);
} // end func setAttributes
Expand All @@ -292,7 +293,7 @@ function setAttributes($attributes)
* @access public
* @return mixed attributes
*/
function getAttributes($asString = false)
public function getAttributes(bool $asString = false)
{
if ($asString) {
return $this->_getAttrString($this->_attributes);
Expand All @@ -306,7 +307,7 @@ function getAttributes($asString = false)
* @param mixed $attributes Either a typical HTML attribute string or an associative array
* @access public
*/
function updateAttributes($attributes)
public function updateAttributes($attributes)
{
$this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes));
} // end func updateAttributes
Expand All @@ -319,7 +320,7 @@ function updateAttributes($attributes)
* @access public
* @return void
*/
function removeAttribute($attr)
public function removeAttribute($attr)
{
$this->_removeAttr($attr, $this->_attributes);
} //end func removeAttribute
Expand All @@ -332,7 +333,7 @@ function removeAttribute($attr)
* @access public
* @return void
*/
function setLineEnd($style)
public function setLineEnd(string $style)
{
switch ($style) {
case 'win':
Expand All @@ -355,7 +356,7 @@ function setLineEnd($style)
* @param int $offset
* @access public
*/
function setTabOffset($offset)
public function setTabOffset(int $offset)
{
$this->_tabOffset = $offset;
} // end func setTabOffset
Expand All @@ -367,7 +368,7 @@ function setTabOffset($offset)
* @access public
* @return int
*/
function getTabOffset()
public function getTabOffset()
{
return $this->_tabOffset;
} //end func getTabOffset
Expand All @@ -380,7 +381,7 @@ function getTabOffset()
* @access public
* @return void
*/
function setTab($string)
public function setTab(string $string)
{
$this->_tab = $string;
} // end func setTab
Expand All @@ -393,7 +394,7 @@ function setTab($string)
* @access public
* @return void
*/
function setComment($comment)
public function setComment(string $comment)
{
$this->_comment = $comment;
} // end func setHtmlComment
Expand All @@ -405,7 +406,7 @@ function setComment($comment)
* @access public
* @return string
*/
function getComment()
public function getComment()
{
return $this->_comment;
} //end func getComment
Expand All @@ -417,17 +418,14 @@ function getComment()
* @return string
* @abstract
*/
function toHtml()
{
return '';
} // end func toHtml
abstract public function toHtml(): string;

/**
* Displays the HTML to the screen
*
* @access public
*/
function display()
public function display()
{
print $this->toHtml();
} // end func display
Expand All @@ -452,7 +450,7 @@ function display()
* @access public
* @static
*/
function charset($newCharset = null)
public static function charset(?string $newCharset = null)
{
static $charset = 'ISO-8859-1';

Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
},
"type": "library",
"require": {
"php": ">=7.4",
"pear/pear_exception": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
"phpunit/phpunit": "*",
"phpstan/phpstan": "^1.7"
}
}
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 0
paths:
- ./Common.php