Skip to content

Commit ab0319d

Browse files
committed
Refactor and enhance code quality across multiple widget files
- Added strict typing declarations to improve type safety. - Updated file headers to include package information and licensing details. - Improved code formatting and consistency, including the use of `<<<'EOD'` for multi-line strings. - Enhanced method signatures with return types for better clarity. - Refactored JavaScript inclusion and property handling in various widget classes. - Updated test classes to reflect changes in namespaces and improve method documentation. - Ensured all tests have appropriate coverage annotations and are structured for clarity.
1 parent 86a1247 commit ab0319d

38 files changed

+1072
-476
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ composer.lock
2626
/debian/php-ease-bootstrap-widgets-doc.substvars
2727
/debian/php-ease-bootstrap-widgets.substvars
2828
/debian/files
29+
/tests/.phpunit.result.cache
30+
/.build/

.php-cs-fixer.dist.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the Ease TWBootstrap4 Widgets package
7+
*
8+
* https://github.com/VitexSoftware/php-ease-twbootstrap4-widgets
9+
*
10+
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
11+
*
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
14+
*/
15+
16+
use Ergebnis\PhpCsFixer\Config\Factory;
17+
use Ergebnis\PhpCsFixer\Config\Rules;
18+
use Ergebnis\PhpCsFixer\Config\RuleSet\Php81;
19+
20+
$header = <<<'HEADER'
21+
This file is part of the Ease TWBootstrap4 Widgets package
22+
23+
https://github.com/VitexSoftware/php-ease-twbootstrap4-widgets
24+
25+
(c) Vítězslav Dvořák <http://vitexsoftware.com>
26+
27+
For the full copyright and license information, please view the LICENSE
28+
file that was distributed with this source code.
29+
HEADER;
30+
31+
$ruleSet = Php81::create()->withHeader($header)->withRules(Rules::fromArray([
32+
'blank_line_before_statement' => [
33+
'statements' => [
34+
'break',
35+
'continue',
36+
'declare',
37+
'default',
38+
'do',
39+
'exit',
40+
'for',
41+
'foreach',
42+
'goto',
43+
'if',
44+
'include',
45+
'include_once',
46+
'require',
47+
'require_once',
48+
'return',
49+
'switch',
50+
'throw',
51+
'try',
52+
'while',
53+
],
54+
],
55+
'concat_space' => [
56+
'spacing' => 'none',
57+
],
58+
'date_time_immutable' => false,
59+
'error_suppression' => false,
60+
'final_class' => false,
61+
'mb_str_functions' => false,
62+
'native_function_invocation' => [
63+
'exclude' => [
64+
'sprintf',
65+
],
66+
'include' => [
67+
'@compiler_optimized',
68+
],
69+
'scope' => 'all',
70+
'strict' => false,
71+
],
72+
'php_unit_internal_class' => false,
73+
'php_unit_test_annotation' => [
74+
'style' => 'prefix',
75+
],
76+
'php_unit_test_class_requires_covers' => false,
77+
'return_to_yield_from' => false,
78+
'phpdoc_array_type' => false,
79+
'phpdoc_list_type' => false,
80+
'attribute_empty_parentheses' => false,
81+
'final_public_method_for_abstract_class' => false,
82+
'class_attributes_separation' => [
83+
'elements' => [
84+
'const' => 'only_if_meta',
85+
'property' => 'only_if_meta',
86+
'trait_import' => 'none',
87+
'case' => 'none',
88+
],
89+
],
90+
'yoda_style' => false,
91+
'php_unit_test_case_static_method_calls' => false,
92+
]));
93+
94+
$config = Factory::fromRuleSet($ruleSet);
95+
96+
$config->getFinder()
97+
->append([
98+
__DIR__.'/.php-cs-fixer.dist.php',
99+
])
100+
->in('src')
101+
->in('tests');
102+
103+
$config->setCacheFile(__DIR__.'/.build/php-cs-fixer/.php-cs-fixer.cache');
104+
105+
return $config;

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"Ease\\ui\\BrowsingHistoryTest::testFinalize":8,"Test\\Ease\\ui\\MainPageMenuTest::testAddMenuItem":8,"Test\\Ease\\ui\\MainPageMenuTest::testFinalize":8,"Test\\Ease\\ui\\SemaforLEDTest::testColorNameToHex":8,"Test\\Ease\\ui\\SemaforLEDTest::testGetColorCode":8,"Test\\Ease\\ui\\SemaforLEDTest::testAdjustBrightness":8,"Test\\Ease\\ui\\TWBSwitchTest::testConstructor":8,"Test\\Ease\\ui\\TWBSwitchTest::testConstructorDefaultProperties":8,"Test\\Ease\\ui\\TWBSwitchTest::testSetPropertiesMergesProperties":8,"Test\\Ease\\ui\\TWBSwitchTest::testFinalizeIncludesAssets":8,"Test\\Ease\\ui\\TWBSwitchTest::testFinalizeAddsJavascript":8,"Test\\Ease\\ui\\TWBSwitchTest::testSetProperties":8,"Test\\Ease\\ui\\TWBSwitchTest::testFinalize":8,"Test\\Ease\\ui\\TWBTreeViewTest::testFinalize":8},"times":[]}

Examples/twbswitch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*
66
* @author Vítězslav Dvořák <[email protected]>
7-
* @copyright 2016 Vitex Software
7+
* @copyright 2016-2024 Vitex Software
88
*/
99

1010
include '../vendor/autoload.php';

Makefile

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
repoversion=$(shell LANG=C aptitude show php-ease-bootstrap-widgets | grep Version: | awk '{print $$2}')
2-
nextversion=$(shell echo $(repoversion) | perl -ne 'chomp; print join(".", splice(@{[split/\./,$$_]}, 0, -1), map {++$$_} pop @{[split/\./,$$_]}), "\n";')
3-
4-
5-
6-
clean:
7-
rm -rf debian/ease-framework-bricks
8-
rm -rf debian/ease-framework-bricks-doc
9-
rm -rf debian/*.log
10-
rm -rf docs/*
11-
12-
doc:
13-
debian/apigendoc.sh
14-
15-
test:
16-
composer update
17-
echo sudo service postgresql start ; sudo service postgresql start
18-
phpunit --bootstrap tests/Bootstrap.php --configuration tests/configuration.xml tests
19-
codecept run
20-
release:
21-
echo Release v$(nextversion)
22-
dch -v $(nextversion) `git log -1 --pretty=%B | head -n 1`
23-
debuild -i -us -uc -b
24-
git commit -a -m "Release v$(nextversion)"
25-
git tag -a $(nextversion) -m "version $(nextversion)"
1+
# vim: set tabstop=8 softtabstop=8 noexpandtab:
2+
.PHONY: help
3+
help: ## Displays this list of targets with descriptions
4+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
5+
6+
.PHONY: static-code-analysis
7+
static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan
8+
vendor/bin/phpstan analyse --configuration=phpstan-default.neon.dist --memory-limit=-1
9+
10+
.PHONY: static-code-analysis-baseline
11+
static-code-analysis-baseline: check-symfony vendor ## Generates a baseline for static code analysis with phpstan/phpstan
12+
vendor/bin/phpstan analyze --configuration=phpstan-default.neon.dist --generate-baseline=phpstan-default-baseline.neon --memory-limit=-1
13+
14+
.PHONY: tests
15+
tests: vendor
16+
vendor/bin/phpunit tests
17+
18+
.PHONY: vendor
19+
vendor: composer.json composer.lock ## Installs composer dependencies
20+
composer install
21+
22+
.PHONY: cs
23+
cs: ## Update Coding Standards
24+
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose
2625

2726

2827
deb:

composer.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@
2222
},
2323
"minimum-stability": "stable",
2424
"require": {
25-
"vitexsoftware/ease-twbootstrap": ">=0.4.3"
25+
"vitexsoftware/ease-twbootstrap": "^1.0"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": ">=9"
28+
"phpunit/phpunit": "*",
29+
"phpstan/phpstan": "*",
30+
"friendsofphp/php-cs-fixer": "^3.61",
31+
"ergebnis/composer-normalize": "^2.43",
32+
"ergebnis/php-cs-fixer-config": "^6.34"
2933
},
3034
"type": "library",
3135
"homepage": "http://v.s.cz/ease.php",
32-
"license": "GPL-2.0+"
36+
"license": "GPL-2.0+",
37+
"config": {
38+
"allow-plugins": {
39+
"ergebnis/composer-normalize": true
40+
}
41+
}
3342
}

phpstan-default-baseline.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors:

phpstan-default.neon.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- phpstan-default-baseline.neon
3+
4+
parameters:
5+
inferPrivatePropertyTypeFromConstructor: true
6+
level: 6
7+
paths:
8+
- src
9+
- tests

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="./testing/bootstrap.php">
2+
<phpunit colors="true" bootstrap="./tests/Bootstrap.php">
33
<testsuites>
44
<testsuite name="all">
55
<directory>./tests</directory>
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
3-
* EasePHP Bricks - Browsing History.
6+
* This file is part of the Ease TWBootstrap4 Widgets package
7+
*
8+
* https://github.com/VitexSoftware/php-ease-twbootstrap4-widgets
9+
*
10+
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
411
*
5-
* @author Vítězslav Dvořák <[email protected]>
6-
* @copyright 2016-2018 Vitex Software
12+
* For the full copyright and license information, please view the LICENSE
13+
* file that was distributed with this source code.
714
*/
815

916
namespace Ease\TWB\Widgets;
1017

1118
/**
12-
* Show history of visited pages in app
13-
*
19+
* Show history of visited pages in app.
20+
*
1421
* @param mixed $content
1522
* @param array $properties
1623
*/
1724
class BrowsingHistory extends \Ease\Html\DivTag
1825
{
19-
2026
/**
21-
* Show history of visited pages in app
22-
*
27+
* Show history of visited pages in app.
28+
*
2329
* @param mixed $content
2430
* @param array $properties
2531
*/
2632
public function __construct($content = null, $properties = null)
2733
{
2834
$webPage = \Ease\WebPage::singleton();
29-
if (is_null($properties)) {
35+
36+
if (null === $properties) {
3037
$properties = [];
3138
}
39+
3240
$properties['id'] = 'history';
3341

3442
if (!isset($_SESSION['history'])) {
@@ -37,33 +45,42 @@ public function __construct($content = null, $properties = null)
3745

3846
parent::__construct(null, $properties);
3947

40-
$currentUrl = \Ease\Document::phpSelf(false);
48+
$currentUrl = \Ease\Document::phpSelf(false);
4149
$currentTitle = $webPage->pageTitle;
4250

43-
4451
foreach ($_SESSION['history'] as $hid => $page) {
45-
if ($page['url'] == $currentUrl) {
52+
if ($page['url'] === $currentUrl) {
4653
unset($_SESSION['history'][$hid]);
4754
}
4855
}
49-
array_unshift($_SESSION['history'],
50-
['url' => $currentUrl, 'title' => $currentTitle]);
56+
57+
array_unshift(
58+
$_SESSION['history'],
59+
['url' => $currentUrl, 'title' => $currentTitle],
60+
);
61+
5162
foreach ($_SESSION['history'] as $bookmark) {
52-
$this->addItem(new \Ease\Html\SpanTag(new \Ease\Html\ATag($bookmark['url'],
53-
[new \Ease\TWB\GlyphIcon('bookmark'), ' '.$bookmark['title']]),
54-
['class' => 'hitem']));
63+
$this->addItem(new \Ease\Html\SpanTag(
64+
new \Ease\Html\ATag(
65+
$bookmark['url'],
66+
[new \Ease\TWB\GlyphIcon('bookmark'), ' '.$bookmark['title']],
67+
),
68+
['class' => 'hitem'],
69+
));
5570
}
5671
}
5772

5873
/**
59-
* Add Css
74+
* Add Css.
6075
*/
61-
function finalize()
76+
public function finalize(): void
6277
{
63-
$this->addCss('
78+
$this->addCss(<<<'EOD'
79+
6480
.hitem { background-color: #B5FFC4; margin: 5px; border-radius: 15px 50px 30px 5px; padding-left: 3px; padding-right: 10px; }
6581
#history { margin: 5px; }
66-
');
82+
83+
EOD);
6784
parent::finalize();
6885
}
6986
}

0 commit comments

Comments
 (0)