Skip to content

Commit

Permalink
Use php-forge/awesome-widget stable version. (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 23, 2024
1 parent f18fbaf commit 55a2398
Show file tree
Hide file tree
Showing 122 changed files with 856 additions and 325 deletions.
6 changes: 3 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ finder:
- vendor

enabled:
- alpha_ordered_traits
- array_indentation
- array_push
- combine_consecutive_issets
Expand All @@ -19,6 +20,7 @@ enabled:
- fully_qualified_strict_types
- function_to_constant
- hash_to_slash_comment
- integer_literal_case
- is_null
- logical_operators
- magic_constant_casing
Expand Down Expand Up @@ -55,7 +57,6 @@ enabled:
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
Expand All @@ -77,9 +78,8 @@ enabled:
- trailing_comma_in_multiline_array
- unalign_double_arrow
- unalign_equals
- empty_loop_body_braces
- integer_literal_case
- union_type_without_spaces

disabled:
- function_declaration
- psr12_braces
28 changes: 10 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"ext-dom": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"php-forge/awesome-widget": "^1.0@dev",
"php-forge/awesome-widget": "^0.1",
"voku/anti-xss": "^4.1"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.3",
"php-forge/support": "^1.0@dev",
"maglnet/composer-require-checker": "^4.7",
"php-forge/support": "^0.1",
"phpunit/phpunit": "^10.5",
"roave/infection-static-analysis-plugin": "^1.3",
"symplify/easy-coding-standard": "^11.5",
"vimeo/psalm": "^5.18"
"roave/infection-static-analysis-plugin": "^1.34",
"symplify/easy-coding-standard": "^12.1",
"vimeo/psalm": "^5.20"
},
"autoload": {
"psr-4": {
Expand All @@ -39,14 +39,14 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev"
"dev-main": "0.1-dev"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
},
"sort-packages": true
},
"scripts": {
"check-dependencies": "composer-require-checker",
Expand All @@ -57,13 +57,5 @@
],
"psalm": "psalm",
"test": "phpunit"
},
"repositories": [
{
"type": "vcs",
"name": "php-forge/awesome-widget",
"url": "https://github.com/php-forge/awesome-widget",
"branch": "main"
}
]
}
}
50 changes: 21 additions & 29 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,33 @@
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths(
return ECSConfig::configure()
->withConfiguredRule(
ClassDefinitionFixer::class,
[
'space_before_parenthesis' => true,
],
)
->withFileExtensions(['php'])
->withPaths(
[
__DIR__ . '/src',
__DIR__ . '/tests',
]
);

// this way you add a single rule
$ecsConfig->rules(
],
)
->withPreparedSets(
arrays: true,
cleanCode: true,
comments:true,
docblocks: true,
namespaces: true,
psr12: true
)
->withRules(
[
NoUnusedImportsFixer::class,
OrderedClassElementsFixer::class,
OrderedTraitsFixer::class,
NoUnusedImportsFixer::class,
]
);

// this way you can add sets - group of rules
$ecsConfig->sets(
[
// run and fix, one by one
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::PSR_12,
]
);

// this way configures a rule
$ecsConfig->ruleWithConfiguration(
ClassDefinitionFixer::class,
[
'space_before_parenthesis' => true,
],
);
};
25 changes: 15 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
</php>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Html">
<directory>./tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory>./vendor</directory>
</exclude>
</source>
</phpunit>
7 changes: 2 additions & 5 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
Expand Down
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataBsAutoClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait HasDataBsAutoClose
*/
public function dataBsAutoClose(string $value): static
{
return $this->dataAttributes([DataAttributes::BS_AUTO_CLOSE => $value]);
return $this->dataAttributes([
DataAttributes::BS_AUTO_CLOSE => $value,
]);
}
}
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataBsDismiss.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait HasDataBsDismiss
*/
public function dataBsDismiss(string $value): static
{
return $this->dataAttributes([DataAttributes::BS_DISMISS => $value]);
return $this->dataAttributes([
DataAttributes::BS_DISMISS => $value,
]);
}
}
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataBsTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ trait HasDataBsTarget
public function dataBsTarget(bool|string $value): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributes::BS_TARGET => $value]);
return $this->dataAttributes([
DataAttributes::BS_TARGET => $value,
]);
}

$new = clone $this;
Expand Down
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataBsToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait HasDataBsToggle
*/
public function dataBsToggle(string $value): static
{
return $this->dataAttributes([DataAttributes::BS_TOGGLE => $value]);
return $this->dataAttributes([
DataAttributes::BS_TOGGLE => $value,
]);
}
}
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataCollapseToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait HasDataCollapseToggle
*/
public function dataCollapseToggle(string $value): static
{
return $this->dataAttributes([DataAttributes::COLLAPSE_TOGGLE => $value]);
return $this->dataAttributes([
DataAttributes::COLLAPSE_TOGGLE => $value,
]);
}
}
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataDismissTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ trait HasDataDismissTarget
public function dataDismissTarget(bool|string $value): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributes::DISMISS_TARGET => $value]);
return $this->dataAttributes([
DataAttributes::DISMISS_TARGET => $value,
]);
}

$new = clone $this;
Expand Down
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataDrawerTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ trait HasDataDrawerTarget
public function dataDrawerTarget(bool|string $value): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributes::DRAWER_TARGET => $value]);
return $this->dataAttributes([
DataAttributes::DRAWER_TARGET => $value,
]);
}

$new = clone $this;
Expand Down
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataDropdownToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ trait HasDataDropdownToggle
public function dataDropdownToggle(bool|string $value): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributes::DROPDOWN_TOGGLE => $value]);
return $this->dataAttributes([
DataAttributes::DROPDOWN_TOGGLE => $value,
]);
}

$new = clone $this;
Expand Down
4 changes: 3 additions & 1 deletion src/Attribute/Custom/HasDataToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ trait HasDataToggle
public function dataToggle(bool|string $value): static
{
if (is_string($value)) {
return $this->dataAttributes([DataAttributes::TOGGLE => $value]);
return $this->dataAttributes([
DataAttributes::TOGGLE => $value,
]);
}

$new = clone $this;
Expand Down
14 changes: 10 additions & 4 deletions src/Base/AbstractSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ private function renderItems(mixed $formValue): array
$options = [];

foreach ($content as $v => $c) {
/** @psalm-var array */
/** @psalm-var array[] $itemsAttributes */
$itemsAttributes[$v] ??= [];
$options[] = Tag::widget()
->attributes(
array_merge(
$itemsAttributes[$v],
['selected' => in_array($v, $formValue), 'value' => $v],
[
'selected' => in_array($v, $formValue),
'value' => $v,
],
)
)
->content($c)
Expand All @@ -135,13 +138,16 @@ private function renderItems(mixed $formValue): array
->tagName('optgroup')
->render();
} else {
/** @psalm-var array */
/** @psalm-var array[] $itemsAttributes */
$itemsAttributes[$value] ??= [];
$items[] = Tag::widget()
->attributes(
array_merge(
$itemsAttributes[$value],
['selected' => in_array($value, $formValue), 'value' => $value],
[
'selected' => in_array($value, $formValue),
'value' => $value,
],
)
)
->content($content)
Expand Down
4 changes: 2 additions & 2 deletions src/ButtonToggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ protected function run(): string

$id = $this->generateId('button-toggle-');

if ($this->ariaControls) {
if ($this->ariaControls === true) {
$attributes['aria-controls'] = $this->toggleId;
}

if ($this->dataBsTarget) {
if ($this->dataBsTarget === true) {
$attributes['data-bs-target'] = "#$this->toggleId";
}

Expand Down
2 changes: 1 addition & 1 deletion src/Helper/CssClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CssClass
*/
public static function add(array &$attributes, array|string $class, bool $override = false): void
{
if (empty($class)) {
if ($class === '' || $class === []) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Helper/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public static function value(mixed $value, bool $doubleEncode = true, string $en
{
$value = htmlspecialchars((string) $value, self::HTMLSPECIALCHARS_FLAGS, $encoding, $doubleEncode);

return strtr($value, ['\u{0000}' => '&#0;']); // U+0000 NULL
return strtr($value, [
'\u{0000}' => '&#0;',
]); // U+0000 NULL
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Helper/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ private static function parseAttribute(string $attribute): array
throw new InvalidArgumentException('Attribute name must contain word characters only.');
}

return ['name' => $matches[2], 'prefix' => $matches[1], 'suffix' => $matches[3]];
return [
'name' => $matches[2],
'prefix' => $matches[1],
'suffix' => $matches[3],
];
}
}
4 changes: 3 additions & 1 deletion src/Input/Base/AbstractButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ protected function run(): string
->suffixContainerTag($this->suffixContainerTag)
->tagName('input')
->template($this->template)
->tokenValues(['{label}' => $this->renderLabelTag($labelFor)])
->tokenValues([
'{label}' => $this->renderLabelTag($labelFor),
])
->type($this->type)
->render()
);
Expand Down

0 comments on commit 55a2398

Please sign in to comment.