diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1f67586..ce25af1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -26,9 +26,11 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' + - '8.4' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP ${{ matrix.php-version }} uses: shivammathur/setup-php@v2 @@ -43,7 +45,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} @@ -56,6 +58,39 @@ jobs: run: php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=coverage.xml - name: Upload coverage report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 with: fail_ci_if_error: false + + static-analysis: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP 8.4 + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + tools: composer:2.2 + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --no-interaction --prefer-dist + + - name: Install PHPStan + run: composer require --dev phpstan/phpstan --with-all-dependencies + + - name: Run PHPStan + run: composer phpstan diff --git a/composer.json b/composer.json index 16138d5..2693864 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,11 @@ "require-dev": { "yoast/phpunit-polyfills": "~1.0" }, + "scripts": { + "phpstan": "phpstan analyse --level=2 src/", + "test": "./vendor/bin/phpunit", + "test-coverage": "php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=coverage.xml" + }, "autoload-dev": { "psr-4": { "Aura\\Html\\": "tests/", diff --git a/src/Escaper.php b/src/Escaper.php index 845a83c..31c7ed1 100644 --- a/src/Escaper.php +++ b/src/Escaper.php @@ -124,7 +124,7 @@ public function __invoke() * * @param string $encoding The encoding to use. * - * @return null + * @return void * */ public function setEncoding($encoding) @@ -141,7 +141,7 @@ public function setEncoding($encoding) * * @param int $flags The `htmlspecialchars()` flags. * - * @return null + * @return void * */ public function setFlags($flags) @@ -212,7 +212,7 @@ public function js($raw) * * @param Escaper $escaper The Escaper to use as the singleton. * - * @return null + * @return void * */ public static function setStatic(Escaper $escaper) diff --git a/src/Escaper/AbstractEscaper.php b/src/Escaper/AbstractEscaper.php index ddc760a..4566cff 100644 --- a/src/Escaper/AbstractEscaper.php +++ b/src/Escaper/AbstractEscaper.php @@ -78,7 +78,7 @@ abstract public function __invoke($raw); * * @param string $encoding The encoding. * - * @return null + * @return void * */ public function setEncoding($encoding) diff --git a/src/Escaper/HtmlEscaper.php b/src/Escaper/HtmlEscaper.php index c05e98e..8a151c9 100644 --- a/src/Escaper/HtmlEscaper.php +++ b/src/Escaper/HtmlEscaper.php @@ -85,7 +85,7 @@ public function __invoke($raw) * * @param int $flags The flags for `htmlspecialchars()`. * - * @return null + * @return void * */ public function setFlags($flags) diff --git a/src/EscaperFactory.php b/src/EscaperFactory.php index 47cc7b9..fdad362 100644 --- a/src/EscaperFactory.php +++ b/src/EscaperFactory.php @@ -60,10 +60,6 @@ public function __construct($encoding = null, $flags = null) * * Creates a new Escaper object. * - * @param string $encoding The encoding for the escapers. - * - * @param int $flags The `htmlspecialchars()` flags for the escapers. - * * @return Escaper * */ diff --git a/src/Helper/AbstractHelper.php b/src/Helper/AbstractHelper.php index 82f9476..61f0f1a 100644 --- a/src/Helper/AbstractHelper.php +++ b/src/Helper/AbstractHelper.php @@ -66,7 +66,7 @@ public function __construct(Escaper $escaper) * * @param string $indent The indent string. * - * @return null + * @return void * */ public function setIndent($indent) diff --git a/src/Helper/AbstractList.php b/src/Helper/AbstractList.php index cadf680..3b569e8 100644 --- a/src/Helper/AbstractList.php +++ b/src/Helper/AbstractList.php @@ -21,7 +21,7 @@ abstract class AbstractList extends AbstractHelper * * Attributes for the ul tag. * - * @var array + * @var array * */ protected $attr = array(); @@ -30,7 +30,7 @@ abstract class AbstractList extends AbstractHelper * * The stack of HTML elements. * - * @var array + * @var array * */ protected $stack = array(); @@ -46,14 +46,13 @@ abstract class AbstractList extends AbstractHelper /** * - * Initializes and returns the UL object. + * Initializes and returns the list object. * - * @param array $attr Attributes for the UL tag. + * @param array|null $attr HTML element attributes * * @return self - * */ - public function __invoke(array $attr = null) + public function __invoke($attr = null) { if ($attr !== null) { $this->attr = $attr; @@ -187,7 +186,7 @@ public function rawItems(array $items) * * @param string $item The item HTML. * - * @return null + * @return void * */ protected function buildItem($item) diff --git a/src/Helper/AbstractSeries.php b/src/Helper/AbstractSeries.php index 360985f..23c27a7 100644 --- a/src/Helper/AbstractSeries.php +++ b/src/Helper/AbstractSeries.php @@ -73,7 +73,7 @@ public function __toString() * * @param string $element The element itself. * - * @return null + * @return void * */ protected function addElement($pos, $element) diff --git a/src/Helper/Input.php b/src/Helper/Input.php index bb659a7..5ff077e 100644 --- a/src/Helper/Input.php +++ b/src/Helper/Input.php @@ -23,12 +23,11 @@ class Input extends HelperLocator * * Given an input specification, returns the HTML for the input. * - * @param array $spec The element specification. - * - * @return mixed + * @param array{type?: string, name?: string, attribs?: array, value?: mixed, options?: array}|null $spec HTML input element specification * + * @return self|string */ - public function __invoke(array $spec = null) + public function __invoke($spec = null) { if ($spec === null) { return $this; diff --git a/src/Helper/Input/AbstractChecked.php b/src/Helper/Input/AbstractChecked.php index 7c933a0..517a155 100644 --- a/src/Helper/Input/AbstractChecked.php +++ b/src/Helper/Input/AbstractChecked.php @@ -68,7 +68,7 @@ protected function htmlChecked() * * Extracts and retains the "label" pseudo-attribute. * - * @return null + * @return void * */ protected function setLabel() @@ -86,7 +86,7 @@ protected function setLabel() * * Sets the "checked" attribute appropriately. * - * @return null + * @return void * */ protected function setChecked() diff --git a/src/Helper/Input/AbstractInput.php b/src/Helper/Input/AbstractInput.php index ce5cb8c..3beceaa 100644 --- a/src/Helper/Input/AbstractInput.php +++ b/src/Helper/Input/AbstractInput.php @@ -25,6 +25,7 @@ abstract class AbstractInput extends AbstractHelper * The input type. * * @var string + * @readonly * */ protected $type; @@ -51,7 +52,7 @@ abstract class AbstractInput extends AbstractHelper * * HTML attributes for the input. * - * @var array + * @var array * */ protected $attribs = array(); @@ -60,21 +61,20 @@ abstract class AbstractInput extends AbstractHelper * * Value options for the input. * - * @var array + * @var array * */ protected $options = array(); /** * - * Given a input spec, returns the HTML for the input. + * Returns the input helper with optional specification. * - * @param array $spec The input spec. - * - * @return string + * @param array{type?: string, name?: string, attribs?: array, value?: mixed, options?: array}|null $spec HTML input element specification * + * @return self */ - public function __invoke(array $spec = null) + public function __invoke($spec = null) { if ($spec !== null) { $this->prep($spec); diff --git a/src/Helper/Input/Select.php b/src/Helper/Input/Select.php index 7896ff5..c5d80ac 100644 --- a/src/Helper/Input/Select.php +++ b/src/Helper/Input/Select.php @@ -72,7 +72,7 @@ class Select extends AbstractInput * @return string|self * */ - public function __invoke(array $spec = null) + public function __invoke($spec = null) { if ($spec !== null) { $this->prep($spec); @@ -291,6 +291,7 @@ protected function buildOptionPlaceholder() array('disabled' => true), )); } + return ''; } /** diff --git a/src/Helper/Scripts.php b/src/Helper/Scripts.php index 2282049..d024e78 100644 --- a/src/Helper/Scripts.php +++ b/src/Helper/Scripts.php @@ -57,7 +57,7 @@ public function add($src, $pos = 100, array $attr = array()) * * @param string $src The source href for the script. * - * @param string $pos The script position in the stack. + * @param int $pos The script position in the stack. * * @param array $attr The additional attributes * @@ -122,7 +122,7 @@ public function addCondInternal($cond, $script, $pos = 100, array $attr = array( * @param array $attr The additional attributes * * - * @return null + * @return void * * @access public */ @@ -139,7 +139,7 @@ public function beginInternal($pos = 100, array $attr = array()) * @param int $pos position * @param array $attr The additional attributes * - * @return null + * @return void * * @access public */ diff --git a/src/Helper/Styles.php b/src/Helper/Styles.php index 510d91c..cdb4b88 100644 --- a/src/Helper/Styles.php +++ b/src/Helper/Styles.php @@ -18,9 +18,10 @@ class Styles extends AbstractSeries { /** - * Temporary storage or params passed to caputre functions + * Temporary storage for capture functions * - * @var mixed + * @var array + * @readonly * * @access private */ @@ -28,18 +29,17 @@ class Styles extends AbstractSeries /** * - * Adds a tag to the series. + * Adds a stylesheet link to the series. * - * @param string $href The source href for the stylesheet. + * @param string $href CSS file URL or path * - * @param array $attr Additional attributes for the tag. + * @param array|null $attr Additional HTML attributes * - * @param int $pos The stylesheet position in the series. + * @param int $pos Position in the output series * * @return self - * */ - public function add($href, array $attr = null, $pos = 100) + public function add($href, $attr = null, $pos = 100) { $attr = $this->fixAttr($href, $attr); $tag = $this->void('link', $attr); @@ -50,21 +50,19 @@ public function add($href, array $attr = null, $pos = 100) /** * - * Adds a conditional `` - * tag to the stack. + * Adds a conditional stylesheet link. * - * @param string $cond The conditional expression for the stylesheet. + * @param string $cond IE conditional expression * - * @param string $href The source href for the stylesheet. + * @param string $href CSS file URL or path * - * @param array $attr Additional attributes for the tag. + * @param array|null $attr Additional HTML attributes * - * @param string $pos The stylesheet position in the stack. + * @param int $pos Position in the output series * * @return self - * */ - public function addCond($cond, $href, array $attr = null, $pos = 100) + public function addCond($cond, $href, $attr = null, $pos = 100) { $attr = $this->fixAttr($href, $attr); $link = $this->void('link', $attr); @@ -85,7 +83,7 @@ public function addCond($cond, $href, array $attr = null, $pos = 100) * * @access protected */ - protected function style($css, array $attr = null) + protected function style($css, $attr = null) { $attr = $this->fixInternalAttr($attr); $attr = $this->escaper->attr($attr); @@ -103,7 +101,7 @@ protected function style($css, array $attr = null) * * @access public */ - public function addInternal($css, array $attr = null, $pos = 100) + public function addInternal($css, $attr = null, $pos = 100) { $style = $this->style($css, $attr); $this->addElement($pos, $style); @@ -121,12 +119,12 @@ public function addInternal($css, array $attr = null, $pos = 100) * * @param array $attr Additional attributes for the