From f9b81cbd6788eed8a5b497034857a94ffc434e5e Mon Sep 17 00:00:00 2001 From: Vladimir Machacek <8machy@seznam.cz> Date: Sun, 7 Mar 2021 18:26:54 +0100 Subject: [PATCH] Migrate to PHP8 --- .travis.yml | 6 ++-- Dockerfile | 7 +++-- composer.json | 19 ++++++------ docker-compose.yml | 2 +- src/Bridges/Nette/WebLoaderExtension.php | 11 +++---- src/WebLoader/Engine.php | 17 +++++----- src/WebLoader/FilesCollection.php | 17 +++++----- src/WebLoader/FilesCollectionRender.php | 31 +++++++++---------- src/WebLoader/FilesCollectionsContainer.php | 5 ++- .../Filters/CssBreakpointsFilter.php | 5 ++- src/WebLoader/Filters/CssUrlFilter.php | 7 ++--- tests/coding-standard/ecs.php | 26 ++++++++++++++++ tests/phpstan/phpstan.neon | 1 - 13 files changed, 87 insertions(+), 67 deletions(-) create mode 100755 tests/coding-standard/ecs.php diff --git a/.travis.yml b/.travis.yml index 98c1bbe..57bb81a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ language: php php: - - 7.2 - - 7.3 - - 7.4 + - 8.0 before_install: - composer self-update @@ -14,7 +12,7 @@ install: script: - composer cs:check - composer phpstan:check - - composer tests + - composer tester:check after_success: - wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar diff --git a/Dockerfile b/Dockerfile index ceaa795..c3037a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,14 @@ -FROM php:7.2 +FROM php:8.0 LABEL maintainer="8machy@seznam.cz" ENV PATH "/composer/vendor/bin:$PATH" ENV COMPOSER_ALLOW_SUPERUSER 1 -RUN apt-get update && apt-get install -y curl curl git zip unzip +RUN apt-get update && apt-get install -y curl curl git zip unzip \ + && apt-get install -y libicu-dev \ + && docker-php-ext-configure intl \ + && docker-php-ext-install intl RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer diff --git a/composer.json b/composer.json index 25c5d21..10bb15b 100644 --- a/composer.json +++ b/composer.json @@ -4,17 +4,18 @@ "keywords": ["webloader", "module-bundler", "javascript", "css", "frontend", "build-tool"], "license": "BSD-3-Clause", "require": { - "php": ">=7.2", + "php": ">=8.0", "nette/neon": "^2.4|^3.0" }, "require-dev": { - "tracy/tracy": "^2.7", - "nette/tester": "^2.3", + "tracy/tracy": "^2.8", + "nette/tester": "^2.4", "tubalmartin/cssmin": "^4.1", "machy8/google-closure-compiler": "^1.0", "phpstan/phpstan": "^0.12", - "symplify/easy-coding-standard": "^8.2", - "migrify/config-transformer": "^0.3.26" + "symplify/easy-coding-standard": "^9.2", + "symplify/config-transformer": "^9.2", + "nette/di": "^3.0" }, "suggest": { "machy8/google-closure-compiler": "PHP client for the Google Closure Compiler API in one file", @@ -26,13 +27,13 @@ }, "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "2.0-dev" } }, "scripts": { - "cs:check": "vendor/bin/ecs check src --set psr12", - "cs:fix": "vendor/bin/ecs check src --set psr12 --fix", - "phpstan:check": "phpstan analyse -c tests/phpstan/phpstan.neon -l max src tests/nette-tester", + "cs:check": "vendor/bin/ecs check src -c tests/coding-standard/ecs.php", + "cs:fix": "vendor/bin/ecs check src -c tests/coding-standard/ecs.php", + "phpstan:check": "phpstan analyse -c tests/phpstan/phpstan.neon -l 5 src tests/nette-tester", "tester:check": "tester -p phpdbg tests/nette-tester -s --coverage ./coverage.xml --coverage-src ./src" }, "minimum-stability": "dev", diff --git a/docker-compose.yml b/docker-compose.yml index 55d8d75..3903c52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: "3" services: - webloader: + server: container_name: webloader working_dir: /var/www/html build: . diff --git a/src/Bridges/Nette/WebLoaderExtension.php b/src/Bridges/Nette/WebLoaderExtension.php index 56276aa..216bda6 100644 --- a/src/Bridges/Nette/WebLoaderExtension.php +++ b/src/Bridges/Nette/WebLoaderExtension.php @@ -19,14 +19,13 @@ class WebLoaderExtension extends CompilerExtension { - private const - ENGINE_CLASSNAME = 'WebLoader\Engine', - ENGINE_PREFIX = 'engine', + private const ENGINE_CLASSNAME = 'WebLoader\Engine'; + private const ENGINE_PREFIX = 'engine'; - TRACY_CLASSNAME = 'Tracy\Debugger', + private const TRACY_CLASSNAME = 'Tracy\Debugger'; - TRACY_PANEL_CLASSNAME = 'WebLoader\Bridges\Tracy\WebLoaderPanel', - TRACY_PANEL_PREFIX = 'tracyPanel'; + private const TRACY_PANEL_CLASSNAME = 'WebLoader\Bridges\Tracy\WebLoaderPanel'; + private const TRACY_PANEL_PREFIX = 'tracyPanel'; /** * @var array diff --git a/src/WebLoader/Engine.php b/src/WebLoader/Engine.php index 22f17d1..b42592c 100644 --- a/src/WebLoader/Engine.php +++ b/src/WebLoader/Engine.php @@ -15,24 +15,23 @@ class Engine { - public const - CSS = 'css', - JS = 'js'; + public const CSS = 'css'; + public const JS = 'js'; /** * @var Compiler */ - private $compiler; + private $compiler = null; /** * @var FilesCollectionRender */ - private $filesCollectionRender; + private $filesCollectionRender = null; /** * @var FilesCollectionsContainerRender */ - private $filesCollectionsContainerRender; + private $filesCollectionsContainerRender = null; public function __construct(string $outputDir, string $documentRoot = '/', ?string $publicPathPrefix = null) @@ -120,7 +119,7 @@ public function disableCache(): Engine public function getCompiler(): Compiler { - if (!$this->compiler) { + if ($this->compiler === null) { $this->compiler = new Compiler(); } @@ -130,7 +129,7 @@ public function getCompiler(): Compiler public function getFilesCollectionRender(): FilesCollectionRender { - if (!$this->filesCollectionRender) { + if ($this->filesCollectionRender === null) { $this->filesCollectionRender = new FilesCollectionRender($this->getCompiler()); } @@ -140,7 +139,7 @@ public function getFilesCollectionRender(): FilesCollectionRender public function getFilesCollectionsContainerRender(): FilesCollectionsContainerRender { - if (!$this->filesCollectionsContainerRender) { + if ($this->filesCollectionsContainerRender === null) { $this->filesCollectionsContainerRender = new FilesCollectionsContainerRender( $this->getFilesCollectionRender() ); diff --git a/src/WebLoader/FilesCollection.php b/src/WebLoader/FilesCollection.php index 2fb22ca..5703b01 100644 --- a/src/WebLoader/FilesCollection.php +++ b/src/WebLoader/FilesCollection.php @@ -15,15 +15,14 @@ class FilesCollection { - public const - CONFIG_SECTION_CSS_FILES = Engine::CSS . 'Files', - CONFIG_SECTION_CSS_FILTERS = Engine::CSS . 'Filters', - CONFIG_SECTION_CSS_LOAD_CONTENT = Engine::CSS . 'LoadContent', - CONFIG_SECTION_CSS_OUTPUT_ELEMENT_ATTRIBUTES = Engine::CSS . 'OutputElementAttributes', - CONFIG_SECTION_JS_FILES = Engine::JS . 'Files', - CONFIG_SECTION_JS_FILTERS = Engine::JS . 'Filters', - CONFIG_SECTION_JS_LOAD_CONTENT = Engine::JS . 'LoadContent', - CONFIG_SECTION_JS_OUTPUT_ELEMENT_ATTRIBUTES = Engine::JS . 'OutputElementAttributes'; + public const CONFIG_SECTION_CSS_FILES = Engine::CSS . 'Files'; + public const CONFIG_SECTION_CSS_FILTERS = Engine::CSS . 'Filters'; + public const CONFIG_SECTION_CSS_LOAD_CONTENT = Engine::CSS . 'LoadContent'; + public const CONFIG_SECTION_CSS_OUTPUT_ELEMENT_ATTRIBUTES = Engine::CSS . 'OutputElementAttributes'; + public const CONFIG_SECTION_JS_FILES = Engine::JS . 'Files'; + public const CONFIG_SECTION_JS_FILTERS = Engine::JS . 'Filters'; + public const CONFIG_SECTION_JS_LOAD_CONTENT = Engine::JS . 'LoadContent'; + public const CONFIG_SECTION_JS_OUTPUT_ELEMENT_ATTRIBUTES = Engine::JS . 'OutputElementAttributes'; /** * @var array diff --git a/src/WebLoader/FilesCollectionRender.php b/src/WebLoader/FilesCollectionRender.php index 40787f1..b9fb783 100644 --- a/src/WebLoader/FilesCollectionRender.php +++ b/src/WebLoader/FilesCollectionRender.php @@ -15,20 +15,19 @@ class FilesCollectionRender { - private const - LINK_ELEMENT = 'link', - SCRIPT_ELEMENT = 'script', - STYLE_ELEMENT = 'style', + private const LINK_ELEMENT = 'link'; + private const SCRIPT_ELEMENT = 'script'; + private const STYLE_ELEMENT = 'style'; - LINK_PREFETCH = 'prefetch', - LINK_PRELOAD = 'preload', - LINK_PRELOAD_AS_CSS = 'style', - LINK_PRELOAD_AS_JS = 'script', + private const LINK_PREFETCH = 'prefetch'; + private const LINK_PRELOAD = 'preload'; + private const LINK_PRELOAD_AS_CSS = 'style'; + private const LINK_PRELOAD_AS_JS = 'script'; - SCRIPT_TYPE_ATTRIBUTE = 'text/javascript', - STYLE_TYPE_ATTRIBUTE = 'text/css', + private const SCRIPT_TYPE_ATTRIBUTE = 'text/javascript'; + private const STYLE_TYPE_ATTRIBUTE = 'text/css'; - VERSION_MARK = '?v='; + private const VERSION_MARK = '?v='; /** * @var Compiler @@ -88,7 +87,7 @@ public function css(?string $collectionName = null, array $attributes = [], bool */ public function cssPrefetch($collectionsNames = null): string { - return $this->generateMetaLinkElements($collectionsNames, Engine::CSS, self::LINK_PREFETCH); + return $this->generateMetaLinkElements(Engine::CSS, self::LINK_PREFETCH, $collectionsNames); } @@ -99,9 +98,9 @@ public function cssPrefetch($collectionsNames = null): string public function cssPreload($collectionsNames = null): string { return $this->generateMetaLinkElements( - $collectionsNames, Engine::CSS, self::LINK_PRELOAD, + $collectionsNames, self::LINK_PRELOAD_AS_CSS ); } @@ -140,7 +139,7 @@ public function js(?string $collectionName = null, array $attributes = [], bool */ public function jsPrefetch($collectionsNames = null): string { - return $this->generateMetaLinkElements($collectionsNames, Engine::JS, self::LINK_PREFETCH); + return $this->generateMetaLinkElements(Engine::JS, self::LINK_PREFETCH, $collectionsNames); } @@ -151,9 +150,9 @@ public function jsPrefetch($collectionsNames = null): string public function jsPreload($collectionsNames = null): string { return $this->generateMetaLinkElements( - $collectionsNames, Engine::JS, self::LINK_PRELOAD, + $collectionsNames, self::LINK_PRELOAD_AS_JS ); } @@ -223,9 +222,9 @@ private function generateElement(string $element, array $attributes, ?string $fi * @param array|string|NULL $collectionsNames */ private function generateMetaLinkElements( - $collectionsNames = null, string $collectionsType, string $rel, + $collectionsNames = null, ?string $as = null ): string { $tags = ''; diff --git a/src/WebLoader/FilesCollectionsContainer.php b/src/WebLoader/FilesCollectionsContainer.php index 32bd87a..9896731 100644 --- a/src/WebLoader/FilesCollectionsContainer.php +++ b/src/WebLoader/FilesCollectionsContainer.php @@ -15,9 +15,8 @@ class FilesCollectionsContainer { - public const - CONFIG_SECTION_CSS_COLLECTIONS = Engine::CSS . 'Collections', - CONFIG_SECTION_JS_COLLECTIONS = Engine::JS . 'Collections'; + public const CONFIG_SECTION_CSS_COLLECTIONS = Engine::CSS . 'Collections'; + public const CONFIG_SECTION_JS_COLLECTIONS = Engine::JS . 'Collections'; /** * @var string[] diff --git a/src/WebLoader/Filters/CssBreakpointsFilter.php b/src/WebLoader/Filters/CssBreakpointsFilter.php index 0750f2c..d500119 100644 --- a/src/WebLoader/Filters/CssBreakpointsFilter.php +++ b/src/WebLoader/Filters/CssBreakpointsFilter.php @@ -15,9 +15,8 @@ class CssBreakpointsFilter { - private const - MEDIA_QUERIES_REGULAR_EXPRESSION = '~@media(?[^{]+){(?:[^{}]*{[^{}]*})+[^}]+}~', - MIN_WIDTH_REGULAR_EXPRESSION = '~\(min-width\s*:\s*(?\d+)\s*(?\S+)\)~'; + private const MEDIA_QUERIES_REGULAR_EXPRESSION = '~@media(?[^{]+){(?:[^{}]*{[^{}]*})+[^}]+}~'; + private const MIN_WIDTH_REGULAR_EXPRESSION = '~\(min-width\s*:\s*(?\d+)\s*(?\S+)\)~'; /** * @var array diff --git a/src/WebLoader/Filters/CssUrlFilter.php b/src/WebLoader/Filters/CssUrlFilter.php index 33764a4..03f965f 100644 --- a/src/WebLoader/Filters/CssUrlFilter.php +++ b/src/WebLoader/Filters/CssUrlFilter.php @@ -15,9 +15,8 @@ class CssUrlFilter { - private const - URL_REGEXP = '~url\([\'"]*(?(?!(?:data:|.*//))[^\'"]+)[\'"]*\)~U', - ABSOLUTE_PATH_REGEXP = '~^/~U'; + private const URL_REGEXP = '~url\([\'"]*(?(?!(?:data:|.*//))[^\'"]+)[\'"]*\)~U'; + private const ABSOLUTE_PATH_REGEXP = '~^/~U'; /** * @var string @@ -39,7 +38,7 @@ public function __construct(string $outputDirPath, string $documentRoot = '/') } - public function filter(string $code, string $filePath): string + public function filter(string $code, string $filePath): ?string { $filePath = ltrim($filePath, '/'); $pathInfo = str_replace($this->documentRoot, '', pathinfo($filePath)['dirname']); diff --git a/tests/coding-standard/ecs.php b/tests/coding-standard/ecs.php new file mode 100755 index 0000000..ec65783 --- /dev/null +++ b/tests/coding-standard/ecs.php @@ -0,0 +1,26 @@ +services(); + $services->set(ArraySyntaxFixer::class) + ->call('configure', [[ + 'syntax' => 'short', + ]]); + + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::PATHS, [ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $parameters->set(Option::SETS, [ + SetList::PSR_12 + ]); +}; diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 2832fd2..5dce781 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -3,4 +3,3 @@ parameters: - ../nette-tester/AbstractTestCase.php ignoreErrors: - '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9_]+ \([\S]+\) does not accept [\S\|]+\.#' - - '#Argument of an invalid type array\|string\|null supplied for foreach, only iterables are supported.#'