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
41 changes: 38 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand All @@ -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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
6 changes: 3 additions & 3 deletions src/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __invoke()
*
* @param string $encoding The encoding to use.
*
* @return null
* @return void
*
*/
public function setEncoding($encoding)
Expand All @@ -141,7 +141,7 @@ public function setEncoding($encoding)
*
* @param int $flags The `htmlspecialchars()` flags.
*
* @return null
* @return void
*
*/
public function setFlags($flags)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Escaper/AbstractEscaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ abstract public function __invoke($raw);
*
* @param string $encoding The encoding.
*
* @return null
* @return void
*
*/
public function setEncoding($encoding)
Expand Down
2 changes: 1 addition & 1 deletion src/Escaper/HtmlEscaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __invoke($raw)
*
* @param int $flags The flags for `htmlspecialchars()`.
*
* @return null
* @return void
*
*/
public function setFlags($flags)
Expand Down
4 changes: 0 additions & 4 deletions src/EscaperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(Escaper $escaper)
*
* @param string $indent The indent string.
*
* @return null
* @return void
*
*/
public function setIndent($indent)
Expand Down
13 changes: 6 additions & 7 deletions src/Helper/AbstractList.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractList extends AbstractHelper
*
* Attributes for the ul tag.
*
* @var array
* @var array<string, scalar|null>
*
*/
protected $attr = array();
Expand All @@ -30,7 +30,7 @@ abstract class AbstractList extends AbstractHelper
*
* The stack of HTML elements.
*
* @var array
* @var array<int, array{string, string}>
*
*/
protected $stack = array();
Expand All @@ -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<string, scalar|null>|null $attr HTML element attributes
*
* @return self
*
*/
public function __invoke(array $attr = null)
public function __invoke($attr = null)
{
if ($attr !== null) {
$this->attr = $attr;
Expand Down Expand Up @@ -187,7 +186,7 @@ public function rawItems(array $items)
*
* @param string $item The item HTML.
*
* @return null
* @return void
*
*/
protected function buildItem($item)
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/AbstractSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __toString()
*
* @param string $element The element itself.
*
* @return null
* @return void
*
*/
protected function addElement($pos, $element)
Expand Down
7 changes: 3 additions & 4 deletions src/Helper/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, scalar|null>, value?: mixed, options?: array<string, string>}|null $spec HTML input element specification
*
* @return self|string
*/
public function __invoke(array $spec = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit confused, can we do array $spec = [] to fix this ? I didnot noticed where the casting was done . (array) $attr mentioned. May be I missed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment, @harikt!

I kept the $spec = null as-is to avoid any behavior changes in legacy code — this method has been around since the PHP 5.x days. Instead of relying on a type hint, I tried to compensate with a more precise PHPDoc type so modern static analysis tools can still verify correctness.

The idea is to preserve runtime compatibility while improving type clarity at the tooling level.

Happy to add an explicit cast if you think it's safer. Let me know what you think!

public function __invoke($spec = null)
{
if ($spec === null) {
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/Input/AbstractChecked.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function htmlChecked()
*
* Extracts and retains the "label" pseudo-attribute.
*
* @return null
* @return void
*
*/
protected function setLabel()
Expand All @@ -86,7 +86,7 @@ protected function setLabel()
*
* Sets the "checked" attribute appropriately.
*
* @return null
* @return void
*
*/
protected function setChecked()
Expand Down
14 changes: 7 additions & 7 deletions src/Helper/Input/AbstractInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class AbstractInput extends AbstractHelper
* The input type.
*
* @var string
* @readonly
*
*/
protected $type;
Expand All @@ -51,7 +52,7 @@ abstract class AbstractInput extends AbstractHelper
*
* HTML attributes for the input.
*
* @var array
* @var array<string, scalar|null>
*
*/
protected $attribs = array();
Expand All @@ -60,21 +61,20 @@ abstract class AbstractInput extends AbstractHelper
*
* Value options for the input.
*
* @var array
* @var array<string, string>
*
*/
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<string, scalar|null>, value?: mixed, options?: array<string, string>}|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);
Expand Down
3 changes: 2 additions & 1 deletion src/Helper/Input/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -291,6 +291,7 @@ protected function buildOptionPlaceholder()
array('disabled' => true),
));
}
return '';
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
Loading