From 20c4c721ae9222cfa1f0f4aa9be57b2c919cca75 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Jan 2026 15:01:57 +0300 Subject: [PATCH 1/4] Add PHP CS Fixer --- .github/workflows/rector-cs.yml | 27 +++++++++++ .github/workflows/rector.yml | 24 ---------- .gitignore | 11 ++--- .php-cs-fixer.dist.php | 21 ++++++++ .styleci.yml | 85 --------------------------------- composer.json | 2 + 6 files changed, 53 insertions(+), 117 deletions(-) create mode 100644 .github/workflows/rector-cs.yml delete mode 100644 .github/workflows/rector.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .styleci.yml diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 000000000..6424c2aab --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +on: + pull_request_target: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + php: '8.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index bb33197b6..000000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - os: >- - ['ubuntu-latest'] - php: >- - ['8.1'] diff --git a/.gitignore b/.gitignore index 60a33a6bb..81485c477 100644 --- a/.gitignore +++ b/.gitignore @@ -34,11 +34,6 @@ composer.phar /phpunit.xml /.phpunit.cache -# ignore dev installed apps and extensions -/apps -/extensions -/packages - -# NPM packages -/node_modules -.env +# PHP CS Fixer +/.php-cs-fixer.cache +/.php-cs-fixer.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 000000000..2477e66d8 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return ConfigBuilder::build() + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@Yiisoft/Core' => true, + '@Yiisoft/Core:risky' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 1ab379b46..000000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.1 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/composer.json b/composer.json index 54e549c7f..6866cf98b 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "rector/rector": "^2.3.4", "spatie/phpunit-watcher": "^1.24.4", "yiisoft/aliases": "^3.1.1", + "yiisoft/code-style": "^1.0", "yiisoft/di": "^1.4.1", "yiisoft/psr-dummy-provider": "^1.0.2", "yiisoft/test-support": "^3.1.0" @@ -83,6 +84,7 @@ }, "scripts": { "bench": "phpbench run", + "cs-fix": "php-cs-fixer fix", "infection": "infection --threads=max", "test": "phpunit --testdox", "test-watch": "phpunit-watcher watch" From 7f6189aa54bc9685ebae0c4622f4b17c18750562 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Jan 2026 15:02:21 +0300 Subject: [PATCH 2/4] Apply PHP CS Fixer --- src/Cache/CachedContent.php | 6 +- src/Cache/DynamicContent.php | 2 +- src/Event/View/AfterRender.php | 5 +- src/Event/View/BeforeRender.php | 5 +- src/Event/View/PageBegin.php | 4 +- src/Event/View/PageEnd.php | 4 +- src/Event/View/ViewEvent.php | 5 +- src/Event/WebView/AfterRender.php | 5 +- src/Event/WebView/BeforeRender.php | 5 +- src/Event/WebView/BodyBegin.php | 4 +- src/Event/WebView/BodyEnd.php | 4 +- src/Event/WebView/Head.php | 4 +- src/Event/WebView/PageBegin.php | 4 +- src/Event/WebView/PageEnd.php | 4 +- src/Event/WebView/WebViewEvent.php | 5 +- src/Exception/ViewNotFoundException.php | 4 +- src/PhpTemplateRenderer.php | 2 + src/State/LocaleState.php | 5 +- src/State/StateTrait.php | 3 +- src/State/ThemeState.php | 5 +- src/State/WebViewState.php | 35 ++-- src/Theme.php | 4 +- src/View.php | 2 +- src/ViewContext.php | 5 +- src/ViewInterface.php | 4 +- src/ViewTrait.php | 37 ++-- src/WebView.php | 46 ++--- tests/Benchmark/BlocksBench.php | 4 +- tests/Benchmark/MultiRendererBench.php | 6 +- tests/Benchmark/NestedViewsBench.php | 2 +- tests/Benchmark/ViewThemeBench.php | 2 + tests/CachedContentTest.php | 8 +- tests/ConfigTest.php | 7 +- tests/TestSupport/StringableObject.php | 3 +- tests/TestSupport/TestTrait.php | 2 +- tests/ThemeTest.php | 2 +- tests/View/RelativePath/RelativePathTest.php | 2 +- .../views-parent/template/nested/template.php | 3 +- .../views-parent/template/with-extension.php | 3 +- .../template/without-extension.php | 3 +- tests/ViewTest.php | 44 ++--- tests/WebViewTest.php | 170 +++++++++--------- 42 files changed, 237 insertions(+), 242 deletions(-) diff --git a/src/Cache/CachedContent.php b/src/Cache/CachedContent.php index 135e0c0e3..c360d051b 100644 --- a/src/Cache/CachedContent.php +++ b/src/Cache/CachedContent.php @@ -40,7 +40,7 @@ public function __construct( private readonly string $id, private readonly CacheInterface $cache, array $dynamicContents = [], - array $variations = [] + array $variations = [], ) { $this->setDynamicContents($dynamicContents); $this->setVariations($variations); @@ -61,8 +61,8 @@ public function __construct( public function cache( string $content, DateInterval|int|null $ttl = 60, - Dependency|null $dependency = null, - float $beta = 1.0 + ?Dependency $dependency = null, + float $beta = 1.0, ): string { /** @psalm-suppress MixedArgument */ return $this->replaceDynamicPlaceholders( diff --git a/src/Cache/DynamicContent.php b/src/Cache/DynamicContent.php index 31dec3782..c69f53b6b 100644 --- a/src/Cache/DynamicContent.php +++ b/src/Cache/DynamicContent.php @@ -22,7 +22,7 @@ final class DynamicContent public function __construct( private readonly string $id, callable $contentGenerator, - private readonly array $parameters = [] + private readonly array $parameters = [], ) { $this->contentGenerator = $contentGenerator; } diff --git a/src/Event/View/AfterRender.php b/src/Event/View/AfterRender.php index f7233d387..85b699ee1 100644 --- a/src/Event/View/AfterRender.php +++ b/src/Event/View/AfterRender.php @@ -20,9 +20,8 @@ public function __construct( private readonly View $view, private readonly string $file, private readonly array $parameters, - private readonly string $result - ) { - } + private readonly string $result, + ) {} public function getView(): View { diff --git a/src/Event/View/BeforeRender.php b/src/Event/View/BeforeRender.php index f9660f8d7..3e3e7a7d6 100644 --- a/src/Event/View/BeforeRender.php +++ b/src/Event/View/BeforeRender.php @@ -21,9 +21,8 @@ final class BeforeRender implements StoppableEventInterface public function __construct( private readonly View $view, private readonly string $file, - private readonly array $parameters - ) { - } + private readonly array $parameters, + ) {} public function stopPropagation(): void { diff --git a/src/Event/View/PageBegin.php b/src/Event/View/PageBegin.php index 92ab85365..0277bfda3 100644 --- a/src/Event/View/PageBegin.php +++ b/src/Event/View/PageBegin.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\View; -final class PageBegin extends ViewEvent -{ -} +final class PageBegin extends ViewEvent {} diff --git a/src/Event/View/PageEnd.php b/src/Event/View/PageEnd.php index fa79d15e8..eda1459e4 100644 --- a/src/Event/View/PageEnd.php +++ b/src/Event/View/PageEnd.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\View; -final class PageEnd extends ViewEvent -{ -} +final class PageEnd extends ViewEvent {} diff --git a/src/Event/View/ViewEvent.php b/src/Event/View/ViewEvent.php index acf7e72d9..6f374c0ca 100644 --- a/src/Event/View/ViewEvent.php +++ b/src/Event/View/ViewEvent.php @@ -12,9 +12,8 @@ abstract class ViewEvent { final public function __construct( - private readonly View $view - ) { - } + private readonly View $view, + ) {} final public function getView(): View { diff --git a/src/Event/WebView/AfterRender.php b/src/Event/WebView/AfterRender.php index 2359572ce..ae9f9139c 100644 --- a/src/Event/WebView/AfterRender.php +++ b/src/Event/WebView/AfterRender.php @@ -20,9 +20,8 @@ public function __construct( private readonly WebView $view, private readonly string $file, private readonly array $parameters, - private readonly string $result - ) { - } + private readonly string $result, + ) {} public function getView(): WebView { diff --git a/src/Event/WebView/BeforeRender.php b/src/Event/WebView/BeforeRender.php index 038b62fd0..717398164 100644 --- a/src/Event/WebView/BeforeRender.php +++ b/src/Event/WebView/BeforeRender.php @@ -21,9 +21,8 @@ final class BeforeRender implements StoppableEventInterface public function __construct( private readonly WebView $view, private readonly string $file, - private readonly array $parameters - ) { - } + private readonly array $parameters, + ) {} public function stopPropagation(): void { diff --git a/src/Event/WebView/BodyBegin.php b/src/Event/WebView/BodyBegin.php index 2cf4e1b75..b5ee5dabc 100644 --- a/src/Event/WebView/BodyBegin.php +++ b/src/Event/WebView/BodyBegin.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\WebView; -final class BodyBegin extends WebViewEvent -{ -} +final class BodyBegin extends WebViewEvent {} diff --git a/src/Event/WebView/BodyEnd.php b/src/Event/WebView/BodyEnd.php index 0a187294c..fa06d2dcc 100644 --- a/src/Event/WebView/BodyEnd.php +++ b/src/Event/WebView/BodyEnd.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\WebView; -final class BodyEnd extends WebViewEvent -{ -} +final class BodyEnd extends WebViewEvent {} diff --git a/src/Event/WebView/Head.php b/src/Event/WebView/Head.php index fdd353a34..381bdfbe8 100644 --- a/src/Event/WebView/Head.php +++ b/src/Event/WebView/Head.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\WebView; -final class Head extends WebViewEvent -{ -} +final class Head extends WebViewEvent {} diff --git a/src/Event/WebView/PageBegin.php b/src/Event/WebView/PageBegin.php index 94bfd1cfb..a8365cbe8 100644 --- a/src/Event/WebView/PageBegin.php +++ b/src/Event/WebView/PageBegin.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\WebView; -final class PageBegin extends WebViewEvent -{ -} +final class PageBegin extends WebViewEvent {} diff --git a/src/Event/WebView/PageEnd.php b/src/Event/WebView/PageEnd.php index cf9cd0d12..5c9edc640 100644 --- a/src/Event/WebView/PageEnd.php +++ b/src/Event/WebView/PageEnd.php @@ -4,6 +4,4 @@ namespace Yiisoft\View\Event\WebView; -final class PageEnd extends WebViewEvent -{ -} +final class PageEnd extends WebViewEvent {} diff --git a/src/Event/WebView/WebViewEvent.php b/src/Event/WebView/WebViewEvent.php index 83f78d05d..daac4b4f9 100644 --- a/src/Event/WebView/WebViewEvent.php +++ b/src/Event/WebView/WebViewEvent.php @@ -12,9 +12,8 @@ abstract class WebViewEvent { final public function __construct( - private readonly WebView $view - ) { - } + private readonly WebView $view, + ) {} final public function getView(): WebView { diff --git a/src/Exception/ViewNotFoundException.php b/src/Exception/ViewNotFoundException.php index 55640e3bd..2f826475b 100644 --- a/src/Exception/ViewNotFoundException.php +++ b/src/Exception/ViewNotFoundException.php @@ -6,6 +6,4 @@ use Exception; -final class ViewNotFoundException extends Exception -{ -} +final class ViewNotFoundException extends Exception {} diff --git a/src/PhpTemplateRenderer.php b/src/PhpTemplateRenderer.php index d923bea9e..f74628a6b 100644 --- a/src/PhpTemplateRenderer.php +++ b/src/PhpTemplateRenderer.php @@ -14,6 +14,8 @@ use function ob_implicit_flush; use function ob_start; +use const EXTR_OVERWRITE; + /** * `PhpTemplateRenderer` renders the PHP views. */ diff --git a/src/State/LocaleState.php b/src/State/LocaleState.php index ef198911d..77a6ccd8a 100644 --- a/src/State/LocaleState.php +++ b/src/State/LocaleState.php @@ -10,9 +10,8 @@ final class LocaleState { public function __construct( - private string $locale = 'en' - ) { - } + private string $locale = 'en', + ) {} /** * Set the specified locale code. diff --git a/src/State/StateTrait.php b/src/State/StateTrait.php index bd7c1a30b..2de0b14f0 100644 --- a/src/State/StateTrait.php +++ b/src/State/StateTrait.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use function is_array; +use function sprintf; /** * @internal @@ -70,7 +71,7 @@ public function addToParameter(string $id, mixed ...$value): static $array = $this->parameters[$id] ?? []; if (!is_array($array)) { throw new InvalidArgumentException( - sprintf('The "%s" parameter already exists and is not an array.', $id) + sprintf('The "%s" parameter already exists and is not an array.', $id), ); } diff --git a/src/State/ThemeState.php b/src/State/ThemeState.php index d7d2f189c..c1e3887f9 100644 --- a/src/State/ThemeState.php +++ b/src/State/ThemeState.php @@ -12,9 +12,8 @@ final class ThemeState { public function __construct( - private ?Theme $theme = null - ) { - } + private ?Theme $theme = null, + ) {} /** * Set the specified view theme. diff --git a/src/State/WebViewState.php b/src/State/WebViewState.php index ad746ef66..8ce951cda 100644 --- a/src/State/WebViewState.php +++ b/src/State/WebViewState.php @@ -13,11 +13,14 @@ use Yiisoft\Html\Tag\Style; use Yiisoft\Json\Json; use Yiisoft\View\WebView; +use Yiisoft\Assets\AssetBundle; +use Yiisoft\Assets\AssetManager; use function array_key_exists; use function in_array; use function is_array; use function is_string; +use function sprintf; /** * @internal @@ -232,7 +235,7 @@ public function registerCss( string $css, int $position = WebView::POSITION_HEAD, array $attributes = [], - ?string $key = null + ?string $key = null, ): void { $this->css[$position][$key ?? md5($css)] = $attributes === [] ? $css : Html::style($css, $attributes); } @@ -248,7 +251,7 @@ public function registerCssFromFile( string $path, int $position = WebView::POSITION_HEAD, array $attributes = [], - ?string $key = null + ?string $key = null, ): void { $css = file_get_contents($path); if ($css === false) { @@ -272,11 +275,11 @@ public function registerStyleTag(Style $style, int $position = WebView::POSITION * Registers a CSS file. * * This method should be used for simple registration of CSS files. If you want to use features of - * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use - * {@see \Yiisoft\Assets\AssetBundle}. + * {@see AssetManager} like appending timestamps to the URL and file publishing options, use + * {@see AssetBundle}. * * @param string $url The CSS file to be registered. - * @param array $options the HTML attributes for the link tag. Please refer to {@see \Yiisoft\Html\Html::cssFile()} + * @param array $options the HTML attributes for the link tag. Please refer to {@see Html::cssFile()} * for the supported options. * @param string|null $key The key that identifies the CSS script file. If `null`, it will use `$url` as the key. * If two CSS files are registered with the same key, the latter will overwrite the former. @@ -285,7 +288,7 @@ public function registerCssFile( string $url, int $position = WebView::POSITION_HEAD, array $options = [], - ?string $key = null + ?string $key = null, ): void { if (!$this->isValidCssPosition($position)) { throw new InvalidArgumentException('Invalid position of CSS file.'); @@ -357,8 +360,8 @@ public function registerScriptTag(Script $script, int $position = WebView::POSIT * Registers a JS file. * * This method should be used for simple registration of JS files. If you want to use features of - * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use - * {@see \Yiisoft\Assets\AssetBundle}. + * {@see AssetManager} like appending timestamps to the URL and file publishing options, use + * {@see AssetBundle}. * * @param string $url The JS file to be registered. * @param array $options The HTML attributes for the script tag. The following options are specially handled and @@ -369,7 +372,7 @@ public function registerScriptTag(Script $script, int $position = WebView::POSIT * * {@see WebView::POSITION_BEGIN}: at the beginning of the body section * * {@see WebView::POSITION_END}: at the end of the body section. This is the default value. * - * Please refer to {@see \Yiisoft\Html\Html::javaScriptFile()} for other supported options. + * Please refer to {@see Html::javaScriptFile()} for other supported options. * @param string|null $key The key that identifies the JS script file. If null, it will use $url as the key. * If two JS files are registered with the same key at the same position, the latter will overwrite the former. * Note that position option takes precedence, thus files registered with the same key, but different @@ -379,7 +382,7 @@ public function registerJsFile( string $url, int $position = WebView::POSITION_END, array $options = [], - ?string $key = null + ?string $key = null, ): void { if (!$this->isValidJsPosition($position)) { throw new InvalidArgumentException('Invalid position of JS file.'); @@ -437,7 +440,7 @@ public function addJsStrings(array $jsStrings): void foreach ($jsStrings as $key => $value) { $this->registerJsStringByConfig( is_string($key) ? $key : null, - is_array($value) ? $value : [$value, WebView::POSITION_END] + is_array($value) ? $value : [$value, WebView::POSITION_END], ); } } @@ -492,7 +495,7 @@ private function registerCssFileByConfig(?string $key, array $config): void sprintf( 'CSS file should be string. Got %s.', get_debug_type($file), - ) + ), ); } @@ -517,7 +520,7 @@ private function registerCssStringByConfig(?string $key, array $config): void sprintf( 'CSS string should be string or instance of \\' . Style::class . '. Got %s.', get_debug_type($css), - ) + ), ); } @@ -567,7 +570,7 @@ private function registerJsFileByConfig(?string $key, array $config): void sprintf( 'JS file should be string. Got %s.', get_debug_type($file), - ) + ), ); } @@ -592,7 +595,7 @@ private function registerJsStringByConfig(?string $key, array $config): void sprintf( 'JS string should be string or instance of \\' . Script::class . '. Got %s.', get_debug_type($js), - ) + ), ); } @@ -626,7 +629,7 @@ private function registerJsVarByConfig(array $config): void sprintf( 'JS variable name should be string. Got %s.', get_debug_type($key), - ) + ), ); } diff --git a/src/Theme.php b/src/Theme.php index 6ceb63d96..465348586 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -201,7 +201,7 @@ private function validatePathMap(array $pathMap): void } /** @var mixed $destination */ - foreach ((array)$destinations as $destination) { + foreach ((array) $destinations as $destination) { if (!is_string($destination)) { $this->throwInvalidPathMapException(); } @@ -212,7 +212,7 @@ private function validatePathMap(array $pathMap): void private function throwInvalidPathMapException(): never { throw new InvalidArgumentException( - 'The path map should contain the mapping between view directories and corresponding theme directories.' + 'The path map should contain the mapping between view directories and corresponding theme directories.', ); } } diff --git a/src/View.php b/src/View.php index 9705c1002..d132b3a75 100644 --- a/src/View.php +++ b/src/View.php @@ -98,7 +98,7 @@ protected function createBeforeRenderEvent(string $viewFile, array $parameters): protected function createAfterRenderEvent( string $viewFile, array $parameters, - string $result + string $result, ): AfterRenderEventInterface { return new AfterRender($this, $viewFile, $parameters, $result); } diff --git a/src/ViewContext.php b/src/ViewContext.php index 477add298..a9e8c186a 100644 --- a/src/ViewContext.php +++ b/src/ViewContext.php @@ -7,9 +7,8 @@ final class ViewContext implements ViewContextInterface { public function __construct( - private readonly string $viewPath - ) { - } + private readonly string $viewPath, + ) {} public function getViewPath(): string { diff --git a/src/ViewInterface.php b/src/ViewInterface.php index 7d88d7abe..b8b2e8f4d 100644 --- a/src/ViewInterface.php +++ b/src/ViewInterface.php @@ -24,7 +24,7 @@ interface ViewInterface * * @param string|null $basePath The base path to the view directory. */ - public function withBasePath(string|null $basePath): static; + public function withBasePath(?string $basePath): static; /** * Returns a new instance with the specified renderers. @@ -55,7 +55,7 @@ public function withSourceLocale(string $locale): static; * * @param ViewContextInterface|null $context The context under which the {@see render()} method is being invoked. */ - public function withContext(ViewContextInterface|null $context): static; + public function withContext(?ViewContextInterface $context): static; /** * Returns a new instance with the specified view context path. diff --git a/src/ViewTrait.php b/src/ViewTrait.php index a3d341f35..d4a09d041 100644 --- a/src/ViewTrait.php +++ b/src/ViewTrait.php @@ -13,6 +13,8 @@ use Yiisoft\View\Exception\ViewNotFoundException; use Yiisoft\View\State\LocaleState; use Yiisoft\View\State\ThemeState; +use Yiisoft\View\Event\View\AfterRender; +use Yiisoft\View\Event\View\BeforeRender; use function array_merge; use function array_pop; @@ -24,6 +26,13 @@ use function is_file; use function pathinfo; use function substr; +use function is_object; +use function is_string; +use function sprintf; +use function strlen; + +use const DIRECTORY_SEPARATOR; +use const PATHINFO_EXTENSION; /** * `ViewTrait` could be used as a base implementation of {@see ViewInterface}. @@ -67,7 +76,7 @@ trait ViewTrait * * @param string|null $basePath The base path to the view directory. */ - public function withBasePath(string|null $basePath): static + public function withBasePath(?string $basePath): static { $new = clone $this; $new->basePath = $basePath; @@ -98,8 +107,8 @@ public function withRenderers(array $renderers): static sprintf( 'Extension must be a non-empty string, %s provided for %s.', get_debug_type($extension), - $renderer::class - ) + $renderer::class, + ), ); } @@ -109,8 +118,8 @@ public function withRenderers(array $renderers): static throw new InvalidArgumentException( sprintf( 'Empty extension is not supported. Please add extension for %s.', - $rendererType - ) + $rendererType, + ), ); } @@ -120,15 +129,15 @@ public function withRenderers(array $renderers): static sprintf( 'Renderer %s is not an instance of %s.', $rendererType, - TemplateRendererInterface::class - ) + TemplateRendererInterface::class, + ), ); } } uksort( $renderers, - static fn(string $a, string $b): int => strlen($b) <=> strlen($a) + static fn(string $a, string $b): int => strlen($b) <=> strlen($a), ); $new = clone $this; @@ -166,7 +175,7 @@ public function withFallbackExtension(string $fallbackExtension, string ...$othe * * @param ViewContextInterface|null $context The context under which the {@see render()} method is being invoked. */ - public function withContext(ViewContextInterface|null $context): static + public function withContext(?ViewContextInterface $context): static { $new = clone $this; $new->context = $context; @@ -572,7 +581,7 @@ abstract protected function createBeforeRenderEvent(string $viewFile, array $par abstract protected function createAfterRenderEvent( string $viewFile, array $parameters, - string $result + string $result, ): AfterRenderEventInterface; /** @@ -599,8 +608,8 @@ private function getRenderer(string $viewFile): TemplateRendererInterface /** * This method is invoked right before {@see render()} renders a view file. * - * The default implementations will trigger the {@see \Yiisoft\View\Event\View\BeforeRender} - * or {@see \Yiisoft\View\Event\WebView\BeforeRender} event. If you override this method, + * The default implementations will trigger the {@see BeforeRender} + * or {@see Event\WebView\BeforeRender} event. If you override this method, * make sure you call the parent implementation first. * * @param string $viewFile The view file to be rendered. @@ -623,8 +632,8 @@ private function beforeRender(string $viewFile, array $parameters): bool /** * This method is invoked right after {@see render()} renders a view file. * - * The default implementations will trigger the {@see \Yiisoft\View\Event\View\AfterRender} - * or {@see \Yiisoft\View\Event\WebView\AfterRender} event. If you override this method, + * The default implementations will trigger the {@see AfterRender} + * or {@see Event\WebView\AfterRender} event. If you override this method, * make sure you call the parent implementation first. * * @param string $viewFile The view file being rendered. diff --git a/src/WebView.php b/src/WebView.php index 726f22490..65320dff3 100644 --- a/src/WebView.php +++ b/src/WebView.php @@ -24,6 +24,8 @@ use Yiisoft\View\State\LocaleState; use Yiisoft\View\State\ThemeState; use Yiisoft\View\State\WebViewState; +use Yiisoft\Assets\AssetBundle; +use Yiisoft\Assets\AssetManager; use function array_merge; use function implode; @@ -42,10 +44,6 @@ final class WebView implements ViewInterface { use ViewTrait; - private WebViewState $state; - private LocaleState $localeState; - private ThemeState $themeState; - /** * This means the location is in the head section. */ @@ -87,6 +85,10 @@ final class WebView implements ViewInterface */ private const PLACEHOLDER_BODY_END = ''; + private WebViewState $state; + private LocaleState $localeState; + private ThemeState $themeState; + /** * @param string|null $basePath The full path to the base directory of views. * @param EventDispatcherInterface|null $eventDispatcher The event dispatcher instance. @@ -192,7 +194,7 @@ public function endPage(bool $ajaxMode = false): void * Renders a view in response to an AJAX request. * * This method is similar to {@see render()} except that it will surround the view being rendered with the calls of - * {@see beginPage()}, {@see head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the + * {@see beginPage()}, {@see Head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the * method is able to inject into the rendering result with JS/CSS scripts and files that are registered with the * view. * @@ -365,7 +367,7 @@ public function registerCss( string $css, int $position = self::POSITION_HEAD, array $attributes = [], - ?string $key = null + ?string $key = null, ): self { $this->state->registerCss($css, $position, $attributes, $key); return $this; @@ -382,7 +384,7 @@ public function registerCssFromFile( string $path, int $position = self::POSITION_HEAD, array $attributes = [], - ?string $key = null + ?string $key = null, ): self { $this->state->registerCssFromFile($path, $position, $attributes, $key); return $this; @@ -403,11 +405,11 @@ public function registerStyleTag(Style $style, int $position = self::POSITION_HE * Registers a CSS file. * * This method should be used for simple registration of CSS files. If you want to use features of - * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use - * {@see \Yiisoft\Assets\AssetBundle}. + * {@see AssetManager} like appending timestamps to the URL and file publishing options, use + * {@see AssetBundle}. * * @param string $url The CSS file to be registered. - * @param array $options the HTML attributes for the link tag. Please refer to {@see \Yiisoft\Html\Html::cssFile()} + * @param array $options the HTML attributes for the link tag. Please refer to {@see Html::cssFile()} * for the supported options. * @param string|null $key The key that identifies the CSS script file. If null, it will use $url as the key. * If two CSS files are registered with the same key, the latter will overwrite the former. @@ -416,7 +418,7 @@ public function registerCssFile( string $url, int $position = self::POSITION_HEAD, array $options = [], - ?string $key = null + ?string $key = null, ): self { $this->state->registerCssFile($url, $position, $options, $key); return $this; @@ -477,8 +479,8 @@ public function registerScriptTag(Script $script, int $position = self::POSITION * Registers a JS file. * * This method should be used for simple registration of JS files. If you want to use features of - * {@see \Yiisoft\Assets\AssetManager} like appending timestamps to the URL and file publishing options, use - * {@see \Yiisoft\Assets\AssetBundle}. + * {@see AssetManager} like appending timestamps to the URL and file publishing options, use + * {@see AssetBundle}. * * @param string $url The JS file to be registered. * @param array $options The HTML attributes for the script tag. The following options are specially handled and @@ -489,7 +491,7 @@ public function registerScriptTag(Script $script, int $position = self::POSITION * * {@see POSITION_BEGIN}: at the beginning of the body section * * {@see POSITION_END}: at the end of the body section. This is the default value. * - * Please refer to {@see \Yiisoft\Html\Html::javaScriptFile()} for other supported options. + * Please refer to {@see Html::javaScriptFile()} for other supported options. * @param string|null $key The key that identifies the JS script file. If null, it will use $url as the key. * If two JS files are registered with the same key at the same position, the latter will overwrite the former. * Note that position option takes precedence, thus files registered with the same key, but different @@ -499,7 +501,7 @@ public function registerJsFile( string $url, int $position = self::POSITION_END, array $options = [], - ?string $key = null + ?string $key = null, ): self { $this->state->registerJsFile($url, $position, $options, $key); return $this; @@ -568,7 +570,7 @@ protected function createBeforeRenderEvent(string $viewFile, array $parameters): protected function createAfterRenderEvent( string $viewFile, array $parameters, - string $result + string $result, ): AfterRenderEventInterface { return new AfterRender($this, $viewFile, $parameters, $result); } @@ -678,15 +680,15 @@ private function renderBodyEndHtml(bool $ajaxMode): string $lines[] = $this->generateJs($this->state->getJs()[self::POSITION_END]); } if (!empty($this->state->getJs()[self::POSITION_READY])) { - $js = "document.addEventListener('DOMContentLoaded', function(event) {\n" . - $this->generateJsWithoutTag($this->state->getJs()[self::POSITION_READY]) . - "\n});"; + $js = "document.addEventListener('DOMContentLoaded', function(event) {\n" + . $this->generateJsWithoutTag($this->state->getJs()[self::POSITION_READY]) + . "\n});"; $lines[] = Html::script($js)->render(); } if (!empty($this->state->getJs()[self::POSITION_LOAD])) { - $js = "window.addEventListener('load', function(event) {\n" . - $this->generateJsWithoutTag($this->state->getJs()[self::POSITION_LOAD]) . - "\n});"; + $js = "window.addEventListener('load', function(event) {\n" + . $this->generateJsWithoutTag($this->state->getJs()[self::POSITION_LOAD]) + . "\n});"; $lines[] = Html::script($js)->render(); } } diff --git a/tests/Benchmark/BlocksBench.php b/tests/Benchmark/BlocksBench.php index e82a80d66..439fd9bc0 100644 --- a/tests/Benchmark/BlocksBench.php +++ b/tests/Benchmark/BlocksBench.php @@ -30,7 +30,7 @@ public function __construct() $this->setBlock('block-id-1', '...content of block1...'); $this->setBlock('block-id-2', '...content of block2...'); -PHP +PHP, ); } @@ -56,7 +56,7 @@ public function __construct() ... default content for block2 ... -PHP +PHP, ); } diff --git a/tests/Benchmark/MultiRendererBench.php b/tests/Benchmark/MultiRendererBench.php index 72cf88867..4509986dc 100644 --- a/tests/Benchmark/MultiRendererBench.php +++ b/tests/Benchmark/MultiRendererBench.php @@ -31,7 +31,7 @@ public function __construct() /** @var \Yiisoft\View\View $this */ echo 'PHP view'; - PHP_WRAP + PHP_WRAP, ); } @@ -47,13 +47,13 @@ public function __construct() $this->view = (new View($basePath, new SimpleEventDispatcher())) ->withRenderers([ - 'blade' => new class () implements TemplateRendererInterface { + 'blade' => new class implements TemplateRendererInterface { public function render(ViewInterface $view, string $template, array $parameters): string { return file_get_contents($template); } }, - 'tpl' => new class () implements TemplateRendererInterface { + 'tpl' => new class implements TemplateRendererInterface { public function render(ViewInterface $view, string $template, array $parameters): string { return file_get_contents($template); diff --git a/tests/Benchmark/NestedViewsBench.php b/tests/Benchmark/NestedViewsBench.php index 9f6c473b5..e9b5de138 100644 --- a/tests/Benchmark/NestedViewsBench.php +++ b/tests/Benchmark/NestedViewsBench.php @@ -32,7 +32,7 @@ public function __construct() /** @var \Yiisoft\View\View $this */ echo $this->render('./sub/sub'); -PHP +PHP, ); } diff --git a/tests/Benchmark/ViewThemeBench.php b/tests/Benchmark/ViewThemeBench.php index 73831964e..7a0cdc299 100644 --- a/tests/Benchmark/ViewThemeBench.php +++ b/tests/Benchmark/ViewThemeBench.php @@ -8,6 +8,8 @@ use Yiisoft\View\Theme; use Yiisoft\View\View; +use function dirname; + final class ViewThemeBench { private readonly View $view; diff --git a/tests/CachedContentTest.php b/tests/CachedContentTest.php index eff67c144..f5b594566 100644 --- a/tests/CachedContentTest.php +++ b/tests/CachedContentTest.php @@ -43,7 +43,7 @@ public function testCache(?int $ttl, ?Dependency $dependency): void for ($counter = 0; $counter < 42; $counter++) { $dynamicContent = new DynamicContent( 'dynamic-test', - static fn ($params) => (string) $params['counter'], + static fn($params) => (string) $params['counter'], ['counter' => $counter], ); @@ -64,7 +64,7 @@ public function testCacheWithExpiredTtl(): void for ($counter = 0; $counter < 42; $counter++) { $dynamicContent = new DynamicContent( 'dynamic-test', - static fn ($params) => (string) $params['counter'], + static fn($params) => (string) $params['counter'], ['counter' => $counter], ); @@ -82,7 +82,7 @@ public function testCacheWithVariants(): void for ($counter = 0; $counter < 42; $counter++) { $dynamicContent = new DynamicContent( 'dynamic-test', - static fn ($params) => (string) $params['counter'], + static fn($params) => (string) $params['counter'], ['counter' => $counter], ); @@ -112,7 +112,7 @@ public function testTwoCache(): void public function testCacheWithSimilarKey(): void { - $this->cache->getOrSet(CacheKeyNormalizer::normalize(['test']), static fn () => 'hello'); + $this->cache->getOrSet(CacheKeyNormalizer::normalize(['test']), static fn() => 'hello'); $cacheContent = new CachedContent('test', $this->cache); $cacheContent->cache('content'); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 3d9f2cbd5..66c833d1a 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -83,11 +83,10 @@ private function createContainer(?string $postfix = null, ?array $params = null) return new Container( ContainerConfig::create()->withDefinitions( $this->getDiConfig($postfix, $params) - + - [ + + [ EventDispatcherInterface::class => new SimpleEventDispatcher(), - ] - ) + ], + ), ); } diff --git a/tests/TestSupport/StringableObject.php b/tests/TestSupport/StringableObject.php index f781cdac5..f8021bb24 100644 --- a/tests/TestSupport/StringableObject.php +++ b/tests/TestSupport/StringableObject.php @@ -10,8 +10,7 @@ final class StringableObject implements Stringable { public function __construct( private readonly string $value = '', - ) { - } + ) {} public function __toString(): string { diff --git a/tests/TestSupport/TestTrait.php b/tests/TestSupport/TestTrait.php index 46cd72282..a3a3a5de1 100644 --- a/tests/TestSupport/TestTrait.php +++ b/tests/TestSupport/TestTrait.php @@ -22,7 +22,7 @@ protected function assertSameIgnoringSlash(string $expected, string $actual): vo protected function assertEqualStringsIgnoringLineEndings( string $expected, string $actual, - string $message = '' + string $message = '', ): void { $expected = self::normalizeLineEndings($expected); $actual = self::normalizeLineEndings($actual); diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 511752399..e1238a54c 100644 --- a/tests/ThemeTest.php +++ b/tests/ThemeTest.php @@ -174,7 +174,7 @@ public function testInvalidPathMapKey(): void public function testInvalidPathMapValue(): void { $this->expectExceptionMessage( - 'The path map should contain the mapping between view directories and corresponding theme directories.' + 'The path map should contain the mapping between view directories and corresponding theme directories.', ); $this->expectException(InvalidArgumentException::class); diff --git a/tests/View/RelativePath/RelativePathTest.php b/tests/View/RelativePath/RelativePathTest.php index 4c6e1cc4f..afac97fe9 100644 --- a/tests/View/RelativePath/RelativePathTest.php +++ b/tests/View/RelativePath/RelativePathTest.php @@ -31,7 +31,7 @@ public function testRelativeWithoutCurrentView(string $template): void $this->expectException(LogicException::class); $this->expectExceptionMessage( - 'Unable to resolve file for view "' . $template . '": no currently rendered view.' + 'Unable to resolve file for view "' . $template . '": no currently rendered view.', ); $view->render($template); } diff --git a/tests/View/RelativePath/views-parent/template/nested/template.php b/tests/View/RelativePath/views-parent/template/nested/template.php index 9943a5746..887fd9572 100644 --- a/tests/View/RelativePath/views-parent/template/nested/template.php +++ b/tests/View/RelativePath/views-parent/template/nested/template.php @@ -1,9 +1,10 @@ Exception -PHP +PHP, ); $normalViewFile = $this->tempDirectory . DIRECTORY_SEPARATOR . 'no-exception.php'; file_put_contents( $normalViewFile, <<<'PHP'

No Exception

-PHP +PHP, ); $obInitialLevel = ob_get_level(); @@ -126,9 +128,9 @@ public function testExceptionWhenRenderIfFileNotExists(): void $this->expectException(ViewNotFoundException::class); $this->expectExceptionMessage( - 'The view file "' . - __DIR__ . '/public/tmp/View/not-exist.php' . - '" does not exist.' + 'The view file "' + . __DIR__ . '/public/tmp/View/not-exist.php' + . '" does not exist.', ); $view->render('not-exist.php'); @@ -144,7 +146,7 @@ public function testRelativePathInView(): void $baseView, <<<'PHP' render('./sub') ?> - PHP + PHP, ); $subView = "{$this->tempDirectory}/sub.php"; @@ -173,7 +175,7 @@ public function testRelativePathInViewWithContext(): void $baseView, <<<'PHP' render('./sub/sub') ?> - PHP + PHP, ); $subViewPath = $baseViewPath . DIRECTORY_SEPARATOR . 'sub'; @@ -194,7 +196,7 @@ public function testRelativePathInViewWithContext(): void public function testWithContextPath(): void { $view = TestHelper::createView()->withContextPath( - __DIR__ . '/public/view/custom-context' + __DIR__ . '/public/view/custom-context', ); $this->assertSame('42', $view->render('view')); @@ -253,7 +255,7 @@ public function testRenderWithoutFileExtension(string $filename, string $extensi $this->assertSame( 'Test ' . $extension, - $view->withFallbackExtension(...$fallbackExtensions)->render($filename) + $view->withFallbackExtension(...$fallbackExtensions)->render($filename), ); } @@ -289,7 +291,7 @@ public function testWithRenderersEmptyExtensionThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Empty extension is not supported. Please add extension for ' . PhpTemplateRenderer::class . '.' + 'Empty extension is not supported. Please add extension for ' . PhpTemplateRenderer::class . '.', ); $view->withRenderers([ @@ -303,7 +305,7 @@ public function testWithRenderersInvalidRendererTypeThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Renderer stdClass is not an instance of ' . TemplateRendererInterface::class . '.' + 'Renderer stdClass is not an instance of ' . TemplateRendererInterface::class . '.', ); $view->withRenderers([ @@ -317,7 +319,7 @@ public function testWithRenderersNullRendererThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Renderer null is not an instance of ' . TemplateRendererInterface::class . '.' + 'Renderer null is not an instance of ' . TemplateRendererInterface::class . '.', ); $view->withRenderers([ @@ -331,7 +333,7 @@ public function testWithRenderersStringRendererThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Renderer string is not an instance of ' . TemplateRendererInterface::class . '.' + 'Renderer string is not an instance of ' . TemplateRendererInterface::class . '.', ); $view->withRenderers([ @@ -345,7 +347,7 @@ public function testWithRenderersArrayRendererThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Renderer array is not an instance of ' . TemplateRendererInterface::class . '.' + 'Renderer array is not an instance of ' . TemplateRendererInterface::class . '.', ); $view->withRenderers([ @@ -359,7 +361,7 @@ public function testWithRenderersIntegerRendererThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Renderer int is not an instance of ' . TemplateRendererInterface::class . '.' + 'Renderer int is not an instance of ' . TemplateRendererInterface::class . '.', ); $view->withRenderers([ @@ -373,7 +375,7 @@ public function testWithRenderersNumericKeyImplicitThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.' + 'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.', ); $view->withRenderers([ @@ -387,7 +389,7 @@ public function testWithRenderersNumericKeyExplicitThrowsException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( - 'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.' + 'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.', ); $view->withRenderers([ @@ -519,7 +521,7 @@ public function testLocalizedDirectory(): void $currentLocale = 'de-DE'; $this->assertSame( $this->tempDirectory . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $currentLocale . DIRECTORY_SEPARATOR . 'faq.php', - $view->localize($viewFile, $currentLocale, $sourceLocale) + $view->localize($viewFile, $currentLocale, $sourceLocale), ); } @@ -669,7 +671,7 @@ public function testPlaceholderSalt(): void $this->assertSame( dechex(crc32('apple')), - $view->getPlaceholderSignature() + $view->getPlaceholderSignature(), ); } @@ -875,9 +877,7 @@ private function createViewWithBasePath(string $basePath): View private function createContext(string $viewPath): ViewContextInterface { return new class ($viewPath) implements ViewContextInterface { - public function __construct(private readonly string $viewPath) - { - } + public function __construct(private readonly string $viewPath) {} public function getViewPath(): string { diff --git a/tests/WebViewTest.php b/tests/WebViewTest.php index 491a33012..a5960eeca 100644 --- a/tests/WebViewTest.php +++ b/tests/WebViewTest.php @@ -139,7 +139,7 @@ public function testRegisterJsFileWithKeyEdgeCase(): void [/ENDBODY] HTML, - $html + $html, ); } @@ -152,11 +152,11 @@ public function testRegisterStyleTag(): void $webView->registerStyleTag($style); $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD]' . $style->render() . '[/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD]' . $style->render() . '[/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -224,7 +224,7 @@ public function testRegisterCssFileEdgeCase(): void [/HEAD] HTML, - $html + $html, ); } @@ -414,7 +414,7 @@ public function testRegisterCssWithKeyEdgeCase(): void .red{color:red;} .red{color:red;} CSS, - $html + $html, ); } @@ -443,7 +443,7 @@ public function testRegisterCssFromFile(): void $this->assertStringContainsString( '[HEAD][/HEAD]', - $html + $html, ); } @@ -453,7 +453,7 @@ public function testRegisterCssFromNonExistsFile(): void $exception = null; - set_error_handler(static fn () => null); + set_error_handler(static fn() => null); try { $webView->registerCssFromFile('/non-exists-file.css'); } catch (Throwable $e) { @@ -512,7 +512,7 @@ public function testRenderAjaxString(): void BodyEnd::class, PageEnd::class, ], - $eventDispatcher->getEventClasses() + $eventDispatcher->getEventClasses(), ); } @@ -573,7 +573,7 @@ public function testRenderEvents(): void PageEnd::class, AfterRender::class, ], - $eventDispatcher->getEventClasses() + $eventDispatcher->getEventClasses(), ); } @@ -587,11 +587,11 @@ public function testRegisterScriptTag(): void $webView->registerScriptTag($script); $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY]' . $script->render() . '[/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY]' . $script->render() . '[/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -646,24 +646,24 @@ public function testRegisterJsAndRegisterScriptTag(): void $html = $webView->render('layout.php', ['content' => '']); $this->assertStringContainsString( - "\n" . - $script3->render() . "\n" . - "\n" . - $script5->render(), - $html + "\n" + . $script3->render() . "\n" + . "\n" + . $script5->render(), + $html, ); $this->assertStringContainsString( - "', - $html + "', + $html, ); $this->assertStringContainsString( - "', - $html + "', + $html, ); } @@ -689,12 +689,12 @@ public function testRegisterJsAndRegisterScriptTagWithAjax(): void $webView->registerJs($js7, WebView::POSITION_READY); $html = $webView->renderAjax('//only-content.php', ['content' => '']); - $expected = "\n" . - $script3->render() . "\n" . - "\n" . - $script5->render() . "\n" . - $script6->render() . "\n" . - ""; + $expected = "\n" + . $script3->render() . "\n" + . "\n" + . $script5->render() . "\n" + . $script6->render() . "\n" + . ""; $this->assertSame($expected, $html); } @@ -716,7 +716,7 @@ public function testRegisterJsWithKeyEdgeCase(): void alert(1); alert(1); JS, - $html + $html, ); } @@ -731,11 +731,11 @@ public function testAddCssFiles(): void $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -768,11 +768,11 @@ public function testAddJsFiles(): void $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -814,19 +814,19 @@ public function testAddCssStrings(): void $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD]' . "\n" . - '' . "\n" . - '' . "\n" . - '[/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY]' . "\n" . - '' . "\n" . - '[/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD]' . "\n" + . '' . "\n" + . '' . "\n" + . '[/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY]' . "\n" + . '' . "\n" + . '[/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertEqualStringsIgnoringLineEndings($expected, $html); } @@ -865,12 +865,12 @@ public function testAddJsStrings(): void $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - "[ENDBODY]\n" . - '[/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . "[ENDBODY]\n" + . '[/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -907,12 +907,12 @@ public function testAddJsVars(): void $html = $webView->render('positions.php'); - $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]'; + $expected = '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]'; $this->assertSame($expected, $html); } @@ -1012,12 +1012,12 @@ public function testClear(): void $this->assertSame('', $webView->getTitle()); $this->assertSame( - '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]', - $webView->render('//positions.php') + '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]', + $webView->render('//positions.php'), ); } @@ -1044,12 +1044,12 @@ public function testWithClearedState(): void $this->assertNull($newWebView->getTheme()); $this->assertSame( - '[BEGINPAGE][/BEGINPAGE]' . "\n" . - '[HEAD][/HEAD]' . "\n" . - '[BEGINBODY][/BEGINBODY]' . "\n" . - '[ENDBODY][/ENDBODY]' . "\n" . - '[ENDPAGE][/ENDPAGE]', - $newWebView->render('positions.php') + '[BEGINPAGE][/BEGINPAGE]' . "\n" + . '[HEAD][/HEAD]' . "\n" + . '[BEGINBODY][/BEGINBODY]' . "\n" + . '[ENDBODY][/ENDBODY]' . "\n" + . '[ENDPAGE][/ENDPAGE]', + $newWebView->render('positions.php'), ); } From 4dd28a6937af37a889b685091415a88e6291a445 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Jan 2026 15:06:44 +0300 Subject: [PATCH 3/4] fix --- CHANGELOG.md | 1 + src/WebView.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 688878c60..af7a8cde0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Bug #295: Remove unnecessary `CacheKeyNormalizer` instance creation in `CachedContent` (@samdark) - Enh #295: Minor refactor `ViewTrait::getParameter()` and `ViewTrait::resolveViewFilePath()` (@samdark) - Bug #300: Fix renderer selection for view files with double extensions (@vjik) +- Enh #302: Explicitly import classes, functions, and constants in "use" section (@vjik) ## 12.2.2 December 07, 2025 diff --git a/src/WebView.php b/src/WebView.php index 65320dff3..20ec9e93a 100644 --- a/src/WebView.php +++ b/src/WebView.php @@ -194,7 +194,7 @@ public function endPage(bool $ajaxMode = false): void * Renders a view in response to an AJAX request. * * This method is similar to {@see render()} except that it will surround the view being rendered with the calls of - * {@see beginPage()}, {@see Head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the + * {@see beginPage()}, {@see head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the * method is able to inject into the rendering result with JS/CSS scripts and files that are registered with the * view. * From 37926e472e095b99217f40468617c2ec45529c48 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 24 Jan 2026 15:08:14 +0300 Subject: [PATCH 4/4] fix --- src/WebView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebView.php b/src/WebView.php index 20ec9e93a..b68786506 100644 --- a/src/WebView.php +++ b/src/WebView.php @@ -194,7 +194,7 @@ public function endPage(bool $ajaxMode = false): void * Renders a view in response to an AJAX request. * * This method is similar to {@see render()} except that it will surround the view being rendered with the calls of - * {@see beginPage()}, {@see head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the + * {@see beginPage()}, {@see self::head()}, {@see beginBody()}, {@see endBody()} and {@see endPage()}. By doing so, the * method is able to inject into the rendering result with JS/CSS scripts and files that are registered with the * view. *