Skip to content

Commit

Permalink
Raise psalm error level to 2 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
dood- committed Jul 21, 2022
1 parent d912e9f commit 3c1cc9e
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 31 deletions.
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -24,7 +24,7 @@
"oomphinc/composer-installers-extender": "^2.0.0",
"yiisoft/arrays": "^1.0|^2.0",
"yiisoft/assets": "^2.0",
"yiisoft/html": "^2.0",
"yiisoft/html": "^2.5",
"yiisoft/json": "^1.0",
"yiisoft/widget": "^1.0"
},
Expand Down Expand Up @@ -61,7 +61,9 @@
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"composer/installers": true,
"oomphinc/composer-installers-extender": true
}
},
"repositories": [
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
7 changes: 5 additions & 2 deletions src/Accordion.php
Expand Up @@ -351,7 +351,6 @@ private function renderItems(): string
/**
* Renders a single collapsible item group.
*
* @param string $label a label of the item group {@see items}
* @param array $item a single item from {@see items}
* @param int $index the item index as each item group content must have an id
*
Expand Down Expand Up @@ -496,14 +495,18 @@ private function renderBody(array $item): string
throw new RuntimeException('The "content" option should be a string, array or object.');
}

$items .= (string) $value;
$items .= $value;
}

return Html::div($items, ['class' => 'accordion-body'])
->encode($this->encodeTags)
->render();
}

/**
* @param mixed $value
* @return bool
*/
private function isStringableObject($value): bool
{
return is_object($value) && method_exists($value, '__toString');
Expand Down
7 changes: 6 additions & 1 deletion src/Alert.php
Expand Up @@ -30,10 +30,12 @@ final class Alert extends Widget
private string $body = '';
private ?string $header = null;
private array $headerOptions = [];
/** @psalm-var non-empty-string */
private string $headerTag = 'h4';
private array $closeButton = [
'class' => 'btn-close',
];
/** @psalm-var non-empty-string */
private string $closeButtonTag = 'button';
private bool $closeButtonInside = true;
private bool $encode = false;
Expand Down Expand Up @@ -116,6 +118,7 @@ public function headerOptions(array $options): self
* Set tag name for header
*
* @param string $tag
* @psalm-param non-empty-string $tag
*
* @return self
*/
Expand Down Expand Up @@ -158,6 +161,7 @@ public function closeButton(array $value): self
/**
* Disable close button.
*
* @param bool $value
* @return self
*/
public function withoutCloseButton(bool $value = false): self
Expand All @@ -172,6 +176,7 @@ public function withoutCloseButton(bool $value = false): self
* Set close button tag
*
* @param string $tag
* @psalm-param non-empty-string $tag
*
* @return self
*/
Expand Down Expand Up @@ -233,7 +238,7 @@ public function fade(bool $fade = true): self
/**
* Set type of alert, 'alert-success', 'alert-danger', 'custom-alert' etc
*
* @param string $type
* @param string ...$classNames
*
* @return self
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Breadcrumbs.php
Expand Up @@ -26,6 +26,7 @@
*/
final class Breadcrumbs extends Widget
{
/** @psalm-var non-empty-string */
private string $tag = 'ol';
private bool $encodeLabels = true;
private bool $encodeTags = false;
Expand Down Expand Up @@ -201,6 +202,7 @@ public function options(array $value): self
* The name of the breadcrumb container tag.
*
* @param string $value
* @psalm-param non-empty-string $value
*
* @return self
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Button.php
Expand Up @@ -19,6 +19,7 @@
*/
final class Button extends Widget
{
/** @psalm-var non-empty-string */
private string $tagName = 'button';
private string $label = 'Button';
private bool $encodeLabels = true;
Expand Down Expand Up @@ -92,6 +93,7 @@ public function options(array $value): self
* The tag to use to render the button.
*
* @param string $value
* @psalm-param non-empty-string $value
*
* @return self
*/
Expand Down
10 changes: 6 additions & 4 deletions src/ButtonDropdown.php
Expand Up @@ -53,9 +53,11 @@ final class ButtonDropdown extends Widget
private array $dropdown = [];
private string $direction = self::DIRECTION_DOWN;
private bool $split = false;
/** @psalm-var non-empty-string */
private string $tagName = 'button';
private bool $encodeLabels = true;
private bool $encodeTags = false;
/** @psalm-var class-string */
private string $dropdownClass = Dropdown::class;
private bool $renderContainer = true;

Expand Down Expand Up @@ -153,6 +155,7 @@ public function dropdown(array $value): self
* Name of a class to use for rendering dropdowns withing this widget. Defaults to {@see Dropdown}.
*
* @param string $value
* @psalm-param class-string $value
*
* @return self
*/
Expand Down Expand Up @@ -240,6 +243,7 @@ public function split(): self
* The tag to use to render the button.
*
* @param string $value
* @psalm-param non-empty-string $value
*
* @return self
*/
Expand Down Expand Up @@ -268,9 +272,9 @@ private function renderButton(): string
$label = Html::encode($label);
}

if ($this->split) {
$buttonOptions = $this->buttonOptions;
$buttonOptions = $this->buttonOptions;

if ($this->split) {
$this->buttonOptions['data-bs-toggle'] = 'dropdown';
$this->buttonOptions['aria-haspopup'] = 'true';
$this->buttonOptions['aria-expanded'] = 'false';
Expand All @@ -285,8 +289,6 @@ private function renderButton(): string
->withoutEncodeLabels()
->render();
} else {
$buttonOptions = $this->buttonOptions;

Html::addCssClass($buttonOptions, ['toggle' => 'dropdown-toggle']);

$buttonOptions['data-bs-toggle'] = 'dropdown';
Expand Down
6 changes: 3 additions & 3 deletions src/Dropdown.php
Expand Up @@ -194,7 +194,7 @@ private function renderItems(array $items, array $options = []): string

return Html::ul()
->items(...$lines)
->attributes($options)
->addAttributes($options)
->render();
}

Expand Down Expand Up @@ -245,7 +245,7 @@ private function renderItem(array $item): Li

return Li::tag()
->content($content)
->attributes($itemOptions)
->addAttributes($itemOptions)
->encode(false);
}

Expand Down Expand Up @@ -282,7 +282,7 @@ private function renderItem(array $item): Li

return Li::tag()
->content($toggle . $dropdown->render())
->attributes($itemOptions)
->addAttributes($itemOptions)
->encode(false);
}
}
20 changes: 8 additions & 12 deletions src/Modal.php
Expand Up @@ -235,7 +235,7 @@ public function bodyOptions(array $value): self
* The rest of the options will be rendered as the HTML attributes of the button tag. Please refer to the
* [Modal plugin help](http://getbootstrap.com/javascript/#modals) for the supported HTML attributes.
*
* @param array $value
* @param array|null $value
*
* @return self
*/
Expand All @@ -260,7 +260,7 @@ public function withoutCloseButton(): self
/**
* The footer content in the modal window.
*
* @param string $value
* @param string|null $value
*
* @return self
*/
Expand Down Expand Up @@ -325,7 +325,7 @@ public function options(array $value): self
/**
* The title content in the modal window.
*
* @param string $value
* @param string|null $value
*
* @return self
*/
Expand Down Expand Up @@ -368,7 +368,7 @@ public function titleOptions(array $value): self
* The rest of the options will be rendered as the HTML attributes of the button tag. Please refer to the
* [Modal plugin help](http://getbootstrap.com/javascript/#modals) for the supported HTML attributes.
*
* @param array $value
* @param array|null $value
*
* @return self
*/
Expand All @@ -393,7 +393,7 @@ public function withoutToggleButton(): self
/**
* The modal size. Can be {@see SIZE_LARGE} or {@see SIZE_SMALL}, or null for default.
*
* @param string $value
* @param string|null $value
*
* @return self
*
Expand Down Expand Up @@ -625,7 +625,7 @@ public function renderToggleButton(array $options = []): ?string
[
'data-bs-toggle' => 'modal',
],
$this->toggleButton,
$this->toggleButton ?? [],
$options
);

Expand All @@ -640,12 +640,8 @@ public function renderToggleButton(array $options = []): ?string
if (!isset($options['data-bs-target'])) {
$target = (string) $this->getId();

if ($tag === 'a') {
if (!isset($options['href'])) {
$options['href'] = '#' . $target;
} else {
$options['data-bs-target'] = '#' . $target;
}
if ($tag === 'a' && !isset($options['href'])) {
$options['href'] = '#' . $target;
} else {
$options['data-bs-target'] = '#' . $target;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Nav.php
Expand Up @@ -106,6 +106,7 @@ final class Nav extends Widget
private bool $activateParents = false;
private ?string $activeClass = null;
private string $currentPath = '';
/** @psalm-var class-string */
private string $dropdownClass = Dropdown::class;
private array $options = [];
private array $itemOptions = [];
Expand Down Expand Up @@ -232,6 +233,7 @@ public function currentPath(string $value): self
* Name of a class to use for rendering dropdowns within this widget. Defaults to {@see Dropdown}.
*
* @param string $value
* @psalm-param class-string $value
*
* @return self
*/
Expand Down
5 changes: 3 additions & 2 deletions src/NavBar.php
Expand Up @@ -180,7 +180,8 @@ public function begin(): string
$htmlStart .= $this->renderBrand();

if ($offcanvas) {
$htmlStart .= $this->renderToggleButton($this->offcanvas->getId());
$offcanvasId = $this->offcanvas ? $this->offcanvas->getId() : null;
$htmlStart .= $this->renderToggleButton($offcanvasId);
$htmlStart .= $offcanvas;
} elseif ($this->expandSize) {
$collapseOptions = $this->collapseOptions;
Expand Down Expand Up @@ -499,7 +500,7 @@ private function renderBrand(): string

if (!empty($this->brandImage)) {
$encode = false;
$content = Html::img($this->brandImage)->attributes($this->brandImageAttributes);
$content = Html::img($this->brandImage)->addAttributes($this->brandImageAttributes);
}

if (!empty($this->brandText)) {
Expand Down
9 changes: 5 additions & 4 deletions src/Tabs.php
Expand Up @@ -54,6 +54,7 @@
* ],
* ]);
* ```
* @psalm-suppress MissingConstructor
*/
final class Tabs extends Widget
{
Expand Down Expand Up @@ -212,7 +213,7 @@ public function itemOptions(array $value): self
* {@see Html::renderTagAttributes()} for details on how attributes are being rendered.
* {@see Nav::linkOptions()}
*
* @param array $options
* @param array $value
*
* @return self
*/
Expand All @@ -225,7 +226,7 @@ public function linkOptions(array $value): self
* List of HTML attributes for the item container tags. This will be overwritten by the "options" set in individual
* {@see items}. The following special options are recognized.
*
* @param array $value
* @param array $options
*
* @return self
*
Expand Down Expand Up @@ -332,7 +333,7 @@ private function renderPanes(array $panes): string
/**
* Prepare Nav::widget for using
*
* @param array $options
* @param array $definitions
* @param array $items
*
* @return Nav
Expand Down Expand Up @@ -372,7 +373,7 @@ private function prepareNavDefinitions(): array
* Renders tab items as specified on {@see items}.
*
* @param array $items
* @param string $navId
* @param string|null $navId
* @param string $prefix
*
* @throws JsonException|RuntimeException
Expand Down

0 comments on commit 3c1cc9e

Please sign in to comment.