Skip to content

Commit

Permalink
Migrate to PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
Machy8 committed Mar 13, 2021
1 parent 9ffbd7e commit b0307e4
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 66 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: php

php:
- 7.2
- 7.3
- 7.4
- 8.0

before_install:
- composer self-update
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3"
services:
webloader:
server:
container_name: webloader
working_dir: /var/www/html
build: .
Expand Down
11 changes: 5 additions & 6 deletions src/Bridges/Nette/WebLoaderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/WebLoader/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -120,7 +119,7 @@ public function disableCache(): Engine

public function getCompiler(): Compiler
{
if (!$this->compiler) {
if ($this->compiler === null) {
$this->compiler = new Compiler();
}

Expand All @@ -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());
}

Expand All @@ -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()
);
Expand Down
17 changes: 8 additions & 9 deletions src/WebLoader/FilesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 15 additions & 16 deletions src/WebLoader/FilesCollectionRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}


Expand All @@ -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
);
}
Expand Down Expand Up @@ -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);
}


Expand All @@ -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
);
}
Expand Down Expand Up @@ -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 = '';
Expand Down
5 changes: 2 additions & 3 deletions src/WebLoader/FilesCollectionsContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
5 changes: 2 additions & 3 deletions src/WebLoader/Filters/CssBreakpointsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

class CssBreakpointsFilter
{
private const
MEDIA_QUERIES_REGULAR_EXPRESSION = '~@media(?<parameters>[^{]+){(?:[^{}]*{[^{}]*})+[^}]+}~',
MIN_WIDTH_REGULAR_EXPRESSION = '~\(min-width\s*:\s*(?<value>\d+)\s*(?<unit>\S+)\)~';
private const MEDIA_QUERIES_REGULAR_EXPRESSION = '~@media(?<parameters>[^{]+){(?:[^{}]*{[^{}]*})+[^}]+}~';
private const MIN_WIDTH_REGULAR_EXPRESSION = '~\(min-width\s*:\s*(?<value>\d+)\s*(?<unit>\S+)\)~';

/**
* @var array
Expand Down
7 changes: 3 additions & 4 deletions src/WebLoader/Filters/CssUrlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

class CssUrlFilter
{
private const
URL_REGEXP = '~url\([\'"]*(?<url>(?!(?:data:|.*//))[^\'"]+)[\'"]*\)~U',
ABSOLUTE_PATH_REGEXP = '~^/~U';
private const URL_REGEXP = '~url\([\'"]*(?<url>(?!(?:data:|.*//))[^\'"]+)[\'"]*\)~U';
private const ABSOLUTE_PATH_REGEXP = '~^/~U';

/**
* @var string
Expand All @@ -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']);
Expand Down
26 changes: 26 additions & 0 deletions tests/coding-standard/ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->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
]);
};
1 change: 0 additions & 1 deletion tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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.#'

0 comments on commit b0307e4

Please sign in to comment.